vn.py量化社区
By Traders, For Traders.
Member
avatar
加入于:
帖子: 107
声望: 1

INFO: 委托下单失败,错误代码:10001,信息:Param validation for 'qty' failed on the 'required' tag

Member
avatar
加入于:
帖子: 107
声望: 1

INFO: 委托撤单失败,错误代码:20001,信息:order_id cannot find working ao to cancel

还有这个错误

这都怎么解决啊

Member
avatar
加入于:
帖子: 187
声望: 40

utility.py修改如下

#------------------------------------------------------------------------------------
def get_digits(value: float) -> int:
    """
    获取浮点数小数点后数据长度
    """
    if "e" in str(value):
        value_str = "{:.10f}".format(value)
    else:
        value_str = str(value)
    for index in range(10):
        value_str = delete_zero(value_str)
    _, buf = value_str.split(".")
    return len(buf)
#------------------------------------------------------------------------------------    
def delete_zero(value:str):
    """
    删除字符串数值类型末尾0
    """
    assert isinstance(value, str),"参数value类型必须为字符串"
    if value[-1] == "0":
        value = value[:-1]
    return value
#------------------------------------------------------------------------------------
def round_to(value:Union[str, float], target: float) -> float:
    """
    取整value到最小变动
    """
    target = float(target)
    value = np.nan_to_num(value)
    try:
        rounded = int(round(value / target)) * target    
    except:
        rounded = 0
    #浮点数再次取整,防止返回数值精度不对
    if isinstance(rounded, float):
        rounded = round(rounded,get_digits(target))
    return rounded

cta_strategy\engine.py里面修改如下

def send_server_order(XXX):
        price = round_to(price, contract.price_tick)
        volume = round_to(volume, contract.min_volume)
Member
avatar
加入于:
帖子: 187
声望: 40

20001错误是你重复撤单了,问题不大,最好给撤单加个状态控制

Member
avatar
加入于:
帖子: 187
声望: 40

bybit_gateway.py修改如下

CONTRACT_LEVERAGE = {
    "BTCUSD": 100,
    "ETHUSD": 50,
    "EOSUSD": 50,
    "XRPUSD": 50,
    "BTCUSDT": 100,
    "BCHUSDT": 100,
    "ETHUSDT": 50,
    "LTCUSDT": 50,
    "LINKUSDT": 25,
    "XTZUSDT": 25
}
    #-------------------------------------------------------------------------------------------------   
    def on_query_contract(self, data: dict, request: Request):
        """
        查询合约
        """
        if self.check_error("查询合约", data):
            return

        for contract_data in data["result"]:
            contract = ContractData(
                symbol=contract_data["name"],
                exchange=Exchange.BYBIT,
                name=contract_data["name"],
                product=Product.FUTURES,
                size = CONTRACT_LEVERAGE.get(contract_data["name"],50),                #合约杠杆
                price_tick=float(contract_data["price_filter"]["min_price"]),
                min_volume=float(contract_data["lot_size_filter"]["min_trading_qty"]),
                gateway_name=self.gateway_name
            )
            self.gateway.on_contract(contract)
Member
avatar
加入于:
帖子: 107
声望: 1

上弦之月 wrote:

utility.py修改如下

#------------------------------------------------------------------------------------
def get_digits(value: float) -> int:
    """
    获取浮点数小数点后数据长度
    """
    if "e" in str(value):
        value_str = "{:.10f}".format(value)
    else:
        value_str = str(value)
    for index in range(10):
        value_str = delete_zero(value_str)
    _, buf = value_str.split(".")
    return len(buf)
#------------------------------------------------------------------------------------    
def delete_zero(value:str):
    """
    删除字符串数值类型末尾0
    """
    assert isinstance(value, str),"参数value类型必须为字符串"
    if value[-1] == "0":
        value = value[:-1]
    return value
#------------------------------------------------------------------------------------
def round_to(value:Union[str, float], target: float) -> float:
    """
    取整value到最小变动
    """
    target = float(target)
    value = np.nan_to_num(value)
    try:
        rounded = int(round(value / target)) * target    
    except:
        rounded = 0
    #浮点数再次取整,防止返回数值精度不对
    if isinstance(rounded, float):
        rounded = round(rounded,get_digits(target))
    return rounded

cta_strategy\engine.py里面修改如下

def send_server_order(XXX):
        price = round_to(price, contract.price_tick)
        volume = round_to(volume, contract.min_volume)

description

出现这个错误

Member
avatar
加入于:
帖子: 107
声望: 1

把你程序中的price_tick改成vnpy中pricetick 错误消失 嘿嘿
谢谢

Member
avatar
加入于:
帖子: 107
声望: 1

不过把usdt合约过滤掉了 会查询不到正向交易的合约 也没法做正向的交易

Member
avatar
加入于:
帖子: 187
声望: 40

@str_pythin 可以把正向合约的杠杆加进CONTRACT_LEVERAGE 再取消过滤

Member
avatar
加入于:
帖子: 107
声望: 1

上弦之月 wrote:

@str_pythin 可以把正向合约的杠杆加进CONTRACT_LEVERAGE 再取消过滤

这个问题搞定了

但是又出现新问题:策略中需要打印输出的内容居然不打印输出了,
看了半天也不知道是改动的哪部分导致的

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

沪公网安备 31011502017034号