From 206c787f15c06c26de0742a8caa573b96140cf3b Mon Sep 17 00:00:00 2001 From: maxxrk Date: Fri, 12 Jul 2024 21:10:41 -0500 Subject: [PATCH] fix order warnings --- firstrade/order.py | 34 +++++++++++++++++++++++++++------- setup.py | 4 ++-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/firstrade/order.py b/firstrade/order.py index a3efe9c..96e895e 100644 --- a/firstrade/order.py +++ b/firstrade/order.py @@ -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 = "" @@ -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": "", @@ -125,7 +121,7 @@ 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 @@ -133,6 +129,30 @@ def place_order( "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() diff --git a/setup.py b/setup.py index f823c4a..3c282b0 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="firstrade", - version="0.0.19", + version="0.0.20", author="MaxxRK", author_email="maxxrk@pm.me", description="An unofficial API for Firstrade", @@ -13,7 +13,7 @@ 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"],