Preamble
The perpetual contract funding fee arbitrage program on okx written last year has a one year measured return of around 40%.
It has the following features:
- Positive Funding Fee Arbitrage
- Negative funding fee arbitrage
- Position leverage reset optimal settings
- Leveraged account fractional smoothing
- OKX top 20 total arbitrageable funds
- Query the current position of the underlying trading limit
This program can automatically adjust the optimal leverage to improve capital utilization.
Put some thoughts on money fee arbitrage below:
Dynamic Balance Funds Fee Arbitrage on Spot and Perpetual Contracts Alpha 1.0
- Project Outline
- Project Outline
- This project uses api calls to an exchange to realize multiple trades of spot (long) and perpetual contracts (short) within a specified time period, to balance the value of the two commodities before the time cutoff. After the completion of the arbitrage of the capital fee, dynamic trading out of the hands of the spot and contract exchange into stable virtual currency USDT.
- Funding Fee Earnings
- Settlement occurs every 8 hours, with one party paying the other. When the funding rate is positive, one party pays the other party; when the funding rate is negative, the other party pays the other party.
- Arbitrage Principle
- In the case of a positive funding fee, on the same exchange, under certain conditions, the value of the spot long and permanent contract short balance, to maintain no loss of principal to obtain the funds paid to the short side of the multi-side of the fee.
- Arbitrage formula
- Profit = (value of spot sold + value of contract sold + margin gain) - (value of spot bought + commission ① + value of contract bought + commission ②)
- When Handling Fee ①② > Funding Fee, you lose money.
- When the Handling Fee ①② = Funding Fee, the position is flat.
- When the fee ①② is lower than the funding fee, then profit is made.
- Profit = (value of spot sold + value of contract sold + margin gain) - (value of spot bought + commission ① + value of contract bought + commission ②)
- Handling Fee Correlation
- The commission decreases as the level of equity increases.
- Beginner’s level Opening fee 0.12
- Coin trading 0.1%
- Contracts 0.02
- Typically, the funding rate is 0.2%-0.4%.
- All three trades are on different underlying instruments Yield 0.24%-0.84
- Yield 0.48%-1.84% for three trades in the same instrument
- Additional information
- Funding rates fluctuate after each liquidation and need to be adjusted for fluctuations.
- Project Outline
- Project flow
- Successful call to Okex api to realize the function of obtaining real-time prices and placing orders.
- The Okex api interface needs to be accessed through the Hong Kong server.
- Get spot price spotAPI.get_specific_ticker(a + ‘-USDT’)
- execute spot order result = levelAPI.take_order(instrument_id=’’, side=’’, margin_trading=’’, client_oid=’’, type=’’, order_type=’0’, price=’’, size=’’, notional=’’, order_type=’0’, price=’’, size=’’) , notional=’’)
- Return spot order results
- Get the price of the perpetual contract swapAPI.get_specific_ticker(a + ‘-USDT-SWAP’)
- Execute a perpetual contract order result = swapAPI.take_order(instrument_id=’’, type=’’, price=’’, size=’’, client_oid=’’, order_type=’0’, match_price=’0’)
- Return the result of placing an order for a perpetual contract
- Think about strategies to achieve a balance of value between matching spot and perpetual contracts Principal risk
- Risk
- Short-term price fluctuations Short-term price difference between the two commodities purchased resulting in loss of capital
- Factors such as exchange restrictions on high-frequency trading, such as ip limits and dollar limits.
- Risk factor and uncertainty of the currency itself
- Risk
- Automated trading to meet the low risk of capital strategies and arbitrage
- Monitoring page and order automation
- Successful call to Okex api to realize the function of obtaining real-time prices and placing orders.
- Project risk points
- When the price does not move, it is very profitable. However, prices do not always move and short-term price fluctuations can cause risk to the asset.
- High funding rates are not always sustainable and cannot be held for a long period of time.
- If you add leverage, there is a risk of bursting the position
- Based on USDT propriety The risk is that USDT and the exchange mine
- Program Evaluation
- Arbitrage through funding fees alone is not very secure
- Alternative solution (stabilized version)
- To find a very high funding rate of coins, the difference returns to profit can fully cover the transaction costs and more surplus to complete the two sides of the order, such as the difference in the expansion of the completion of the ladder to increase the position, due to the existence of the funding rate, the difference will return sooner or later. If it does not return, you can continue to collect funds fees, and use this to complete a stable arbitrage.
- Negative funding rate Borrowing coins to go short Contracts to go long
- Positive funding rate Buy long contracts, short contracts.
- Requirements for each step of the program (core trading steps)
- ① Input the name of the cargo to be arbitraged, in the form of a character string, and the principal amount to be arbitraged, in integer form.
- ② call api interface to get the relevant data, including the latest spot price, transaction fees, the latest price of the perpetual contract, the opening fee, the capital rate, etc. ③ calculate this arbitrage.
- ③ calculate the estimated return on this arbitrage
- ④ Calculate the price and quantity of the first order to be placed.
- ⑤ Monitor the number of spot transactions and the number of perpetual contract transactions, as well as the ups and downs, respectively.
- ⑤ Monitor the number of spot transactions, the number of permanent contracts traded, and the ups and downs.
- ⑦If the funding rate is adjusted or reversed, sell in batches, refer to the above process.
High Frequency Funding Rate Arbitrage Model Design and its Extension
- Alpha 1.0 Version
- Function ① Go long on spot and short on swap perpetual contract with positive funding rate (single exchange).
- Function 2: Detect the price fluctuations of spot and swap perpetual contracts on OKEX during the trading process.
- Function 3: Fulfill buy and sell orders in optimal conditions.
- A few problems need to be solved
- 1, the pursuit of the second order of the transaction at the expense of profits, the pursuit of price balance or price advantage, the transaction is often completed by pending orders.
- 2, spot spot and swap perpetual contract price fluctuations in real time, only in a very few times can be traded.
- 3、Small currency price fluctuations is very affecting the capital, how to find the price of relatively stable oscillation time period.
- Alpha 2.0 Version
- Ability to monitor prices and place orders on different exchanges.
- Function 4: Sell spot borrowed coins and go long on swap perpetual contracts (on a single exchange), taking into account negative funding rates.
- Function 5: Go long and long swap perpetual contracts on different exchanges (multiple exchanges)
- Alpha 3.0 Version
- Mixed ETF arbitrage model with multiple currency pairs to further reduce risk points.
- Multi-account, multi-IP, multi-exchange, multi-currency pair matrix crossover modeling
- Model Extension - High Frequency Price Spread Arbitrage Modeling
- Timing of buys and sells based on monitoring the price fit in the Funding Fee Arbitrage model.
Code File
core code :
swap_rates.py:
1 | # -*- coding = utf-8 -*- |
code file:
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.
Comment