VeighNa量化社区
你的开源社区量化交易平台
Member
avatar
加入于:
帖子: 7
声望: 0

价差交易模块里的strategy定义了on_spread_tick方法,代码如下,策略启动后,并没有按照逻辑发出停止单,大佬们可以帮忙看一下问题在哪吗?

def on_spread_tick(self, tick: TickData):
    """
    Callback when new spread tick data is generated.
    """

    self.spread_pos = self.get_spread_pos()

    if self.spread_pos > 0:
        self.stop_open_algos()

        # Start sell close algo (profit taking)
        if (tick.last_price >= self.sell_price) and (not self.sell_algoid):
            self.sell_algoid = self.start_short_algo(
                self.sell_price, abs(
                    self.spread_pos), self.payup, self.interval
            )

        # Start stop close algo for long trading (stop loss)
        elif (tick.last_price <= self.buy_stop_price) and (not self.buy_stop_algoid):
            self.buy_stop_algoid = self.start_short_algo(
                self.buy_stop_price, self.spread_pos, self.payup, self.interval
            )

    elif self.spread_pos < 0:
        self.stop_open_algos()

        # Start cover close algo (profit taking)
        if (tick.last_price <= self.cover_price) and (not self.cover_algoid):
            self.cover_algoid = self.start_long_algo(
                self.cover_price, abs(
                    self.spread_pos), self.payup, self.interval
            )

        # Start stop close algo for short trading (stop loss)
        elif (tick.last_price >= self.short_stop_price) and (not self.short_stop_algoid):
            self.short_stop_algoid = self.start_long_algo(
                self.short_stop_price, abs(
                    self.spread_pos), self.payup, self.interval
            )

    self.put_event()
Member
avatar
加入于:
帖子: 1627
声望: 117

要在策略回调函数on_spread_data中接收SpreadData推送后,用spread.to_tick()转化为tick,并调用on_spread_tick函数

Member
avatar
加入于:
帖子: 7
声望: 0

MTF wrote:

要在策略回调函数on_spread_data中接收SpreadData推送后,用spread.to_tick()转化为tick,并调用on_spread_tick函数

非常感谢!

是不是像statistical_arbitrage_stategy里面的on_spread_data一样?
def on_spread_data(self):
"""
Callback when spread price is updated.
"""
tick = self.get_spread_tick()
self.on_spread_tick(tick)

Member
avatar
加入于:
帖子: 1627
声望: 117

是的

Member
avatar
加入于:
帖子: 7
声望: 0

MTF wrote:

是的
感谢!我测试后如还有疑问再请教大牛

© 2015-2022 上海韦纳软件科技有限公司
备案服务号:沪ICP备18006526号

沪公网安备 31011502017034号

【用户协议】
【隐私政策】
【免责条款】