Skip to content

Commit

Permalink
Merge pull request #2 from aoki-h-jp/feature/1.0.0/get-funding-rate
Browse files Browse the repository at this point in the history
Initial commit
  • Loading branch information
aoki-h-jp authored Mar 15, 2023
2 parents 04cb532 + 79c13a6 commit 95d7c75
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/fetch_funding_rate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
"""
An example of fetching funding rate
"""
from frarb import FundingRateArbitrage
from frarb.utils import Exchange


if __name__ == '__main__':
# fetch from binance
fr = FundingRateArbitrage()
fr.fetch_all_funding_rate(Exchange.BINANCE)
20 changes: 20 additions & 0 deletions frarb/frarb.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
import utils
import ccxt
import pandas as pd


class FundingRateArbitrage:
def __init__(self):
pass

def fetch_all_funding_rate(self, exchange: utils.Exchange) -> dict:
"""
Fetch funding rates on all perpetual contracts listed on the exchange.
Args:
exchange (utils.Exchange): Exchange (binance, bybit, ...)
Returns (dict): Dict of perpetual contract pair and funding rate
"""
ex = getattr(ccxt, exchange)()
info = ex.load_markets()
perp = [p for p in info if info[p]['linear']]
return {p: ex.fetch_funding_rate(p)['fundingRate'] for p in perp}
10 changes: 10 additions & 0 deletions frarb/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class Exchange(Enum):
BINANCE = 'binance'
BYBIT = 'bybit'
OKX = 'okx'
BITGET = 'bitget'
GATEIO = 'gate'
COINEX = 'coinex'
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ccxt
pandas

0 comments on commit 95d7c75

Please sign in to comment.