knowm / XChange

XChange is a Java library providing a streamlined API for interacting with 60+ Bitcoin and Altcoin exchanges providing a consistent interface for trading and accessing market data.
http://knowm.org/open-source/xchange/
MIT License
3.87k stars 1.94k forks source link

Retrieve funding rates for FTX #4469

Closed m1dnightc0der closed 1 year ago

m1dnightc0der commented 2 years ago

The perpetual swap contracts prevent dislocation with the spot price by charging a small amount known as the funding rate, when spot price> swap price, the funding rate is negative, so that short swap holders pay long swap holders, incentivising the short swap holder to buy, and bring the swap price inline with the spot price. When the spot price< swap price, the funding rate is positive, so that long swap holders pay short swap holders, incentivising the long swap holder to sell, and bring the swap price inline with the spot price.

FTX calculates the predictive funding rate and is available via their API, https://docs.ftx.com/#get-funding-rates, this information is very useful for certain trades such as basis trades where you are buying the spot, selling the swap when the funding rate is positive or selling the spot, buying the swap when the funding rate is negative.

Unless there are any objections I would like to create a new set of predictive funding rate DTO objects in xchange-core and have FTX adapter pull them in to make them available for consumption via the xchange library. Any exchange that trades the swap contracts (binance, okex, bybit etc etc) will also publish the funding rates i.e. binanace (https://binance-docs.github.io/apidocs/futures/en/#get-funding-rate-history). Think for exchanges like bitmex we have custom dto for the adapter, but given so many exchanges, think it makes more sense to pull these into the core project.

walec51 commented 2 years ago

before doing any bigger implementation feel free to post some pseudocode showing the structure of those DTOs in this issues thread so we can discuss them