Cryptocurrency spot hedging strategy design(1-4)

in fmz •  last year 

It can be seen that the balancing function is executed periodically, but if the lastKeepBalanceTS is reset to 0 after the hedging operation is triggered, the balancing operation will be triggered immediately. The profit will be calculated after a successful balancing.

Status bar information

      LogStatus(_D(), "A->B:", depthA.Bids[0].Price - depthB.Asks[0].Price, " B->A:", depthB.Bids[0].Price - depthA.Asks[0].Price, " targetDiffPrice:", targetDiffPrice, "\n", 
          "current A, Stocks:", nowAccs[0].Stocks, "FrozenStocks:", nowAccs[0].FrozenStocks, "Balance:", nowAccs[0].Balance, "FrozenBalance", nowAccs[0].FrozenBalance, "\n", 
          "current B, Stocks:", nowAccs[1].Stocks, "FrozenStocks:", nowAccs[1].FrozenStocks, "Balance:", nowAccs[1].Balance, "FrozenBalance", nowAccs[1].FrozenBalance, "\n", 
          "initial A, Stocks:", initAccs[0].Stocks, "FrozenStocks:", initAccs[0].FrozenStocks, "Balance:", initAccs[0].Balance, "FrozenBalance", initAccs[0].FrozenBalance, "\n", 
          "initial B, Stocks:", initAccs[1].Stocks, "FrozenStocks:", initAccs[1].FrozenStocks, "Balance:", initAccs[1].Balance, "FrozenBalance", initAccs[1].FrozenBalance)

The status bar is not particularly complex in design. It displays the current time, the price difference from Exchange A to Exchange B and the price difference from Exchange B to Exchange A. And it displays the current hedge target spread, the asset data of the exchange A account and the exchange B account.

Handling of trading pairs of different denominated currencies
In terms of parameters, we designed the conversion rate value parameter, and we also designed the exchange rate conversion in the initial operation of the main function at the beginning of the strategy. It should be noted that the SetRate exchange rate conversion function needs to be executed first.
Because this function affects two aspects:

Price conversion in all market data, order data, and position data.
The conversion of the denominated currency in the account assets.
For example, the current trading pair is BTC_USDT, the price unit is USDT, and the available denomination currency in the account assets is also USDT. If I want to convert the value into CNY, set exchange.SetRate(6.8) in the code to convert the data obtained by all functions under the exchange exchange object to CNY.
To convert to what denominated currency, pass in the exchange rate from the current denominated currency to the target denominated currency to the SetRate function.
Complete Strategy: Spot Hedging Strategy of Different Denominated Currencis (Tutorial)

From: https://blog.mathquant.com/2022/07/18/cryptocurrency-spot-hedging-strategy-design-1.html

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!