bfr w buy_ratios and std, algo with symbol switching and fr exponentiation for optimization
This commit is contained in:
@@ -54,8 +54,6 @@ async def get_extended_markets_info() -> pd.DataFrame:
|
||||
df['min_notional'] = 0
|
||||
df['min_lot_size'] = df['tradingConfig'].apply(lambda x: x.get('minOrderSizeChange',{}))
|
||||
df['max_leverage'] = df['tradingConfig'].apply(lambda x: x.get('maxLeverage',{}))
|
||||
|
||||
#### TODO: ADD IN LOT SIZE FOR ROUND LOTS (SEE IPYNB)
|
||||
|
||||
print('Extend markets info refreshed successfully')
|
||||
|
||||
@@ -184,7 +182,12 @@ async def loop() -> None:
|
||||
df_comb_fr['net_mult'] = df_comb_fr['net_mult'].round(2)
|
||||
df_comb_fr['net_mult_x_net_fr_abs'] = df_comb_fr['net_funding_rate_abs'] * df_comb_fr['net_mult']
|
||||
|
||||
df_best_fr_rate = df_comb_fr[['symbol_ext','symbol_ast','daily_volume_ext','daily_volume_ast','min_price_ext','min_price_ast','min_order_size_ext','min_order_size_ast','min_lot_size_ext','min_lot_size_ast','min_notional_ext','min_notional_ast','funding_rate_ext','funding_rate_ast','max_leverage_ext','max_leverage_ast','lh_asset_ext','lh_asset_ast','rh_asset_ext','rh_asset_ast','net_mult_x_net_fr_abs','net_funding_rate_abs','net_funding_rate','next_funding_at_same_time','last_trade_ts_ast']].sort_values(by='net_mult_x_net_fr_abs', ascending=False).reset_index(drop=True)
|
||||
df_best_fr_rate = df_comb_fr[
|
||||
['symbol_ext','symbol_ast','daily_volume_ext','daily_volume_ast','min_price_ext','min_price_ast','min_order_size_ext',
|
||||
'min_order_size_ast','min_lot_size_ext','min_lot_size_ast','min_notional_ext','min_notional_ast','funding_rate_ext',
|
||||
'funding_rate_ast','max_leverage_ext','max_leverage_ast','lh_asset_ext','lh_asset_ast','rh_asset_ext','rh_asset_ast',
|
||||
'net_mult_x_net_fr_abs','net_funding_rate_abs','net_funding_rate','next_funding_at_same_time','last_trade_ts_ast']
|
||||
].sort_values(by='net_mult_x_net_fr_abs', ascending=False).reset_index(drop=True)
|
||||
|
||||
# min_daily_volume = 100_000
|
||||
# df_best_fr_rate = df_best_fr_rate.loc[ (df_best_fr_rate['daily_volume_ast']>=min_daily_volume) & (df_best_fr_rate['daily_volume_ext']>min_daily_volume) ,:].reset_index(drop=True)
|
||||
@@ -211,7 +214,8 @@ async def loop() -> None:
|
||||
for index, row in df_best_fr_rate.iterrows():
|
||||
df = await get_candles(symbol=row['symbol_ext'])
|
||||
buy_ratio_ext = float(df['med_ratio_aster_over_extend'].median())
|
||||
candles_ratios.append({'symbol_ext':row['symbol_ext'], 'buy_ratio_ext':buy_ratio_ext,'buy_ratio_ast':buy_ratio_ext*-1})
|
||||
buy_ratio_std = float(df['med_ratio_aster_over_extend'].std())
|
||||
candles_ratios.append({'symbol_ext':row['symbol_ext'], 'buy_ratio_std': buy_ratio_std, 'buy_ratio_ext':buy_ratio_ext,'buy_ratio_ast':buy_ratio_ext*-1})
|
||||
|
||||
df_best_fr_rate = df_best_fr_rate.merge(pd.DataFrame(candles_ratios), on='symbol_ext', how='left')
|
||||
|
||||
@@ -230,6 +234,7 @@ async def loop() -> None:
|
||||
min_lot_size=float(df_best_fr_rate['min_lot_size_ast'].iloc[0]),
|
||||
min_notional=float(df_best_fr_rate['min_notional_ast'].iloc[0]),
|
||||
buy_ratio=float(df_best_fr_rate['buy_ratio_ast'].iloc[0]),
|
||||
buy_ratio_std=float(df_best_fr_rate['buy_ratio_std'].iloc[0]),
|
||||
)
|
||||
EXTEND = structs.Perpetual_Exchange(
|
||||
mult = int(df_best_fr_rate['max_leverage_ext'].iloc[0]),
|
||||
@@ -242,6 +247,7 @@ async def loop() -> None:
|
||||
min_lot_size=float(df_best_fr_rate['min_lot_size_ext'].iloc[0]),
|
||||
min_notional=float(df_best_fr_rate['min_notional_ext'].iloc[0]),
|
||||
buy_ratio=float(df_best_fr_rate['buy_ratio_ext'].iloc[0]),
|
||||
buy_ratio_std=float(df_best_fr_rate['buy_ratio_std'].iloc[0]),
|
||||
)
|
||||
except Exception as e:
|
||||
logging.critical(f'Failed to build ASTER/EXTEND objs err: {e}; df cols: {df_best_fr_rate.columns}')
|
||||
@@ -252,7 +258,7 @@ async def loop() -> None:
|
||||
|
||||
master_data = df_best_fr_rate[
|
||||
['symbol_ast','max_leverage_ast','lh_asset_ast','rh_asset_ast','funding_rate_ast','min_price_ast','min_order_size_ast','min_lot_size_ast','min_notional_ast','buy_ratio_ast',
|
||||
'symbol_ext','max_leverage_ext','lh_asset_ext','rh_asset_ext','funding_rate_ext','min_price_ext','min_order_size_ext','min_lot_size_ext','min_notional_ext','buy_ratio_ext']
|
||||
'symbol_ext','max_leverage_ext','lh_asset_ext','rh_asset_ext','funding_rate_ext','min_price_ext','min_order_size_ext','min_lot_size_ext','min_notional_ext','buy_ratio_ext', 'buy_ratio_std']
|
||||
].to_json(orient='records')
|
||||
|
||||
VAL_KEY.set(name='fr_engine_best_fund_rate_master', value=str(master_data))
|
||||
|
||||
Reference in New Issue
Block a user