-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from aoki-h-jp/feature/1.0.0/commission
Feature/1.0.0/commission
- Loading branch information
Showing
5 changed files
with
164 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
""" | ||
An example of fetching funding rate | ||
""" | ||
from frarb import FundingRateArbitrage | ||
|
||
|
||
if __name__ == '__main__': | ||
# fetch from all exchanges | ||
fr = FundingRateArbitrage() | ||
for ex in fr.get_exchanges(): | ||
print(ex) | ||
print(fr.fetch_all_funding_rate(exchange=ex)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
""" | ||
An example of getting commission. | ||
""" | ||
from frarb import FundingRateArbitrage | ||
|
||
|
||
if __name__ == '__main__': | ||
fr = FundingRateArbitrage() | ||
# binance futures maker commission with BNB | ||
print('binance futures maker commission with BNB') | ||
print(fr.get_commission(exchange='binance', trade='futures', taker=False, by_token=True)) | ||
|
||
# bybit spot taker commission | ||
print('bybit spot taker commission') | ||
print(fr.get_commission(exchange='bybit', trade='spot')) | ||
|
||
# OKX spot maker commission | ||
print('OKX spot maker commission') | ||
print(fr.get_commission(exchange='okx', trade='spot', taker=False)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,150 @@ | ||
import utils | ||
import ccxt | ||
import pandas as pd | ||
|
||
|
||
class FundingRateArbitrage: | ||
def __init__(self): | ||
pass | ||
self.exchanges = ['binance', 'bybit', 'okx', 'bitget', 'gate', 'coinex'] | ||
|
||
def fetch_all_funding_rate(self, exchange: utils.Exchange) -> dict: | ||
@staticmethod | ||
def fetch_all_funding_rate(exchange: str) -> dict: | ||
""" | ||
Fetch funding rates on all perpetual contracts listed on the exchange. | ||
Args: | ||
exchange (utils.Exchange): Exchange (binance, bybit, ...) | ||
exchange (str): Name of exchange (binance, bybit, ...) | ||
Returns (dict): Dict of perpetual contract pair and funding rate | ||
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} | ||
|
||
def get_exchanges(self) -> list: | ||
""" | ||
Get a list of exchanges. | ||
Returns (list): List of exchanges. | ||
""" | ||
return self.exchanges | ||
|
||
def add_exchanges(self, exchange: str) -> list: | ||
""" | ||
Add exchanges. | ||
Args: | ||
exchange (str): Name of the exchange you want to add. | ||
Returns (list): List of exchanges. | ||
""" | ||
self.exchanges.append(exchange) | ||
return self.exchanges | ||
|
||
@staticmethod | ||
def get_commission(exchange: str, trade: str, taker=True, by_token=False) -> float: | ||
""" | ||
Get commission. | ||
TODO: Get with ccxt or CEX API. | ||
Args: | ||
exchange (str): Name of exchanges (binance, bybit, ...) | ||
trade (str): Spot Trade or Futures Trade | ||
taker (bool): is Taker or is Maker | ||
by_token (bool): Pay with exchange tokens (BNB, CET, ...) | ||
Returns (float): Commission. | ||
""" | ||
# https://www.binance.com/en/fee/schedule | ||
if exchange == 'binance': | ||
if trade == 'spot': | ||
if by_token: | ||
return 0.075 | ||
else: | ||
return 0.1 | ||
elif trade == 'futures': | ||
if taker: | ||
if by_token: | ||
return 0.036 | ||
else: | ||
return 0.04 | ||
else: | ||
if by_token: | ||
return 0.018 | ||
else: | ||
return 0.02 | ||
else: | ||
raise KeyError | ||
|
||
# https://www.bybit.com/ja-JP/help-center/bybitHC_Article?id=360039261154&language=ja | ||
if exchange == 'bybit': | ||
if trade == 'spot': | ||
return 0.1 | ||
elif trade == 'futures': | ||
if taker: | ||
return 0.06 | ||
else: | ||
return 0.01 | ||
else: | ||
raise KeyError | ||
|
||
# https://www.okx.com/fees | ||
if exchange == 'okx': | ||
if trade == 'spot': | ||
if taker: | ||
return 0.1 | ||
else: | ||
return 0.08 | ||
elif trade == 'futures': | ||
if taker: | ||
return 0.05 | ||
else: | ||
return 0.02 | ||
else: | ||
raise KeyError | ||
|
||
# https://www.bitget.com/ja/rate/ | ||
if exchange == 'bitget': | ||
if trade == 'spot': | ||
if by_token: | ||
return 0.08 | ||
else: | ||
return 0.1 | ||
elif trade == 'futures': | ||
if taker: | ||
return 0.051 | ||
else: | ||
return 0.017 | ||
else: | ||
raise KeyError | ||
|
||
# https://www.gate.io/ja/fee | ||
if exchange == 'gate': | ||
if trade == 'spot': | ||
if by_token: | ||
return 0.15 | ||
else: | ||
return 0.2 | ||
elif trade == 'futures': | ||
if taker: | ||
return 0.05 | ||
else: | ||
return 0.015 | ||
else: | ||
raise KeyError | ||
|
||
# https://www.coinex.zone/fees?type=spot&market=normal | ||
if exchange == 'gate': | ||
if trade == 'spot': | ||
if by_token: | ||
return 0.16 | ||
else: | ||
return 0.2 | ||
elif trade == 'futures': | ||
if taker: | ||
return 0.05 | ||
else: | ||
return 0.03 | ||
else: | ||
raise KeyError |
This file was deleted.
Oops, something went wrong.