| | |
| | | # 买入队列 |
| | | import itertools |
| | | import json |
| | | import time |
| | | |
| | | import constant |
| | | from db import redis_manager |
| | | from db.redis_manager import RedisUtils |
| | | from db import redis_manager_delegate as redis_manager |
| | | from db.redis_manager_delegate import RedisUtils |
| | | from utils import tool |
| | | import l2.l2_data_util |
| | | from log_module.log import logger_l2_trade_buy_queue, logger_l2_trade_buy_progress |
| | |
| | | |
| | | class TradeBuyQueue: |
| | | buy_progress_index_cache = {} |
| | | latest_buy_progress_index_cache = {} |
| | | # 成交速率 |
| | | trade_speed_cache = {} |
| | | |
| | | __db = 0 |
| | | __redis_manager = redis_manager.RedisManager(0) |
| | |
| | | return None |
| | | self.last_buy_queue_data[code] = queues |
| | | |
| | | if abs(float(buy_1_price) - float(limit_up_price)) >= 0.01: |
| | | if abs(float(buy_1_price) - float(limit_up_price)) >= 0.001: |
| | | # 保存最近的涨停起始时间 |
| | | self.__save_latest_not_limit_up_time(code, buy_1_time) |
| | | return None |
| | |
| | | index, is_default = self.__get_buy_progress_index_cache(code) |
| | | return index, is_default |
| | | |
| | | def set_traded_index(self, code, index): |
| | | # 设置交易进度 |
| | | def set_traded_index(self, code, index, total_datas = None): |
| | | last_info = self.latest_buy_progress_index_cache.get(code) |
| | | # 交易进度是否改变 |
| | | traded_index_changed = False |
| | | if not last_info or last_info[0] != index: |
| | | if last_info and total_datas: |
| | | val = total_datas[last_info[0]]['val'] |
| | | if time.time() - last_info[1] > 0: |
| | | rate = round(val["num"] * float(val["price"]) * 100 / (time.time() - last_info[1])) |
| | | # 成交速率 |
| | | self.trade_speed_cache[code] = rate |
| | | self.latest_buy_progress_index_cache[code] = (index, time.time()) |
| | | traded_index_changed = True |
| | | self.__save_buy_progress_index(code, index, False) |
| | | return traded_index_changed |
| | | |
| | | # 获取成交速率 |
| | | def get_trade_speed(self, code): |
| | | return self.trade_speed_cache.get(code) |
| | | |
| | | |
| | | if __name__ == '__main__': |