| | |
| | | from copy import deepcopy |
| | | from unittest import mock |
| | | |
| | | import constant |
| | | from cancel_strategy.s_l_h_cancel_strategy import SCancelBigNumComputer |
| | | from code_attribute import big_money_num_manager, gpcode_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from l2.huaxin import huaxin_delegate_postion_manager |
| | | from l2.l2_sell_manager import L2MarketSellManager |
| | | from l2.l2_transaction_data_manager import HuaXinSellOrderStatisticManager |
| | | from log_module import log, log_export, async_log_util |
| | | from trade.huaxin import huaxin_trade_api |
| | | from utils import tool |
| | | from trade.buy_radical.radical_buy_data_manager import RadicalBuyDataManager, RadicalBuyBlockManager |
| | | from utils import tool, init_data_util |
| | | from db import redis_manager_delegate as redis_manager |
| | | from l2 import l2_log, l2_data_manager, transaction_progress, l2_data_manager_new |
| | | from l2 import l2_log, l2_data_manager, transaction_progress, l2_data_manager_new, l2_transaction_data_processor, \ |
| | | cancel_buy_strategy |
| | | from l2.transaction_progress import TradeBuyQueue |
| | | from third_data import kpl_util, kpl_data_manager, block_info |
| | | from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager, CodePlateKeyBuyManager, KPLCodeJXBlockManager |
| | | from third_data.code_plate_key_manager import LimitUpCodesPlateKeyManager |
| | | from third_data.kpl_data_manager import KPLDataManager |
| | | from trade import trade_data_manager, current_price_process_manager, l2_trade_util |
| | | from trade.trade_queue_manager import THSBuy1VolumnManager |
| | | from trade import trade_data_manager, current_price_process_manager, l2_trade_util, trade_manager |
| | | import l2.l2_data_manager_new, l2.l2_data_manager, l2.l2_data_util, l2.cancel_buy_strategy |
| | | |
| | | |
| | |
| | | except Exception as e: |
| | | pass |
| | | |
| | | # @unittest.skip("跳过此单元测试") |
| | | def test_trade(self): |
| | | constant.TEST = True |
| | | trade_manager.TradeStateManager().open_buy() |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |
| | | code = "000026" |
| | | code = "000590" |
| | | clear_trade_data(code) |
| | | l2.l2_data_util.load_l2_data(code) |
| | | total_datas = deepcopy(l2.l2_data_util.local_today_datas[code]) |
| | |
| | | # pos_list.insert(75, (472, 488)) |
| | | # pos_list.insert(84, (516, 532)) |
| | | |
| | | # hook |
| | | # tool.get_now_time_str = mock.Mock(return_value="09:35:00") |
| | | |
| | | # 获取交易进度 |
| | | trade_progress_list, buy_queues = log_export.get_trade_progress(code) |
| | | trade_progress_list.reverse() |
| | |
| | | KPLDataManager().get_from_file(kpl_util.KPLDataType.LIMIT_UP, tool.get_now_date_str())) |
| | | |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.load_total_datas() |
| | | |
| | | current_price_process_manager.set_trade_price(code, round(float(gpcode_manager.get_limit_up_price(code)), 2)) |
| | | limit_up_price = gpcode_manager.get_limit_up_price(code) |
| | | if limit_up_price is None: |
| | | init_data_util.re_set_price_pre(code) |
| | | current_price_process_manager.set_trade_price(code, gpcode_manager.get_limit_up_price_as_num(code)) |
| | | |
| | | pss_server, pss_strategy = multiprocessing.Pipe() |
| | | huaxin_trade_api.run_pipe_trade(pss_server, None) |
| | | # huaxin_trade_api.run_pipe_trade(pss_server, None, None) |
| | | |
| | | for indexs in pos_list: |
| | | l2_log.threadIds[code] = mock.Mock( |
| | |
| | | break |
| | | |
| | | print("----------------处理位置", indexs) |
| | | for l2_m in l2_market_datas: |
| | | if int(str(l2_m["dataTimeStamp"])[:-3]) < int(total_datas[indexs[0]]["val"]["time"].replace(":", "")): |
| | | time_str = f"{l2_m['dataTimeStamp']}" |
| | | if time_str.startswith("9"): |
| | | time_str = "0" + time_str |
| | | time_str = time_str[:6] |
| | | time_str = f"{time_str[0:2]}:{time_str[2:4]}:{time_str[4:6]}" |
| | | L2MarketSellManager().set_current_total_sell_data(code, time_str, |
| | | l2_m["totalAskVolume"] * l2_m["avgAskPrice"]) |
| | | break |
| | | if l2_market_datas: |
| | | for l2_m in l2_market_datas: |
| | | if int(str(l2_m["dataTimeStamp"])[:-3]) < int( |
| | | total_datas[indexs[0]]["val"]["time"].replace(":", "")): |
| | | time_str = f"{l2_m['dataTimeStamp']}" |
| | | if time_str.startswith("9"): |
| | | time_str = "0" + time_str |
| | | time_str = time_str[:6] |
| | | time_str = f"{time_str[0:2]}:{time_str[2:4]}:{time_str[4:6]}" |
| | | L2MarketSellManager().set_current_total_sell_data(code, time_str, |
| | | l2_m["totalAskVolume"] * l2_m["avgAskPrice"], |
| | | l2_m["totalAskVolume"]) |
| | | break |
| | | |
| | | for tp in trade_progress_list: |
| | | if int(tp[1].replace(":", "")) < int(total_datas[indexs[0]]["val"]["time"].replace(":", "")): |
| | |
| | | l2.l2_data_manager_new.L2TradeDataProcessor.process_add_datas(code, total_datas[indexs[0]:indexs[1] + 1], 0, |
| | | 0) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_place_order(self): |
| | | code = "002241" |
| | | # @unittest.skip("跳过此单元测试") |
| | | def test_s_cancel(self): |
| | | code = "002288" |
| | | l2.l2_data_util.load_l2_data(code) |
| | | total_datas = deepcopy(l2.l2_data_util.local_today_datas[code]) |
| | | huaxin_delegate_postion_manager.place_order(code, 17.36, 100, total_datas[753]) |
| | | huaxin_delegate_postion_manager.get_l2_place_order_position(code, total_datas[755:1038]) |
| | | l2.l2_data_util.local_today_datas[code] = l2.l2_data_util.local_today_datas[code][:222] |
| | | SCancelBigNumComputer().set_real_place_order_index(code, 153, False) |
| | | |
| | | TradeBuyQueue.get_traded_index = mock.Mock(return_value=(117, False)) |
| | | order_begin_pos = l2_data_manager.OrderBeginPosInfo(buy_single_index=117, buy_exec_index=122) |
| | | sell_order_info = [1517999, [[2996226, 300000, 5.06, (10223471, 4876395), (10223471, 4876395)]]] |
| | | SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, sell_order_info, |
| | | order_begin_pos) |
| | | |
| | | sell_order_info = [508507, [[5564445, 100100, 5.08, (10372994, 4876545), (10372994, 4876546)]]] |
| | | SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, sell_order_info, |
| | | order_begin_pos) |
| | | SCancelBigNumComputer().set_big_sell_order_info_for_cancel(code, sell_order_info, |
| | | order_begin_pos) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_h_cancel(self): |
| | |
| | | l2.l2_data_util.local_today_datas[code] = total_datas |
| | | l2.l2_data_util.load_num_operate_map(l2.l2_data_util.local_today_num_operate_map, code, total_datas, True) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | # @unittest.skip("跳过此单元测试") |
| | | def test_block(self): |
| | | code = "000628" |
| | | KPLCodeJXBlockManager().load_jx_blocks(code, 17.96, 17.96) |
| | | block_info.init_code(code) |
| | | codes_str = "300390" |
| | | codes = codes_str.split(",") # ["002889", "300337", "001298", "002771"] |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.load_total_datas() |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas = kpl_data_manager.KPLDataManager.get_data( |
| | | kpl_util.KPLDataType.LIMIT_UP) |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.save_record(tool.get_now_date_str(), |
| | | kpl_data_manager.KPLDataManager.get_data( |
| | | kpl_util.KPLDataType.LIMIT_UP)) |
| | | for code in codes: |
| | | # KPLCodeJXBlockManager().load_jx_blocks(code, 23.52,23.62, |
| | | # kpl_data_manager.KPLLimitUpDataRecordManager.get_current_reasons()) |
| | | # |
| | | block_info.init_code(code) |
| | | # latest_current_limit_up_records = kpl_data_manager.get_latest_current_limit_up_records() |
| | | |
| | | CodePlateKeyBuyManager.update_can_buy_blocks(code, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, |
| | | yesterday_codes, |
| | | block_info.get_before_blocks_dict()) |
| | | init_data_util.re_set_price_pre(code, True) |
| | | |
| | | limit_up_data = kpl_data_manager.KPLLimitUpDataRecordManager.record_code_dict.get(code) |
| | | if limit_up_data: |
| | | limit_up_time = tool.to_time_str(limit_up_data[2]) |
| | | RadicalBuyBlockManager.set_current_limit_up_datas( |
| | | kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas) |
| | | # CodePlateKeyBuyManager.update_can_buy_blocks(code, |
| | | # kpl_data_manager.KPLLimitUpDataRecordManager.latest_origin_datas, |
| | | # kpl_data_manager.KPLLimitUpDataRecordManager.total_datas, |
| | | # latest_current_limit_up_records, |
| | | # block_info.get_before_blocks_dict(), |
| | | # kpl_data_manager.KPLLimitUpDataRecordManager.get_current_limit_up_reason_codes_dict()) |
| | | # can_buy_result = CodePlateKeyBuyManager.can_buy(code) |
| | | # print(can_buy_result) |
| | | # if can_buy_result: |
| | | # if can_buy_result[0]: |
| | | # blocks = ",".join([f"{x[0]}-{x[1] + 1}({x[2]}&{x[3] - x[2]})" for x in can_buy_result[0]]) |
| | | # print(blocks) |
| | | |
| | | # class TestTrade(unittest.TestCase): |
| | | # processor = L2TradeDataProcessor() |
| | | # code = "002094" |
| | | # l2_data_manager.load_l2_data(code) |
| | | # l2_data_manager.local_today_datas[code] = l2_data_manager.local_today_datas[code][0:520] |
| | | # buy_single_index = 426 |
| | | # buy_exec_index = 479 |
| | | # processor.random_key[code] = mock.Mock(return_value=123123) |
| | | # L2LimitUpMoneyStatisticUtil._L2LimitUpMoneyStatisticUtil__get_l2_latest_money_record = mock.Mock( |
| | | # return_value=(0, -1)) |
| | | # |
| | | # AverageBigNumComputer.place_order_success(code, buy_single_index, buy_exec_index) |
| | | # |
| | | # L2LimitUpMoneyStatisticUtil.process_data(code, buy_single_index, buy_exec_index, buy_single_index, |
| | | # buy_exec_index, False) |
| | | # |
| | | # l2_data_manager.TradePointManager().get_buy_compute_start_data = mock.Mock(return_value=(426, 479, 479, 0, 100)) |
| | | # buy_single_index, buy_exec_index, compute_index, num, count = l2_data_manager.TradePointManager().get_buy_compute_start_data( |
| | | # code) |
| | | # processor.unreal_buy_dict[code] = mock.Mock(return_value=(479, 167234623)) |
| | | # |
| | | # |
| | | # processor.process_order(code, 480, 519, 167234623, False) |
| | | # print(buy_single_index, buy_exec_index, compute_index, num, count) |
| | | yesterday_codes = kpl_data_manager.get_yesterday_limit_up_codes() |
| | | if yesterday_codes is None: |
| | | yesterday_codes = set() |
| | | result = RadicalBuyBlockManager.is_radical_buy(code, yesterday_codes) |
| | | print(code, result) |
| | | if result[0]: |
| | | can_buy_result = RadicalBuyDataManager.is_code_can_buy(code) |
| | | if can_buy_result[0]: |
| | | print("可以买", code, result) |
| | | else: |
| | | print("不可以买", code, can_buy_result) |
| | | |
| | | # l2.l2_data_manager_new.L2TradeDataProcessor.can_buy_first(code, None) |
| | | |
| | | # class TestData(unittest.TestCase): |
| | | # code = "002103" |
| | | # # l2_data_manager.load_l2_data(code) |
| | | # # TradeBuyQueue().save_traded_index(code, "6.94", [1511, 888, 796]) |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_add_transaction_orders(self): |
| | | code = "603359" |
| | | date = "2024-03-14" |
| | | data_map = log_export.load_huaxin_transaction_map(date=date) |
| | | for code in data_map: |
| | | datas = data_map[code] |
| | | for d in datas: |
| | | big_sell_order_info = HuaXinSellOrderStatisticManager.add_transaction_datas(code, d) |
| | | |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_b_cancel(self): |
| | | code = "603032" |
| | | l2.l2_data_util.load_l2_data(code) |
| | | total_datas = l2.l2_data_util.local_today_datas.get(code) |
| | | TradeBuyQueue.get_traded_index = mock.Mock(return_value=(1000, False)) |
| | | cancel_buy_strategy.NewGCancelBigNumComputer().set_real_place_order_index(code, 1015, 10000, False) |
| | | cancel_buy_strategy.GCancelBigNumComputer().set_trade_progress(code, 1000, 1000) |
| | | result = cancel_buy_strategy.GCancelBigNumComputer().need_cancel_for_b(code, 1020, 1077) |
| | | print(result) |
| | | |
| | | # |
| | | @unittest.skip("跳过此单元测试") |
| | | def test_transaction(self): |
| | | threading.Thread(target=async_log_util.run_sync, daemon=True).start() |
| | | code = "003019" |
| | | l2.l2_data_util.load_l2_data(code) |
| | | # 读取成交数据 |
| | | transaction_map = log_export.load_huaxin_transaction_map() |
| | | fdatas = transaction_map.get(code) |
| | | for d in fdatas: |
| | | l2_transaction_data_processor.HuaXinTransactionDatasProcessor().process_huaxin_transaction_datas(code, d) |
| | | |
| | | def test_cancel(self): |
| | | code = "603300" |
| | | l2.l2_data_util.load_l2_data(code) |
| | | TradeBuyQueue.get_traded_index = mock.Mock(return_value=(3742, False)) |
| | | l2.cancel_buy_strategy.RDCancelBigNumComputer._RDCancelBigNumComputer__watch_indexes_cache ={ code: {3686, 3691, 3693, 3694, 3699, 3700}} |
| | | l2.cancel_buy_strategy.RDCancelBigNumComputer().need_cancel(code, 4370, 4372) |
| | | |
| | | |
| | | class TestTradedProgress(unittest.TestCase): |
| | | @unittest.skip("跳过此单元测试") |