Administrator
2025-06-24 50805343f897aadad3da99c3dacefcbc095455e5
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
"""
交易记录日志工具
"""
 
# 下单信息
import json
 
from log_module import async_log_util, log_export
from log_module.log import logger_trade_record
from utils import tool
 
TYPE_PLACE_ORDER = "place_order"  # 下单
TYPE_REAL_PLACE_ORDER_POSITION = "real_place_order_position"  # 真实下单位置
TYPE_CANCEL_WATCH_INDEXES = "cancel_watch_indexes"  # 撤单监听位置
TYPE_FORBIDDEN_BUY = "forbidden_buy"  # 禁止买入
TYPE_CANT_PLACE_ORDER = "can_not_place_order"  # 不能下单
TYPE_CANCEL = "cancel"  # 撤单
TYPE_ACTION = "action"  # 针对代码的操作
 
 
class PlaceOrderInfo(object):
    def __init__(self, code=None, time_str=None, price=None, rate=None, plates=None, plates_info=None, info=None):
        """
        初始化
        @param code: 代码
        @param time_str: 时间
        @param price: 价格
        @param rate: 涨幅
        @param plates: 板块
        @param info: 信息
        """
        self.code = code
        self.time_str = time_str
        self.price = price
        self.rate = rate
        self.plates = plates
        self.plates_info = plates_info
        self.info = info
 
    def to_json_str(self):
        return json.dumps(vars(self))
 
    def to_dict(self):
        return vars(self)
 
    @classmethod
    def to_object(cls, json_str: str):
        d = json.loads(json_str)
        return PlaceOrderInfo(**d)
 
 
# 添加日志
def __add_log(type_, code, data):
    try:
        fdata = {"code": code, "type": type_, "data": data}
        async_log_util.info(logger_trade_record, json.dumps(fdata, cls=tool.SetEncoder))
    except:
        pass
 
 
# 添加下单日志
def add_place_order_log(code, info: PlaceOrderInfo):
    __add_log(TYPE_PLACE_ORDER, code, info.to_dict())
 
 
def get_trade_records(type_, day=tool.get_now_date_str()):
    """
    获取交易记录
    @param type_: 类型
    @param day: 日期
    @return:
    """
    return log_export.load_trade_recod_by_type(type_, day)
 
 
# 加白
def add_common_msg(code, type_, msg=""):
    __add_log(TYPE_ACTION, code, {"type": type_, "msg": msg})
 
 
if __name__ == "__main__":
    datas = get_trade_records(TYPE_PLACE_ORDER)
    print(len(datas))