Skip to content

Commit 206c787

Browse files
author
maxxrk
committed
fix order warnings
1 parent bbdf540 commit 206c787

2 files changed

Lines changed: 29 additions & 9 deletions

File tree

firstrade/order.py

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,6 @@ def place_order(
8686
Order:order_confirmation: Dictionary containing the order confirmation data.
8787
"""
8888

89-
if dry_run:
90-
previewOrders = "1"
91-
else:
92-
previewOrders = ""
9389

9490
if price_type == PriceType.MARKET:
9591
price = ""
@@ -100,8 +96,8 @@ def place_order(
10096
"orderbar_accountid": "",
10197
"notional": "yes" if notional else "",
10298
"stockorderpage": "yes",
103-
"submitOrders": "1",
104-
"previewOrders": previewOrders,
99+
"submitOrders": "",
100+
"previewOrders": "1",
105101
"lotMethod": "1",
106102
"accountType": "1",
107103
"quoteprice": "",
@@ -125,14 +121,38 @@ def place_order(
125121
"cond_compare_type0_1": "2",
126122
"cond_compare_value0_1": "",
127123
}
128-
124+
129125
order_data = BeautifulSoup(
130126
self.ft_session.post(
131127
url=urls.orderbar(), headers=urls.session_headers(), data=data
132128
).text,
133129
"xml",
134130
)
135131
order_confirmation = {}
132+
cdata = order_data.find("actiondata").string
133+
cdata_soup = BeautifulSoup(cdata, "html.parser")
134+
span = (
135+
cdata_soup.find('div', class_='msg_bg')
136+
.find('div', class_='yellow box')
137+
.find('div', class_='error_msg')
138+
.find('div', class_='outbox')
139+
.find('div', class_='inbox')
140+
.find('span')
141+
)
142+
if span:
143+
order_warning = span.text.strip()
144+
order_confirmation["warning"] = order_warning
145+
data["viewederror"] = "1"
146+
if not dry_run:
147+
data["previewOrders"] = ""
148+
data["submitOrders"] = "1"
149+
order_data = BeautifulSoup(
150+
self.ft_session.post(
151+
url=urls.orderbar(), headers=urls.session_headers(), data=data
152+
).text,
153+
"xml",
154+
)
155+
136156
order_success = order_data.find("success").text.strip()
137157
order_confirmation["success"] = order_success
138158
action_data = order_data.find("actiondata").text.strip()

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66
setuptools.setup(
77
name="firstrade",
8-
version="0.0.19",
8+
version="0.0.20",
99
author="MaxxRK",
1010
author_email="maxxrk@pm.me",
1111
description="An unofficial API for Firstrade",
1212
long_description=long_description,
1313
long_description_content_type="text/markdown",
1414
license="MIT",
1515
url="https://github.com/MaxxRK/firstrade-api",
16-
download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0019.tar.gz",
16+
download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0020.tar.gz",
1717
keywords=["FIRSTRADE", "API"],
1818
install_requires=["requests", "beautifulsoup4", "lxml"],
1919
packages=["firstrade"],

0 commit comments

Comments
 (0)