32 浏览
0

快疯了,用TargetPosTask来调仓,同样是set_target_volume(0),有时是直接清仓,有时是反向对冲,这到底是怎么回事啊,其他设置都是一样的啊。构造TargetPosTask的语句如下:

ctx.pos_tasks[mid] = TargetPosTask(
    api=api,
    symbol=mid,
    price=price,
    offset_priority="昨今,开",
    support_open_min_volume=True,
    min_volume=min_vol,
    max_volume=max_vol,
)

其中的参数price是一个函数,定义如下:

def get_price_by_quote(quote: Quote):
     def get_price(direction: str) -> float:
        if direction == DIRECTION_LONG:
            if quote.upper_limit is not None and quote.upper_limit > 0:
                return quote.upper_limit
            else:
                return quote.ask_price1
        else:
            if quote.lower_limit is not None and quote.lower_limit > 0:
                return quote.lower_limit
            else:
                return quote.bid_price1
     return get_price

queshw 编辑问题 23小时 前