Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

设置交易类型,配置 #437

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions easytrader/clienttrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,23 @@ def today_entrusts(self):

return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID)

@property
def history_entrusts(self):
self._switch_left_menus(["查询[F4]", "历史委托"])

return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID)

@property
def today_trades(self):
self._switch_left_menus(["查询[F4]", "当日成交"])

return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID)

def history_trades(self):
self._switch_left_menus(["查询[F4]", "历史成交"])

return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID)

@property
def cancel_entrusts(self):
self.refresh()
Expand Down Expand Up @@ -454,11 +465,14 @@ def _set_trade_params(self, security, price, amount):
# wait security input finish
self.wait(0.1)

# close the popup dialog to prompt selecting stock exchange type
self._handle_pop_dialogs()

# 设置交易所
if security.lower().startswith("sz"):
self._set_stock_exchange_type("深圳A股")
self._set_stock_exchange_type(self._config.TRADE_STOCK_EXCHANGE_TYPE_SZA)
if security.lower().startswith("sh"):
self._set_stock_exchange_type("上海A股")
self._set_stock_exchange_type(self._config.TRADE_STOCK_EXCHANGE_TYPE_SHA)

self.wait(0.1)

Expand Down
13 changes: 11 additions & 2 deletions easytrader/config/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ class CommonConfig:
# 交易所类型。 深圳A股、上海A股
TRADE_STOCK_EXCHANGE_CONTROL_ID = 1003

TRADE_STOCK_EXCHANGE_TYPE_SZA = "深圳A股"
TRADE_STOCK_EXCHANGE_TYPE_SHA = "上海A股"

# 撤销界面上, 全部撤销按钮
TRADE_CANCEL_ALL_ENTRUST_CONTROL_ID = 30001

Expand Down Expand Up @@ -82,7 +85,10 @@ class CommonConfig:


class YH(CommonConfig):
DEFAULT_EXE_PATH = r"C:\双子星-中国银河证券\Binarystar.exe"
DEFAULT_EXE_PATH = r"C:\双子星金融终端独立交易-中国银河证券\xiadan.exe"

TRADE_STOCK_EXCHANGE_TYPE_SZA = "深A"
TRADE_STOCK_EXCHANGE_TYPE_SHA = "沪A"

BALANCE_GRID_CONTROL_ID = 1308

Expand All @@ -102,7 +108,10 @@ class YH(CommonConfig):


class HT(CommonConfig):
DEFAULT_EXE_PATH = r"C:\htzqzyb2\xiadan.exe"
DEFAULT_EXE_PATH = r"C:\htwt\xiadan.exe"

TRADE_STOCK_EXCHANGE_TYPE_SZA = "深圳A"
TRADE_STOCK_EXCHANGE_TYPE_SHA = "上海A"

BALANCE_CONTROL_ID_GROUP = {
"资金余额": 1012,
Expand Down
2 changes: 1 addition & 1 deletion easytrader/grid_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _set_foreground(self, grid=None):
if grid.has_style(win32defines.WS_MINIMIZE): # if minimized
ShowWindow(grid.wrapper_object(), 9) # restore window state
else:
SetForegroundWindow(grid.wrapper_object()) # bring to front
SetForegroundWindow(grid.wrapper_object().handle) # bring to front
except:
pass

Expand Down
2 changes: 1 addition & 1 deletion easytrader/ht_clienttrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def login(self, user, password, exe_path, comm_password=None, **kwargs):
self._app.top_window().Edit1.type_keys(user)
self._app.top_window().Edit2.type_keys(password)

self._app.top_window().Edit3.set_edit_text(comm_password)
#self._app.top_window().Edit3.set_edit_text(comm_password)

self._app.top_window().button0.click()

Expand Down
13 changes: 10 additions & 3 deletions easytrader/pop_dialog_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _set_foreground(window):
if window.has_style(win32defines.WS_MINIMIZE): # if minimized
ShowWindow(window.wrapper_object(), 9) # restore window state
else:
SetForegroundWindow(window.wrapper_object()) # bring to front
SetForegroundWindow(window.wrapper_object().handle) # bring to front

@perf_clock
def handle(self, title):
Expand All @@ -37,6 +37,9 @@ def handle(self, title):
def _extract_content(self):
return self._app.top_window().Static.window_text()

def _extract_content_edit(self):
return self._app.top_window().Edit.window_text()

@staticmethod
def _extract_entrust_id(content):
return re.search(r"[\da-zA-Z]+", content).group()
Expand Down Expand Up @@ -64,13 +67,17 @@ def handle(self, title) -> Optional[dict]:
self._submit_by_shortcut()
return None

if title == "风险提示":
self._submit_by_click()
return None

if title == "提示信息":
content = self._extract_content()
if "超出涨跌停" in content:
self._submit_by_shortcut()
return None

if "委托价格的小数价格应为" in content:
if "委托价格的小数" in content:
self._submit_by_shortcut()
return None

Expand All @@ -85,7 +92,7 @@ def handle(self, title) -> Optional[dict]:
return None

if title == "提示":
content = self._extract_content()
content = self._extract_content_edit()
if "成功" in content:
entrust_no = self._extract_entrust_id(content)
self._submit_by_click()
Expand Down
1 change: 0 additions & 1 deletion easytrader/refresh_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

from easytrader.log import logger
from easytrader.utils.captcha import captcha_recognize
from easytrader.utils.win_gui import SetForegroundWindow, ShowWindow, win32defines

if TYPE_CHECKING:
# pylint: disable=unused-import
Expand Down
17 changes: 17 additions & 0 deletions easytrader/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def get_today_entrusts():
return jsonify(today_entrusts), 200


@app.route("/history_entrusts", methods=["GET"])
@error_handle
def get_history_entrusts():
user = global_store["user"]
history_entrusts = user.history_entrusts

return jsonify(history_entrusts), 200


@app.route("/today_trades", methods=["GET"])
@error_handle
def get_today_trades():
Expand All @@ -81,6 +90,14 @@ def get_today_trades():
return jsonify(today_trades), 200


@app.route("/history_trades", methods=["GET"])
@error_handle
def get_history_trades():
user = global_store["user"]
history_trades = user.history_trades

return jsonify(history_trades), 200

@app.route("/cancel_entrusts", methods=["GET"])
@error_handle
def get_cancel_entrusts():
Expand Down
3 changes: 2 additions & 1 deletion easytrader/utils/win_gui.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding:utf-8
from pywinauto import win32defines
from pywinauto.win32functions import SetForegroundWindow, ShowWindow
from pywinauto.win32functions import ShowWindow
from win32gui import SetForegroundWindow
41 changes: 11 additions & 30 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
-i http://mirrors.aliyun.com/pypi/simple/
--trusted-host mirrors.aliyun.com
beautifulsoup4==4.6.0
bs4==0.0.1
certifi==2018.4.16
chardet==3.0.4
click==6.7
cssselect==1.0.3; python_version != '3.3.*'
dill==0.2.8.2
easyutils==0.1.7
flask==1.0.2
idna==2.7
itsdangerous==0.24
jinja2==2.10
lxml==4.2.3
markupsafe==1.0
numpy==1.15.0; python_version >= '2.7'
pandas==0.23.3
pillow==5.2.0
pyperclip==1.6.4
pyquery==1.4.0; python_version != '3.0.*'
pytesseract==0.2.4
python-dateutil==2.7.3
python-xlib==0.23
pytz==2018.5
pywinauto==0.6.6
requests==2.19.1
six==1.11.0
urllib3==1.23; python_version != '3.1.*'
werkzeug==0.14.1

Flask==2.3.2
pandas==2.0.3
Pillow==10.0.0
pytesseract==0.3.10
pywin32==306
pywinauto==0.6.8
Requests==2.31.0
#rqopen_client==0.0.6
setuptools==56.0.0
six==1.16.0
urllib3==2.0.4
3 changes: 3 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from easytrader import server

server.run(port=14433) # 默认端口为 1430