From c25ca04703092a997bc1f0ead1a7d9479893c940 Mon Sep 17 00:00:00 2001 From: Administrator <admin@example.com> Date: 星期五, 24 一月 2025 15:36:31 +0800 Subject: [PATCH] L2历史数据解析 --- l2_data_parser.py | 70 +++++++++++++++++++++++++++++++++++ 1 files changed, 70 insertions(+), 0 deletions(-) diff --git a/l2_data_parser.py b/l2_data_parser.py index 0960ea9..f2b2d32 100644 --- a/l2_data_parser.py +++ b/l2_data_parser.py @@ -34,6 +34,69 @@ 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:] @@ -42,3 +105,10 @@ day = params[1].strip() if _type == 'OrderDetail': parse_order_detail(day) + elif _type == 'Transaction': + parse_transaction(day) + elif _type == 'XTSTick': + parse_ngtstick(day) + elif _type == 'MarketData': + parse_market_data(day) + -- Gitblit v1.8.0