Skip to content

Commit

Permalink
fix order warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxrk committed Jul 13, 2024
1 parent bbdf540 commit 206c787
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
34 changes: 27 additions & 7 deletions firstrade/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ def place_order(
Order:order_confirmation: Dictionary containing the order confirmation data.
"""

if dry_run:
previewOrders = "1"
else:
previewOrders = ""

if price_type == PriceType.MARKET:
price = ""
Expand All @@ -100,8 +96,8 @@ def place_order(
"orderbar_accountid": "",
"notional": "yes" if notional else "",
"stockorderpage": "yes",
"submitOrders": "1",
"previewOrders": previewOrders,
"submitOrders": "",
"previewOrders": "1",
"lotMethod": "1",
"accountType": "1",
"quoteprice": "",
Expand All @@ -125,14 +121,38 @@ def place_order(
"cond_compare_type0_1": "2",
"cond_compare_value0_1": "",
}

order_data = BeautifulSoup(
self.ft_session.post(
url=urls.orderbar(), headers=urls.session_headers(), data=data
).text,
"xml",
)
order_confirmation = {}
cdata = order_data.find("actiondata").string
cdata_soup = BeautifulSoup(cdata, "html.parser")
span = (
cdata_soup.find('div', class_='msg_bg')
.find('div', class_='yellow box')
.find('div', class_='error_msg')
.find('div', class_='outbox')
.find('div', class_='inbox')
.find('span')
)
if span:
order_warning = span.text.strip()
order_confirmation["warning"] = order_warning
data["viewederror"] = "1"
if not dry_run:
data["previewOrders"] = ""
data["submitOrders"] = "1"
order_data = BeautifulSoup(
self.ft_session.post(
url=urls.orderbar(), headers=urls.session_headers(), data=data
).text,
"xml",
)

order_success = order_data.find("success").text.strip()
order_confirmation["success"] = order_success
action_data = order_data.find("actiondata").text.strip()
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

setuptools.setup(
name="firstrade",
version="0.0.19",
version="0.0.20",
author="MaxxRK",
author_email="[email protected]",
description="An unofficial API for Firstrade",
long_description=long_description,
long_description_content_type="text/markdown",
license="MIT",
url="https://github.com/MaxxRK/firstrade-api",
download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0019.tar.gz",
download_url="https://github.com/MaxxRK/firstrade-api/archive/refs/tags/0020.tar.gz",
keywords=["FIRSTRADE", "API"],
install_requires=["requests", "beautifulsoup4", "lxml"],
packages=["firstrade"],
Expand Down

0 comments on commit 206c787

Please sign in to comment.