| | |
| | | # 买入队列 |
| | | import itertools |
| | | import json |
| | | import time |
| | | |
| | | import constant |
| | | from db import redis_manager_delegate as redis_manager |
| | |
| | | |
| | | class TradeBuyQueue: |
| | | buy_progress_index_cache = {} |
| | | latest_buy_progress_index_cache = {} |
| | | # 成交速率 |
| | | trade_speed_cache = {} |
| | | |
| | | __db = 0 |
| | | __redis_manager = redis_manager.RedisManager(0) |
| | |
| | | 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) |
| | | if not last_info or last_info[0] != index: |
| | | if last_info: |
| | | val = total_datas[last_info[0]]['val'] |
| | | 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()) |
| | | self.__save_buy_progress_index(code, index, False) |
| | | |
| | | # 获取成交速率 |
| | | def get_trade_speed(self, code): |
| | | return self.trade_speed_cache.get(code) |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | a = [1, 2, 3, 4] |