Created
December 22, 2022 12:58
-
-
Save cheekybastard/69058fa161487133c7f2d272b77d4683 to your computer and use it in GitHub Desktop.
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
import httpx | |
import cytoolz as tz # type: ignore | |
from cytoolz import curried as c # type: ignore | |
black_list_crypto: list = ['FTT', 'SOL', 'CHZ', 'BNT', 'SUSHI'] | |
COLLATERAL: int = 1500 | |
BASE_SPREAD: float = 0.0025 | |
gtrade_trading_vars: dict = httpx.get("https://gains-farm-v2-mainnet.herokuapp.com/trading-variables").json() | |
FROM_SYMBOLS_ALL: list = [x['from'] for x in gtrade_trading_vars['pairs']] | |
_from_symbols_crypto: list = [x['from'] for x in gtrade_trading_vars['pairs'] if x['groupIndex'] == '0'] | |
FROM_SYMBOLS_CRYPTO: list = [x for x in _from_symbols_crypto if x not in black_list_crypto] | |
def get_price_spread_impact_above(symbol: str, trade_size: int, openinterest: dict, onePercentDepth: dict) -> float: | |
# (int(openinterest_dict['ETH']['long'])+(1500*10**18)/2) / int(onePercentDepth_dict['ETH']['onePercentDepthAbove']) | |
one_percent_depth = int(onePercentDepth[symbol]['onePercentDepthAbove']) | |
# if for ZeroDivisionError | |
if one_percent_depth: | |
return ((int(openinterest[symbol]['long'])+(trade_size)/2)/one_percent_depth/10**18)+BASE_SPREAD | |
else: | |
return 0.0 | |
def get_price_spread_impact_below(symbol: str, trade_size: int, openinterest: dict, onePercentDepth: dict) -> float: | |
one_percent_depth = int(onePercentDepth[symbol]['onePercentDepthBelow']) | |
if one_percent_depth: | |
return ((int(openinterest[symbol]['short'])+(trade_size)/2)/one_percent_depth/10**18)+BASE_SPREAD | |
else: | |
return 0.0 | |
_openinterest: list = gtrade_trading_vars['openInterests'] | |
_onePercentDepth: list = gtrade_trading_vars['pairInfos']['params'] | |
_openinterest_dict = dict(zip(FROM_SYMBOLS_ALL, _openinterest)) | |
openinterest_mung: dict = tz.keyfilter(lambda x: x in FROM_SYMBOLS_CRYPTO, _openinterest_dict) | |
_onePercentDepth_dict = dict(zip(FROM_SYMBOLS_ALL, _onePercentDepth)) | |
onePercentDepth_mung: dict = tz.keyfilter(lambda x: x in FROM_SYMBOLS_CRYPTO, _onePercentDepth_dict) | |
gtrade_spread: dict = {symbol: { | |
'long': get_price_spread_impact_above(symbol, COLLATERAL, openinterest_mung, onePercentDepth_mung), | |
'short': get_price_spread_impact_below(symbol, COLLATERAL, openinterest_mung, onePercentDepth_mung) | |
} for symbol in FROM_SYMBOLS_CRYPTO} | |
assert len(openinterest_mung) == len(onePercentDepth_mung), 'mung short data' | |
assert all([isinstance(x[0], str) for x in gtrade_spread.items()]), 'dud key' | |
assert all([isinstance(x[1]['long'], float) for x in gtrade_spread.items()]), 'dud long val' | |
assert all([isinstance(x[1]['short'], float) for x in gtrade_spread.items()]), 'dud short val' | |
print(f"symbols: {len(gtrade_spread)}") | |
print(f"gtrade_spread: {gtrade_spread}") | |
# {'BTC': {'long': 0.11081393562766044, 'short': 0.29230769292317266}, 'ETH': {'long': 0.08609053979076561, 'short': 0.15440454699146453}...} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment