some change
This commit is contained in:
65
bot.py
65
bot.py
@@ -87,40 +87,49 @@ def on_trade(message: dict, orderman: OrderManager, state: StateManager):
|
||||
|
||||
state.set_last_price(symbol, price)
|
||||
|
||||
# 거래도 진행 // VALBZ와 VALE의 가격이 모두 존재할 때만 거래 시도
|
||||
if symbol == "VALBZ" or symbol == "VALE":
|
||||
print(
|
||||
f"Current prices - VALBZ: {state.get_last_price('VALBZ')}, VALE: {state.get_last_price('VALE')}"
|
||||
)
|
||||
p_valbz = state.get_last_price("VALBZ")
|
||||
p_vale = state.get_last_price("VALE")
|
||||
execute_arb(orderman, state)
|
||||
|
||||
|
||||
def execute_arb(orderman: OrderManager, state: StateManager):
|
||||
p_valbz = state.get_fair_value("VALBZ")
|
||||
p_vale = state.get_fair_value("VALE")
|
||||
p_bond = state.get_fair_value("BOND")
|
||||
p_gs = state.get_fair_value("GS")
|
||||
p_ms = state.get_fair_value("MS")
|
||||
p_wfc = state.get_fair_value("WFC")
|
||||
p_xlf = state.get_fair_value("XLF")
|
||||
|
||||
if p_vale is None or p_valbz is None:
|
||||
print("NONE")
|
||||
return
|
||||
|
||||
vale_to_valbz = p_valbz - p_vale
|
||||
valbz_to_vale = p_vale - p_valbz
|
||||
|
||||
FEE = 10
|
||||
SZ = 10
|
||||
if p_vale + 1 < p_valbz - 1:
|
||||
print("Good")
|
||||
if (p_vale + 1) * SZ + FEE < (p_valbz - 1) * SZ:
|
||||
if abs(orderman.positions["VALE"] + SZ) > orderman.POSITIONS_LIMIT["VALE"] or abs(orderman.positions["VALBZ"] - SZ) > orderman.POSITIONS_LIMIT["VALBZ"]:
|
||||
print("포지션 제한으로 인해 주문이 무시되었습니다.")
|
||||
return
|
||||
if vale_to_valbz > 10:
|
||||
orderman.buy("VALE", Dir.BUY, p_vale, 10)
|
||||
orderman.convert("VALE", Dir.SELL, 10)
|
||||
orderman.sell("VALBZ", Dir.SELL, p_valbz, 10)
|
||||
elif valbz_to_vale > 10:
|
||||
orderman.buy("VALBZ", Dir.BUY, p_valbz, 10)
|
||||
orderman.convert("VALE", Dir.BUY, 10)
|
||||
orderman.sell("VALE", Dir.SELL, p_vale, 10)
|
||||
|
||||
orderman.buy("VALE", p_vale + 1, -SZ)
|
||||
orderman.sell_convert("VALE", SZ)
|
||||
orderman.sell("VALBZ", p_valbz - 1, SZ)
|
||||
elif p_vale - 1 > p_valbz + 1:
|
||||
print("Good")
|
||||
if (p_vale - 1) * SZ - FEE > (p_valbz + 1) * SZ:
|
||||
if abs(orderman.positions["VALE"] - SZ) > orderman.POSITIONS_LIMIT["VALE"] or abs(orderman.positions["VALBZ"] + SZ) > orderman.POSITIONS_LIMIT["VALBZ"]:
|
||||
print("포지션 제한으로 인해 주문이 무시되었습니다.")
|
||||
return
|
||||
orderman.sell("VALE", p_vale - 1, -SZ)
|
||||
orderman.buy_convert("VALE", SZ)
|
||||
orderman.buy("VALBZ", p_valbz + 1, SZ)
|
||||
if p_xlf is not None and all(p is not None for p in [p_bond, p_gs, p_ms, p_wfc]):
|
||||
components = p_bond * 3 + p_gs * 2 + p_ms * 3 + p_wfc * 2
|
||||
xlf_fair = components / 10
|
||||
|
||||
if p_xlf > xlf_fair + 10:
|
||||
orderman.sell("XLF", Dir.SELL, p_xlf, 10)
|
||||
orderman.buy("BOND", Dir.BUY, p_bond, 30)
|
||||
orderman.buy("GS", Dir.BUY, p_gs, 20)
|
||||
orderman.buy("MS", Dir.BUY, p_ms, 30)
|
||||
orderman.buy("WFC", Dir.BUY, p_wfc, 20)
|
||||
elif xlf_fair > p_xlf + 10:
|
||||
orderman.buy("XLF", Dir.BUY, p_xlf, 10)
|
||||
orderman.sell("BOND", Dir.SELL, p_bond, 30)
|
||||
orderman.sell("GS", Dir.SELL, p_gs, 20)
|
||||
orderman.sell("MS", Dir.SELL, p_ms, 30)
|
||||
orderman.sell("WFC", Dir.SELL, p_wfc, 20)
|
||||
|
||||
# ~~~~~============== PROVIDED CODE ==============~~~~~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user