Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get funding rate #2

Merged
merged 1 commit into from
Mar 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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