Administrator
2025-04-09 3843348344ddac2a8846af7f88b977762d85617a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
L2数据解析器
"""
import csv
import os
import sys
from db import mysql_data_delegate as mysql_data
 
 
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, code):
    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)
        # 遍历数据行
        _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
                if code and code != row[1]:
                    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 len(params)>2:
            code = params[2].strip()
        else:
            code = None
        if _type == 'OrderDetail':
            parse_order_detail(day, code)
        elif _type == 'Transaction':
            parse_transaction(day)
        elif _type == 'NGTSTick':
            parse_ngtstick(day)
        elif _type == 'MarketData':
            parse_market_data(day)