| | |
| | | |
| | | import array |
| | | import logging |
| | | import re |
| | | import threading |
| | | import time |
| | | import random |
| | | |
| | | import numpy |
| | | import win32gui |
| | | import win32con |
| | | |
| | | import constant |
| | | from ocr import ocr_util |
| | | from trade import l2_trade_util |
| | | from db import redis_manager |
| | | from log import * |
| | | from tool import async_call |
| | | from utils import win32_util |
| | | from utils import win32_util, capture_util |
| | | |
| | | |
| | | class THSGuiTrade(object): |
| | |
| | | # raise Exception(error) |
| | | |
| | | # TODO 暂时不验证涨停价 |
| | | if not constant.TEST: |
| | | if abs(float(limit_up_price_now) - float(limit_up_price)) >= 0.01: |
| | | error = "涨停价验证出错 {}-{}".format(limit_up_price, limit_up_price_now) |
| | | raise Exception(error) |
| | | # if not constant.TEST: |
| | | # if abs(float(limit_up_price_now) - float(limit_up_price)) >= 0.01: |
| | | # error = "涨停价验证出错 {}-{}".format(limit_up_price, limit_up_price_now) |
| | | # raise Exception(error) |
| | | |
| | | # 开始交易,买入按钮ID:0x000003EE |
| | | # buy_hwnd = win32gui.GetDlgItem(win, 0x000003EE) |
| | |
| | | self.buy_cancel_locks[w] = threading.RLock() |
| | | |
| | | |
| | | |
| | | |
| | | class THSGuiUtil: |
| | | @classmethod |
| | | def getText(cls, hwnd): |
| | |
| | | if win in win_set: |
| | | win_set.remove(win) |
| | | if len(win_set) > 0: |
| | | return win_set.pop() |
| | | win_list = list(win_set) |
| | | random.shuffle(win_list) |
| | | return win_list[0] |
| | | |
| | | # 没有剩余的窗口,新增加窗口 |
| | | raise Exception("没有剩余窗口") |
| | |
| | | THSGuiUtil.set_buy_window_code(cls.get_trade_win(win), code) |
| | | time.sleep(0.5) |
| | | code_name_win = cls.__get_code_name(win) |
| | | if code_name == code_name_win: |
| | | is_success = True |
| | | break |
| | | if code_name == code_name_win or code_name_win.find(code_name) > -1: |
| | | if cls.__is_buy_limit_up_price(win): |
| | | is_success = True |
| | | break |
| | | else: |
| | | cls.__del_code_win(code) |
| | | THSGuiUtil.set_buy_window_code(cls.get_trade_win(win), "") |
| | | raise Exception("不是买涨停价") |
| | | if is_success: |
| | | logger_buy_win_distibute.info(f"新分配窗口成功:{code}-{win}") |
| | | else: |
| | |
| | | name = name.replace(" ", "") |
| | | return tool.strQ2B(name) |
| | | |
| | | # 是否是涨停价 |
| | | @classmethod |
| | | def __is_buy_limit_up_price(cls, win): |
| | | trade_win = cls.get_trade_win(win) |
| | | if trade_win is None: |
| | | return None |
| | | price_win = win32gui.GetDlgItem(trade_win, 0x00000409) |
| | | ocr_result = ocr_util.OcrUtil.ocr_with_key(capture_util.window_capture(price_win), "涨停价|张停价") |
| | | if ocr_result: |
| | | return True |
| | | return False |
| | | |
| | | @classmethod |
| | | def fill_codes(cls, codes): |
| | | name_codes = gpcode_manager.get_name_codes() |
| | |
| | | new_delete_codes.append(code) |
| | | |
| | | cancel_wins = THSGuiTrade.getCancelBuyWins() |
| | | add_codes_num = len(cancel_wins)*10 |
| | | add_codes_num = len(cancel_wins) * 10 |
| | | add_codes = new_codes[0:add_codes_num] |
| | | del_codes = new_codes[add_codes_num:] |
| | | del_codes.extend(new_delete_codes) |
| | |
| | | print("分配的窗口:", win, THSGuiUtil.is_win_exist(win)) |
| | | except Exception as e: |
| | | logging.exception(e) |
| | | |
| | | |
| | | # 根据涨幅高低分配交易窗口 |
| | | def re_distribute_buy_win(codes): |
| | | THSBuyWinManagerNew.fill_codes(codes) |
| | | |
| | | |
| | | class GUITest: |
| | |
| | | |
| | | |
| | | if __name__ == '__main__': |
| | | pass |
| | | # try: |
| | | # THSGuiTrade().cancel_buy_again("000637") |
| | | # except Exception as e: |
| | | # print(e) |
| | | print(THSGuiTrade().cancel_buy("000582")) |
| | | print(ocr_util.OcrUtil.ocr_with_key(capture_util.window_capture(0x000314EA), "涨停价|张停价")) |
| | | |
| | | # THSGuiTrade().buy("600613", 10.29) |