| | |
| | | # 深证撤单 |
| | | print("逐笔委托", item) |
| | | |
| | | l2_data_manager.add_l2_order_detail(item, True) |
| | | l2_data_manager.add_l2_order_detail(item, 0, True) |
| | | else: |
| | | if abs(pTransaction['TradePrice'] - limit_up_price) < 0.201: |
| | | # 涨停价 |
| | |
| | | def OnRtnOrderDetail(self, pOrderDetail): |
| | | can_listen = False |
| | | code = str(pOrderDetail['SecurityID']) |
| | | start_time = 0 |
| | | if code in self.special_code_volume_for_order_dict: |
| | | start_time = time.time() |
| | | if self.special_code_volume_for_order_dict[code][0] == pOrderDetail['Volume'] or constant.SHADOW_ORDER_VOLUME == pOrderDetail['Volume']: |
| | | # 监控目标订单与影子订单 |
| | | if self.special_code_volume_for_order_dict[code][1] > time.time(): |
| | |
| | | "OrderTime": pOrderDetail['OrderTime'], "MainSeq": pOrderDetail['MainSeq'], |
| | | "SubSeq": pOrderDetail['SubSeq'], "OrderNO": pOrderDetail['OrderNO'], |
| | | "OrderStatus": pOrderDetail['OrderStatus'].decode()} |
| | | l2_data_manager.add_l2_order_detail(item) |
| | | l2_data_manager.add_l2_order_detail(item, start_time) |
| | | |
| | | def OnRtnBondMarketData(self, pDepthMarketData, FirstLevelBuyNum, FirstLevelBuyOrderVolumes, FirstLevelSellNum, |
| | | FirstLevelSellOrderVolumes): |
| | |
| | | |
| | | |
| | | # 添加委托详情 |
| | | def add_l2_order_detail(data, istransaction=False): |
| | | def add_l2_order_detail(data, start_time, istransaction=False): |
| | | code = data["SecurityID"] |
| | | # 异步日志记录 |
| | | if code not in tmep_order_detail_queue_dict: |
| | |
| | | |
| | | tmep_order_detail_queue_dict[code].put( |
| | | (data['SecurityID'], data['Price'], data['Volume'], data['Side'], data['OrderType'], data['OrderTime'], |
| | | data['MainSeq'], data['SubSeq'], data['OrderNO'], data['OrderStatus'], int(time.time() * 1000))) |
| | | data['MainSeq'], data['SubSeq'], data['OrderNO'], data['OrderStatus'], time.time(), start_time)) |
| | | |
| | | |
| | | # 添加逐笔成交 |
| | |
| | | try: |
| | | if code not in target_codes: |
| | | break |
| | | # 打开共享内存 |
| | | order_detail_upload_active_time_dict[code] = time.time() |
| | | udatas = [] |
| | | while not tmep_order_detail_queue_dict[code].empty(): |
| | | temp = tmep_order_detail_queue_dict[code].get() |
| | | udatas.append(temp) |
| | | if udatas: |
| | | start_time = time.time() |
| | | # start_time = time.time() |
| | | # upload_data(code, "l2_order", udatas) |
| | | l2_data_callback.OnL2Order(code, udatas, int(time.time() * 1000)) |
| | | # l2_data_transaction_protocol.send_l2_order_detail(pipe, _mmap, code, udatas) |
| | | use_time = int((time.time() - start_time) * 1000) |
| | | if use_time > 10: |
| | | async_log_util.info(logger_local_huaxin_l2_upload, f"{code}-上传代码耗时:{use_time}ms") |
| | | # use_time = int((time.time() - start_time) * 1000) |
| | | # if use_time > 10: |
| | | # async_log_util.info(logger_local_huaxin_l2_upload, f"{code}-上传代码耗时:{use_time}ms") |
| | | else: |
| | | # 没有数据的时候需等待,有数据时不需等待 |
| | | time.sleep(0.004) |
| | | time.sleep(0.001) |
| | | except Exception as e: |
| | | hx_logger_contact_debug.exception(e) |
| | | logger_local_huaxin_l2_error.error(f"上传订单数据出错:{str(e)}") |
| | |
| | | jx_blocks, jx_blocks_by = KPLCodeJXBlockManager().get_jx_blocks_cache( |
| | | code), KPLCodeJXBlockManager().get_jx_blocks_cache(code, by=True) |
| | | info = cls.__trade_log_placr_order_info_dict[code] |
| | | info.mode = order_begin_pos.mode |
| | | info.set_buy_index(order_begin_pos.buy_single_index, order_begin_pos.buy_exec_index) |
| | | if jx_blocks: |
| | | info.set_kpl_blocks(list(jx_blocks)) |
| | |
| | | import code_attribute |
| | | from code_attribute import code_volumn_manager, limit_up_time_manager, global_data_loader, gpcode_manager |
| | | import constant |
| | | from l2.l2_data_manager import OrderBeginPosInfo |
| | | from l2.l2_data_util import L2DataUtil |
| | | from utils import global_util, tool |
| | | from log_module import log, log_export |
| | |
| | | extra_datas.append(f"安全笔数:{data['safe_count']}") |
| | | |
| | | records_new_data.append((time_, "", "-------------------------", [])) |
| | | records_new_data.append((time_, "下单", |
| | | f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】", |
| | | extra_datas)) |
| | | mode = data.get('mode') |
| | | if mode == OrderBeginPosInfo.MODE_FAST: |
| | | records_new_data.append((time_, "闪电下单", |
| | | f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】", |
| | | extra_datas)) |
| | | else: |
| | | records_new_data.append((time_, "下单", |
| | | f"【{format_l2_data(total_datas[data['buy_single_index']])}】-【{format_l2_data(total_datas[data['buy_exec_index']])}】", |
| | | extra_datas)) |
| | | elif type == trade_record_log_util.TYPE_REAL_PLACE_ORDER_POSITION: |
| | | _datas = [] |
| | | MIN_MONEYS = [30000, 20000, 10000] |
| | |
| | | if __name__ == '__main__': |
| | | code = '002786' |
| | | l2_data_util.load_l2_data(code) |
| | | print( __load_trade_record(code, l2_data_util.local_today_datas.get(code))) |
| | | print(__load_trade_record(code, l2_data_util.local_today_datas.get(code))) |
| | |
| | | def __buy(code, price, trade_state, capture_timestamp, last_data, last_data_index, mode=0): |
| | | async_log_util.info(logger_trade, "{} trade_manager.__buy 开始".format(code)) |
| | | try: |
| | | |
| | | if constant.API_TRADE_ENABLE: |
| | | count = (constant.BUY_MONEY_PER_CODE // int(round(float(price) * 100))) * 100 |
| | | if mode != 0: |
| | | count = 100 |
| | | # if mode != 0: |
| | | # count = 100 |
| | | # 最低下单1手 |
| | | if count < 100: |
| | | count = 100 |
| | |
| | | |
| | | class PlaceOrderInfo(object): |
| | | def __init__(self, buy_single_index=None, buy_exec_index=None, m_val=None, safe_count=None, big_num_indexes=None, |
| | | kpl_blocks=None): |
| | | kpl_blocks=None, mode=None): |
| | | self.buy_single_index = buy_single_index |
| | | self.buy_exec_index = buy_exec_index |
| | | self.m_val = m_val |
| | | self.safe_count = safe_count |
| | | self.big_num_indexes = big_num_indexes |
| | | self.kpl_blocks = kpl_blocks |
| | | self.mode = mode |
| | | |
| | | def set_buy_index(self, buy_single_index, buy_exec_index): |
| | | self.buy_single_index = buy_single_index |