| | |
| | | |
| | | import big_money_num_manager |
| | | import code_volumn_manager |
| | | import data_process |
| | | import global_util |
| | | import gpcode_manager |
| | | import threading |
| | |
| | | |
| | | |
| | | def on_tick(context, tick): |
| | | if global_util.TEST: |
| | | return |
| | | # print(tick["created_at"]) |
| | | relative_timestamp = t.time() % (24 * 60 * 60) + 8 * 60 * 60 |
| | | # 9点20-15:05接受数据 |
| | | start1 = 60 * 60 * 9 + 24 * 60; |
| | | end1 = 60 * 60 * 11 + 35 * 60; |
| | | start2 = 60 * 60 * 12 + 50 * 60; |
| | | end2 = 60 * 60 * 15 + 5 * 60; |
| | | start1 = 60 * 60 * 9 + 31 * 60 |
| | | end1 = 60 * 60 * 11 + 35 * 60 |
| | | start2 = 60 * 60 * 12 + 50 * 60 |
| | | end2 = 60 * 60 * 15 + 5 * 60 |
| | | # TODO 测试 |
| | | if (start1 < relative_timestamp < end1 or start2 < relative_timestamp < end2) or global_util.TEST: |
| | | symbol = tick['symbol'] |
| | |
| | | # 移除监控 |
| | | if gpcode_manager.is_listen(code) and not gpcode_manager.is_operate(code): |
| | | L2CodeOperate.get_instance().add_operate(0, code, "现价变化") |
| | | |
| | | |
| | | # 获取到现价 |
| | | def accpt_prices(prices): |
| | | now_str = datetime.datetime.now().strftime("%H:%M:%S") |
| | | now_strs = now_str.split(":") |
| | | now_second = int(now_strs[0]) * 60 * 60 + int(now_strs[1]) * 60 + int(now_strs[2]) |
| | | start = 60 * 60 * 9 + 31 * 60 |
| | | if now_second > start: |
| | | for d in prices: |
| | | code, price = d["code"], float(d["price"]) |
| | | accpt_price(code, price) |
| | | else: |
| | | _code_list = [] |
| | | _delete_list = [] |
| | | for d in prices: |
| | | code, price = d["code"], float(d["price"]) |
| | | gpcode_manager.set_price(code, price) |
| | | # 获取收盘价 |
| | | pricePre = gpcode_manager.get_price_pre(code) |
| | | if pricePre is not None: |
| | | rate = round((price - pricePre) * 100 / pricePre, 1) |
| | | if rate >= 0: |
| | | _code_list.append((rate, code)) |
| | | else: |
| | | _delete_list.append((rate, code)) |
| | | # 排序 |
| | | new_code_list = sorted(_code_list, key=lambda e: e.__getitem__(0), reverse=True) |
| | | client_ids = data_process.getValidL2Clients() |
| | | max_count = len(client_ids) * 8 |
| | | add_list = new_code_list[:max_count] |
| | | _delete_list.extend(new_code_list[max_count:]) |
| | | |
| | | add_code_list = [] |
| | | del_list = [] |
| | | for d in add_list: |
| | | add_code_list.append(d[1]) |
| | | |
| | | for d in _delete_list: |
| | | del_list.append(d[1]) |
| | | |
| | | for code in add_code_list: |
| | | L2CodeOperate.get_instance().add_operate(1, code, "现价变化") |
| | | |
| | | for code in del_list: |
| | | L2CodeOperate.get_instance().add_operate(0, code, "现价变化") |
| | | |
| | | print(add_code_list, del_list) |
| | | |
| | | |
| | | def on_bar(context, bars): |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | everyday_init() |
| | | accpt_prices_before_open([{"code": "001332", "price": "82.37"}, {"code": "002246", "price": "10.10"}, |
| | | {"code": "600537", "price": "6.65"}]) |