[Add] more log output for arbitrage algo
This commit is contained in:
parent
0aa1bda8df
commit
ab605767b6
@ -87,6 +87,7 @@ class ArbitrageAlgo(AlgoTemplate):
|
||||
|
||||
# Hedge if active symbol traded
|
||||
if trade.vt_symbol == self.active_vt_symbol:
|
||||
self.write_log("收到主动腿成交回报,执行对冲")
|
||||
self.hedge()
|
||||
|
||||
self.put_variables_event()
|
||||
@ -102,11 +103,13 @@ class ArbitrageAlgo(AlgoTemplate):
|
||||
|
||||
# Cancel all active orders before moving on
|
||||
if self.active_vt_orderid or self.passive_vt_orderid:
|
||||
self.write_log("有未成交委托,执行撤单")
|
||||
self.cancel_all()
|
||||
return
|
||||
|
||||
# Make sure that active leg is fully hedged by passive leg
|
||||
if (self.active_pos + self.passive_pos) != 0:
|
||||
self.write_log("主动腿和被动腿数量不一致,执行对冲")
|
||||
self.hedge()
|
||||
return
|
||||
|
||||
@ -114,6 +117,7 @@ class ArbitrageAlgo(AlgoTemplate):
|
||||
active_tick = self.get_tick(self.active_vt_symbol)
|
||||
passive_tick = self.get_tick(self.passive_vt_symbol)
|
||||
if not active_tick or not passive_tick:
|
||||
self.write_log("获取某条套利腿的行情失败,无法交易")
|
||||
return
|
||||
|
||||
# Calculate spread
|
||||
@ -125,12 +129,16 @@ class ArbitrageAlgo(AlgoTemplate):
|
||||
spread_ask_volume = min(active_tick.ask_volume_1,
|
||||
passive_tick.bid_volume_1)
|
||||
|
||||
self.write_log(f"盘口价差,买:{spread_bid_volume}@{spread_bid_price}")
|
||||
self.write_log(f"盘口价差,卖:{spread_ask_volume}@{spread_ask_price}")
|
||||
msg = f"价差盘口,买:{spread_bid_price} ({spread_bid_volume}),卖:{spread_ask_price} ({spread_ask_volume})"
|
||||
self.write_log(msg)
|
||||
|
||||
# Sell condition
|
||||
if spread_bid_price > self.spread_up:
|
||||
self.write_log("套利价差超过上限,满足做空条件")
|
||||
|
||||
if self.active_pos > -self.max_pos:
|
||||
self.write_log("当前持仓小于最大持仓限制,执行卖出操作")
|
||||
|
||||
volume = min(spread_bid_volume,
|
||||
self.active_pos + self.max_pos)
|
||||
|
||||
@ -142,7 +150,11 @@ class ArbitrageAlgo(AlgoTemplate):
|
||||
|
||||
# Buy condition
|
||||
elif spread_ask_price < -self.spread_down:
|
||||
self.write_log("套利价差超过下限,满足做多条件")
|
||||
|
||||
if self.active_pos < self.max_pos:
|
||||
self.write_log("当前持仓小于最大持仓限制,执行买入操作")
|
||||
|
||||
volume = min(spread_ask_volume,
|
||||
self.max_pos - self.active_pos)
|
||||
|
||||
|
@ -661,14 +661,11 @@ class BitmexWebsocketApi(WebsocketClient):
|
||||
|
||||
def on_position(self, d):
|
||||
""""""
|
||||
if not d["currentQty"]:
|
||||
return
|
||||
|
||||
position = PositionData(
|
||||
symbol=d["symbol"],
|
||||
exchange=Exchange.BITMEX,
|
||||
direction=Direction.NET,
|
||||
volume=d["currentQty"],
|
||||
volume=d.get("currentQty", 0),
|
||||
gateway_name=self.gateway_name,
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user