From 7eb1a8ed1a007d80de41d131071ee38f5872700c Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 07 二月 2025 14:26:37 +0800 Subject: [PATCH] 辨识度票策略修改/恢复P撤/上传订阅涨幅 --- l2_data_parser.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 95 insertions(+), 10 deletions(-) diff --git a/l2_data_parser.py b/l2_data_parser.py index 0d0a4d9..b7feec4 100644 --- a/l2_data_parser.py +++ b/l2_data_parser.py @@ -2,28 +2,113 @@ L2鏁版嵁瑙f瀽鍣� """ import csv +import os import sys +from db import mysql_data_delegate as mysql_data -def parse_order_detail(): - with open('/home/userzjj/ftp/20250123/OrderDetail.csv', 'r', encoding='utf-8') as file: +def __get_target_codes(day): + results = mysql_data.Mysqldb().select_all(f"select _code from kpl_limit_up_record where _day='{day}'") + codes = set([x[0] for x in results]) + return codes + + +def parse_order_detail(day): + target_codes = __get_target_codes(day) + base_path = f"/home/userzjj/ftp/{day}" + with open(f"{base_path}/OrderDetail.csv", 'r', encoding='utf-8') as file: csv_reader = csv.reader(file) # 鑾峰彇琛ㄥご锛�: ['ExchangeID', 'SecurityID', 'OrderTime', 'Price', 'Volume', 'Side', 'OrderType', 'MainSeq', 'SubSeq', 'Info1', 'Info2', 'Info3', 'OrderNO', 'OrderStatus', 'BizIndex', 'LocalTimeStamp'] headers = next(csv_reader) print("琛ㄥご:", headers) # 閬嶅巻鏁版嵁琛� - max_count = 10 - count = 0 - for row in csv_reader: - print(row) - count += 1 - if count > max_count: - break + _path = f"{base_path}/OrderDetail_filter.csv" + with open(_path, 'w', newline='', encoding='utf-8') as csvfile: + # 鍒涘缓涓�涓� CSV 鍐欏叆鍣ㄥ璞� + writer = csv.writer(csvfile) + # 閫愯鍐欏叆鏁版嵁 + for row in csv_reader: + if row[1] not in target_codes: + continue + # 灏嗘枃浠跺啓鍏ュ埌鏂囨湰 + writer.writerow(row) + + +def parse_transaction(day): + target_codes = __get_target_codes(day) + base_path = f"/home/userzjj/ftp/{day}" + with open(f"{base_path}/Transaction.csv", 'r', encoding='utf-8') as file: + csv_reader = csv.reader(file) + # 鑾峰彇琛ㄥご锛�: [ExchangeID,SecurityID,TradeTime,TradePrice,TradeVolume,ExecType,MainSeq,SubSeq,BuyNo,SellNo,Info1,Info2,Info3,TradeBSFlag,BizIndex,LocalTimeStamp] + headers = next(csv_reader) + print("琛ㄥご:", headers) + # 閬嶅巻鏁版嵁琛� + _path = f"{base_path}/Transaction_filter.csv" + with open(_path, 'w', newline='', encoding='utf-8') as csvfile: + # 鍒涘缓涓�涓� CSV 鍐欏叆鍣ㄥ璞� + writer = csv.writer(csvfile) + # 閫愯鍐欏叆鏁版嵁 + for row in csv_reader: + if row[1] not in target_codes: + continue + # 灏嗘枃浠跺啓鍏ュ埌鏂囨湰 + writer.writerow(row) + + +def parse_ngtstick(day): + target_codes = __get_target_codes(day) + base_path = f"/home/userzjj/ftp/{day}" + with open(f"{base_path}/NGTSTick.csv", 'r', encoding='utf-8') as file: + csv_reader = csv.reader(file) + # 鑾峰彇琛ㄥご锛�: [ExchangeID,SecurityID,MainSeq,SubSeq,TickTime,TickType,BuyNo,SellNo,Price,Volume,TradeMoney,Side,TradeBSFlag,MDSecurityStat,Info1,Info2,Info3,LocalTimeStamp] + headers = next(csv_reader) + print("琛ㄥご:", headers) + # 閬嶅巻鏁版嵁琛� + _path = f"{base_path}/NGTSTick_filter.csv" + with open(_path, 'w', newline='', encoding='utf-8') as csvfile: + # 鍒涘缓涓�涓� CSV 鍐欏叆鍣ㄥ璞� + writer = csv.writer(csvfile) + # 閫愯鍐欏叆鏁版嵁 + for row in csv_reader: + if row[1] not in target_codes: + continue + # 灏嗘枃浠跺啓鍏ュ埌鏂囨湰 + writer.writerow(row) + + +def parse_market_data(day): + target_codes = __get_target_codes(day) + base_path = f"/home/userzjj/ftp/{day}" + with open(f"{base_path}/MarketData.csv", 'r', encoding='utf-8') as file: + csv_reader = csv.reader(file) + # 鑾峰彇琛ㄥご锛�: [SecurityID,ExchangeID,DataTimeStamp,PreClosePrice,OpenPrice,NumTrades,TotalVolumeTrade,TotalValueTrade,TotalBidVolume,AvgBidPrice,TotalAskVolume,AvgAskPrice,HighestPrice,LowestPrice,LastPrice,BidPrice1,BidVolume1,AskPrice1,AskVolume1....] + headers = next(csv_reader) + print("琛ㄥご:", headers) + # 閬嶅巻鏁版嵁琛� + _path = f"{base_path}/MarketData_filter.csv" + with open(_path, 'w', newline='', encoding='utf-8') as csvfile: + # 鍒涘缓涓�涓� CSV 鍐欏叆鍣ㄥ璞� + writer = csv.writer(csvfile) + # 閫愯鍐欏叆鏁版嵁 + for row in csv_reader: + if row[0] not in target_codes: + continue + # 灏嗘枃浠跺啓鍏ュ埌鏂囨湰 + writer.writerow(row) if __name__ == '__main__': if len(sys.argv) > 1: params = sys.argv[1:] print("鎺ユ敹鐨勫弬鏁�", params) + _type = params[0].strip() + day = params[1].strip() + if _type == 'OrderDetail': + parse_order_detail(day) + elif _type == 'Transaction': + parse_transaction(day) + elif _type == 'NGTSTick': + parse_ngtstick(day) + elif _type == 'MarketData': + parse_market_data(day) - parse_order_detail() -- Gitblit v1.8.0