def save_order(account_id, order_array):
    for order_info in order_array:
        order_db = Order()
        order_db.sys_id = getattr(order_info, 'OrderSysID', '')
        order_db.account = account_id
        order_db.symbol = getattr(order_info, 'InstrumentID', '')
        order_db.direction = getattr(order_info, 'Direction', '')
        order_db.trade_type = getattr(order_info, 'OffsetFlag', '')
        order_db.status = getattr(order_info, 'OrderStatus', '')

        order_submit_status = getattr(order_info, 'OrderSubmitStatus', '')
        if order_submit_status == '':
            order_submit_status = order_db.status
        order_db.submit_status = order_submit_status

        trading_day = getattr(order_info, 'TradingDay', '')
        insert_time = getattr(order_info, 'InsertTime', '')
        if (trading_day != '') and (insert_time != ''):
            insert_time_str = '%s-%s-%s %s' % (trading_day[0:4], trading_day[4:6], trading_day[6:8], insert_time)
        else:
            insert_time_str = '%s 00:00:00' % (today_str,)
        order_db.insert_time = insert_time_str

        order_db.qty = getattr(order_info, 'Volume', '')
        order_db.price = getattr(order_info, 'LimitPrice', '')
        order_db.ex_qty = getattr(order_info, 'VolumeTraded', '')
        order_list.append(order_db)
def __get_order_list(account_id, order_array):
    order_list = []
    order_dict = dict()
    for order_info in order_array:
        order_db = Order()
        order_db.sys_id = getattr(order_info, 'OrderSysID', '')
        # sys_id为空表示交易未到达交易所即被打回
        if order_db.sys_id == '':
            continue

        order_db.account = account_id
        order_db.symbol = getattr(order_info, 'InstrumentID', '')
        if local_server_name == 'huabao':
            if not ('IH' in order_db.symbol or 'IC' in order_db.symbol or 'IF' in order_db.symbol):
                continue
        if local_server_name == 'zhongxin':
            if 'IH' in order_db.symbol or 'IC' in order_db.symbol or 'IF' in order_db.symbol:
                continue

        # 0:买,1:卖
        order_db.direction = getattr(order_info, 'Direction', '')
        # 0:开仓  1:平仓  3:平今  4:平昨
        order_db.trade_type = getattr(order_info, 'CombOffsetFlag', '')

        # 全部成交:'0' 部分成交还在队列中:'1',部分成交不在队列中:'2',未成交还在队列中:'3',
        # 未成交不在队列中:'4',撤单:'5',未知:'a',尚未触发:'b',已触发:'c'
        order_db.status = getattr(order_info, 'OrderStatus', '')

        # 已经提交:'0',撤单已经提交:'1',修改已经提交:'2',已经接受:'3',报单已经被拒绝:'4',撤单已经被拒绝:'5',改单已经被拒绝:'6'
        order_db.submit_status = getattr(order_info, 'OrderSubmitStatus', '')

        trading_day = getattr(order_info, 'InsertDate', '')
        insert_time = getattr(order_info, 'InsertTime', '')
        if (trading_day != '') and (insert_time != ''):
            insert_time_str = '%s-%s-%s %s' % (trading_day[0:4], trading_day[4:6], trading_day[6:8], insert_time)
            if insert_time > now_datetime_str:
                insert_time_str = '%s %s' % (last_trading_day, insert_time)
        else:
            insert_time_str = '%s 00:00:00' % (now_date_str,)
        order_db.insert_time = insert_time_str

        qty = getattr(order_info, 'VolumeTotalOriginal', '')
        if order_db.direction == '0':
            order_db.qty = qty
        elif order_db.direction == '1':
            order_db.qty = 0 - int(qty)
        order_db.price = getattr(order_info, 'LimitPrice', '')
        order_db.ex_qty = getattr(order_info, 'VolumeTraded', '')
        order_list.append(order_db)
        order_dict[order_db.sys_id] = order_db
    return order_list, order_dict
def __get_order_list(account_id, order_array):
    order_list = []
    order_dict = dict()
    for order_info in order_array:
        order_db = Order()
        order_db.sys_id = getattr(order_info, 'm_strOrderSysID', '')
        # sys_id为空表示交易未到达交易所即被打回
        if order_db.sys_id == '':
            continue

        order_db.account = account_id
        order_db.symbol = getattr(order_info, 'm_strInstrumentID', '')

        # 48:买,49:卖
        order_db.direction = getattr(order_info, 'm_nDirection', '')

        # 0:开仓  1:平仓  3:平今  4:平昨
        order_db.trade_type = getattr(order_info, 'm_eOffsetFlag', '')

        # 全部成交:'0' 部分成交还在队列中:'1',部分成交不在队列中:'2',未成交还在队列中:'3',
        # 未成交不在队列中:'4',撤单:'5',未知:'a',尚未触发:'b',已触发:'c'
        order_db.status = getattr(order_info, 'EEntrustStatus', '')

        # 已经提交:'0',撤单已经提交:'1',修改已经提交:'2',已经接受:'3',报单已经被拒绝:'4',撤单已经被拒绝:'5',改单已经被拒绝:'6'
        order_db.submit_status = getattr(order_info, 'EEntrustSubmitStatus',
                                         '')

        trading_day = getattr(order_info, 'm_strInsertDate', '')
        insert_time = getattr(order_info, 'm_strInsertTime', '')
        if (trading_day != '') and (insert_time != ''):
            insert_time_str = '%s-%s-%s %s' % (trading_day[0:4],
                                               trading_day[4:6],
                                               trading_day[6:8], insert_time)
            if insert_time > now_datetime_str:
                insert_time_str = '%s %s' % (last_trading_day, insert_time)
        else:
            insert_time_str = '%s 00:00:00' % (now_date_str, )
        order_db.insert_time = insert_time_str

        qty = getattr(order_info, 'm_nTotalVolume', '')
        if order_db.direction == '0':
            order_db.qty = qty
        elif order_db.direction == '1':
            order_db.qty = 0 - int(qty)
        order_db.price = getattr(order_info, 'm_dAveragePrice', '')
        order_db.ex_qty = getattr(order_info, 'm_nTradedVolume', '')
        order_list.append(order_db)
        order_dict[order_db.sys_id] = order_db
    return order_list, order_dict
Beispiel #4
0
def __get_order_list(account_id, order_array):
    order_list = []
    order_dict = dict()
    for order_info in order_array:
        order_db = Order()
        order_db.sys_id = getattr(order_info, 'report_no', '')
        # sys_id为空表示交易未到达交易所即被打回
        if order_db.sys_id == '':
            continue

        order_db.account = account_id
        order_db.symbol = getattr(order_info, 'stock_code', '')

        # 48:买,49:卖
        order_db.direction = getattr(order_info, 'entrust_bs', '')

        # # 0:开仓  1:平仓  3:平今  4:平昨
        # order_db.trade_type = getattr(order_info, 'm_eOffsetFlag', '')
        order_db.trade_type = 0

        # 全部成交:'0' 部分成交还在队列中:'1',部分成交不在队列中:'2',未成交还在队列中:'3',
        # 未成交不在队列中:'4',撤单:'5',未知:'a',尚未触发:'b',已触发:'c'
        order_db.status = getattr(order_info, 'entrust_status', '')

        # # 已经提交:'0',撤单已经提交:'1',修改已经提交:'2',已经接受:'3',报单已经被拒绝:'4',撤单已经被拒绝:'5',改单已经被拒绝:'6'
        # order_db.submit_status = getattr(order_info, 'EEntrustSubmitStatus', '')
        order_db.submit_status = 0

        trading_day = getattr(order_info, 'entrust_date', '')
        insert_time = getattr(order_info, 'entrust_time', '').zfill(6)
        if (trading_day != '') and (insert_time != ''):
            insert_time_str = '%s-%s-%s %s:%s:%s' % (trading_day[0:4], trading_day[4:6], trading_day[6:8], \
                                                     insert_time[:2], insert_time[2:4], insert_time[4:6])
        else:
            insert_time_str = '%s 00:00:00' % (now_date_str, )
        order_db.insert_time = insert_time_str

        qty = getattr(order_info, 'entrust_amount', '')
        if order_db.direction == '0':
            order_db.qty = qty
        elif order_db.direction == '1':
            order_db.qty = 0 - float(qty)
        order_db.price = getattr(order_info, 'entrust_price', '')
        order_db.ex_qty = getattr(order_info, 'business_amount', '')
        order_list.append(order_db)
        order_dict[order_db.sys_id] = order_db
    return order_list, order_dict