Giter Site home page Giter Site logo

funding-rate-arbitrage's Introduction

funding-rate-arbitrage

Python 3.11

Python library for funding rate arbitrage

A framework to help you easily perform funding rate arbitrage on the following major centralized cryptocurrency exchanges (CEX).

  • binance
  • bybit
  • OKX
  • gate.io
  • CoinEx
  • Bitget

This library can detect perpetual contract with a large divergence in funding rates between CEXs.

NOTE: This library does not include the feature to perform automatic funding rate arbitrage.

What's FR Arbitrage?

Arbitrage of different funding rates among different exchanges is another trading strategy that takes advantage of the disparity in funding rates for the same cryptocurrency perpetual contracts between exchanges. It involves combining long positions with low funding rates from one exchange with short positions from another exchange with higher funding rates to generate profits. Funding rates are periodic payments between long and short traders to ensure that the perpetual contract price remains close to the underlying asset price.

Installation

pip install git+https://github.com/aoki-h-jp/funding-rate-arbitrage

Usage

Fetch FR & commission

from funding_rate_arbitrage.frarb import FundingRateArbitrage

fr = FundingRateArbitrage()

# fetch all perp funding rate on binance
fr_binance = fr.fetch_all_funding_rate(exchange='binance')

# get commission on binance with futures, maker
cm_binance = fr.get_commission(exchange='binance', trade='futures', taker=False)

Fetch FR history

from funding_rate_arbitrage.frarb import FundingRateArbitrage

fr = FundingRateArbitrage()

# figure funding rate history
fr.fetch_funding_rate_history(exchange='binance', symbol='BTC/USDT:USDT')

'funding rate history example'

Display large FR divergence on single CEX

# display large funding rate divergence on bybit
>>> fr.display_large_divergence_single_exchange(exchange='bybit', display_num=5)
                 Funding Rate [%]  Commission [%]  Revenue [/100 USDT]
CTC/USDT:USDT              0.1794            0.32              -0.1406
CREAM/USDT:USDT            0.0338            0.32              -0.2862
TWT/USDT:USDT              0.0295            0.32              -0.2905
TLM/USDT:USDT              0.0252            0.32              -0.2948
JASMY/USDT:USDT            0.0100            0.32              -0.3100

# display Top 5 large funding rate divergence on bybit one by one.
>>> fr.display_one_by_one_single_exchange(exchange='bybit', display_num=5)
------------------------------------------------
Revenue: -0.1663 / 100USDT
SELL: CTC/USDT:USDT Perp
BUY: CTC/USDT:USDT Spot
Funding Rate: 0.1537 %
Commission: 0.32 %
------------------------------------------------
Revenue: -0.17200000000000001 / 100USDT
SELL: CREAM/USDT:USDT Perp
BUY: CREAM/USDT:USDT Spot
Funding Rate: 0.1480 %
Commission: 0.32 %
------------------------------------------------
Revenue: -0.2107 / 100USDT
SELL: BOBA/USDT:USDT Perp
BUY: BOBA/USDT:USDT Spot
Funding Rate: 0.1093 %
Commission: 0.32 %
------------------------------------------------
Revenue: -0.2854 / 100USDT
SELL: TLM/USDT:USDT Perp
BUY: TLM/USDT:USDT Spot
Funding Rate: 0.0346 %
Commission: 0.32 %
------------------------------------------------
Revenue: -0.2953 / 100USDT
SELL: TOMO/USDT:USDT Perp
BUY: TOMO/USDT:USDT Spot
Funding Rate: 0.0247 %
Commission: 0.32 %

# display Top 5 large funding rate divergence on bybit one by one (minus FR).
>>> fr.display_one_by_one_single_exchange(exchange='bybit', display_num=5, minus=True)
------------------------------------------------
Revenue: -0.1458 / 100USDT
SELL: ARPA/USDT:USDT Options
BUY: ARPA/USDT:USDT Perp
Funding Rate: -0.2342 %
Commission: 0.38 %
------------------------------------------------
Revenue: -0.2569 / 100USDT
SELL: MASK/USDT:USDT Options
BUY: MASK/USDT:USDT Perp
Funding Rate: -0.1231 %
Commission: 0.38 %
------------------------------------------------
Revenue: -0.3056 / 100USDT
SELL: APE/USD:USDC Options
BUY: APE/USD:USDC Perp
Funding Rate: -0.0744 %
Commission: 0.38 %
------------------------------------------------
Revenue: -0.3158 / 100USDT
SELL: SWEAT/USD:USDC Options
BUY: SWEAT/USD:USDC Perp
Funding Rate: -0.0642 %
Commission: 0.38 %
------------------------------------------------
Revenue: -0.3166 / 100USDT
SELL: APE/USDT:USDT Options
BUY: APE/USDT:USDT Perp
Funding Rate: -0.0634 %
Commission: 0.38 %

Display large FR divergence between CEX

# display large funding rate divergence between CEX.
>>> fr.display_large_divergence_multi_exchange(display_num=5, sorted_by='divergence')
                 binance   bybit       okx  bitget    gate    coinex  Divergence [%]  Commission [%]  Revenue [/100 USDT]
FIL/USDT:USDT  -0.008948 -0.0229 -0.334535 -0.0084 -0.0240 -0.737473        0.729073           0.202             0.527073
HNT/USDT:USDT  -0.023885 -0.0125       NaN     NaN  0.0056  0.304442        0.328327           0.180             0.148327
WAXP/USDT:USDT       NaN     NaN       NaN     NaN  0.0100  0.205733        0.195733           0.500            -0.304267
AXS/USDT:USDT  -0.021292 -0.0385 -0.205174 -0.0212 -0.0282 -0.215217        0.194017           0.202            -0.007983
OP/USDT:USDT   -0.060397 -0.0228 -0.206011 -0.0601 -0.0147 -0.148713        0.191311           0.200            -0.008689

# sorted by revenue. 
>>> fr.display_large_divergence_multi_exchange(display_num=5, sorted_by='revenue')
                binance   bybit       okx  bitget    gate    coinex  Divergence [%]  Commission [%]  Revenue [/100 USDT]
FIL/USDT:USDT -0.004703 -0.0232 -0.334535 -0.0047 -0.0245 -0.737473        0.732773           0.202             0.530773
HNT/USDT:USDT -0.030722 -0.0141       NaN     NaN  0.0051  0.304442        0.335164           0.180             0.155164
OP/USDT:USDT  -0.057856 -0.0235 -0.206011 -0.0589 -0.0162 -0.148713        0.189811           0.200            -0.010189
MKR/USDT:USDT  0.010000  0.0100 -0.056437  0.0104  0.0100  0.075530        0.131967           0.200            -0.068033
TON/USDT:USDT       NaN     NaN -0.023741     NaN  0.0100 -0.116483        0.126483           0.200            -0.073517

# Display Top 5 large funding rate divergence between multi exchange.
>>> fr.display_one_by_one_multi_exchanges(display_num=5)
------------------------------------------------
Revenue: 0.2184 USDT / 100USDT
SELL: coinex IOTA/USDT:USDT Perp (Funding Rate 0.3478 %)
BUY: okx IOTA/USDT:USDT Perp (Funding Rate -0.0706 %)
Divergence: 0.4184 %
Commission: 0.2000 %
------------------------------------------------
Revenue: 0.1191 USDT / 100USDT
SELL: coinex DASH/USDT:USDT Perp (Funding Rate 0.4267 %)
BUY: okx DASH/USDT:USDT Spot
Divergence: 0.4191 %
Commission: 0.3000 %
------------------------------------------------
Revenue: 0.1080 USDT / 100USDT
SELL: okx TON/USDT:USDT Perp (Funding Rate 0.0482 %)
BUY: coinex TON/USDT:USDT Perp (Funding Rate -0.2598 %)
Divergence: 0.3080 %
Commission: 0.2000 %
------------------------------------------------
Revenue: 0.0842 USDT / 100USDT
SELL: binance GMX/USDT:USDT Perp (Funding Rate 0.0100 %)
BUY: coinex GMX/USDT:USDT Perp (Funding Rate -0.2542 %)
Divergence: 0.2642 %
Commission: 0.1800 %
------------------------------------------------
Revenue: 0.0447 USDT / 100USDT
SELL: okx FIL/USDT:USDT Perp (Funding Rate 0.2416 %)
BUY: gate FIL/USDT:USDT Perp (Funding Rate -0.0031 %)
Divergence: 0.2447 %
Commission: 0.2000 %

Disclaimer

This project is for educational purposes only. You should not construe any such information or other material as legal, tax, investment, financial, or other advice. Nothing contained here constitutes a solicitation, recommendation, endorsement, or offer by me or any third party service provider to buy or sell any securities or other financial instruments in this or in any other jurisdiction in which such solicitation or offer would be unlawful under the securities laws of such jurisdiction.

Under no circumstances will I be held responsible or liable in any way for any claims, damages, losses, expenses, costs, or liabilities whatsoever, including, without limitation, any direct or indirect damages for loss of profits.

funding-rate-arbitrage's People

Contributors

aoki-h-jp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

funding-rate-arbitrage's Issues

How to run this?

i have intslled by downoading package and then just pip install -r requirments.txt ... after packages were installed i run this command:
python fetch_funding_rate_all_exchanges.py - from examples folder but got error :
\examples\fetch_funding_rate_all_exchanges.py", line 4, in
from funding_rate_arbitrage.frarb import FundingRateArbitrage
ModuleNotFoundError: No module named 'funding_rate_arbitrage'
What i am doing wrong?

Errors on Bybit, OKX, Gate

There are errors of this kind:

[22:32:58] ERROR    BTC/USDC:USDC-240405 is not perp.               frarb.py:51
                    ┌───── Traceback (most recent call last) ─────┐            
                    │ D:\Dwnld\pyProject\funding-rate-arbitrage-m │            
                    │ ain\funding_rate_arbitrage\frarb.py:49 in   │            
                    │ fetch_all_funding_rate                      │            
                    │                                             │            
                    │    46 │   │   fr_d = {}                     │            
                    │    47 │   │   for p in perp:                │            
                    │    48 │   │   │   try:                      │            
                    │ >  49 │   │   │   │   fr_d[p] = ex.fetch_fu │            
                    │    50 │   │   │   except ExchangeError:     │            
                    │    51 │   │   │   │   log.exception(f"{p} i │            
                    │    52 │   │   return fr_d                   │            
                    │                                             │            
                    │ D:\Dwnld\pyProject\funding-rate-arbitrage-m │            
                    │ ain\.venv\Lib\site-packages\ccxt\base\excha │            
                    │ nge.py:4798 in fetch_funding_rate           │            
                    │                                             │            
                    │   4795 │   │   │   symbol = market['symbol' │            
                    │   4796 │   │   │   if not market['contract' │            
                    │   4797 │   │   │   │   raise BadSymbol(self │            
                    │        only')                               │            
                    │ > 4798 │   │   │   rates = self.fetchFundin │            
                    │   4799 │   │   │   rate = self.safe_value(r │            
                    │   4800 │   │   │   if rate is None:         │            
                    │   4801 │   │   │   │   raise NullResponse(s │            
                    │        + symbol)                            │            
                    │                                             │            
                    │ D:\Dwnld\pyProject\funding-rate-arbitrage-m │            
                    │ ain\.venv\Lib\site-packages\ccxt\bybit.py:2 │            
                    │ 325 in fetch_funding_rates                  │            
                    │                                             │            
                    │   2322 │   │   type = None                  │            
                    │   2323 │   │   type, params = self.handle_m │            
                    │        params)                              │            
                    │   2324 │   │   if type != 'swap':           │            
                    │ > 2325 │   │   │   raise NotSupported(self. │            
                    │        + ' markets')                        │            
                    │   2326 │   │   else:                        │            
                    │   2327 │   │   │   subType = None           │            
                    │   2328 │   │   │   subType, params = self.h │            
                    │        market, params, 'linear')            │            
                    └─────────────────────────────────────────────┘            
                    NotSupported: bybit fetchFundingRates() does               
                    not support future markets

And on the OKX exchange:

ExchangeError: okx fetchFundingRate() is only              
                    valid for swap markets 

And on the GATE exchange

gate fetchFundingRate() supports                
                    swap contracts only 

I tried to figure it out myself, but my level of code writing is 0 :D

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.