-
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 #4 from aoki-h-jp/release/1.0.0
Release/1.0.0
- Loading branch information
Showing
9 changed files
with
236 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Hirotaka Aoki | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
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,10 @@ | ||
""" | ||
An example of fetching funding rate | ||
""" | ||
from frarb import FundingRateArbitrage | ||
|
||
|
||
if __name__ == '__main__': | ||
# fetch from binance | ||
fr = FundingRateArbitrage() | ||
print(fr.fetch_all_funding_rate(exchange='binance')) |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .frarb import FundingRateArbitrage | ||
|
||
__all__ = ["FundingRateArbitrage"] |
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,150 @@ | ||
import ccxt | ||
import pandas as pd | ||
|
||
|
||
class FundingRateArbitrage: | ||
def __init__(self): | ||
self.exchanges = ['binance', 'bybit', 'okx', 'bitget', 'gate', 'coinex'] | ||
|
||
@staticmethod | ||
def fetch_all_funding_rate(exchange: str) -> dict: | ||
""" | ||
Fetch funding rates on all perpetual contracts listed on the exchange. | ||
Args: | ||
exchange (str): Name of 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} | ||
|
||
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 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,2 @@ | ||
ccxt | ||
pandas |
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 @@ | ||
from setuptools import setup | ||
|
||
setup( | ||
name='funding-rate-arbitrage', | ||
version="1.0.0", | ||
description='A framework to help you easily perform funding rate arbitrage on major centralized cryptocurrency ' | ||
'exchanges.', | ||
install_requires=['ccxt', 'pandas'], | ||
author='aoki-h-jp', | ||
author_email='[email protected]', | ||
license='MIT' | ||
) |