Skip to content

Commit

Permalink
order fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxxrk committed May 22, 2024
1 parent 763ad15 commit 04dd46e
Showing 1 changed file with 15 additions and 29 deletions.
44 changes: 15 additions & 29 deletions vanguard/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def place_order(
if account_id in account.text_content():
account.click()
break
except:
except PlaywrightTimeoutError:
pass
quote_box = self.session.page.wait_for_selector(
"//input[@placeholder='Get Quote']"
Expand Down Expand Up @@ -187,9 +187,7 @@ def place_order(
self.session.page.click("xpath=//label[text()='60-day (GTC)']")
if order_type == "SELL":
self.session.page.wait_for_selector(
"body > twe-root > main > twe-trade > form > div > div.row >"
" div:nth-child(1) > twe-cost-basis-control > twe-cost-basis-modal"
" > tds-modal > div.modal.visible > div > div.modal__content",
"body > twe-root > main > twe-trade > form > div > div.row > div:nth-child(1) > twe-cost-basis-control > twe-cost-basis-modal > tds-modal > div.modal.visible > div > div.modal__content",
timeout=10000,
)
self.session.page.wait_for_selector(
Expand All @@ -200,10 +198,7 @@ def place_order(
pass
try:
self.session.page.wait_for_selector(
"body > twe-root > main > twe-trade > form > div > div.row >"
" div.col-lg-6.col-xxl-4.tds-mb-9.d-none.d-xxl-block > twe-trade-detail"
" > tds-card > div > tds-card-body > div.twe-flex-button-wrap >"
" button:nth-child(2)",
"body > twe-root > vg-vgn-nav > div > main > twe-trade > form > div > div.row > div.col-lg-6.col-xxl-4.tds-mb-9.d-none.d-xxl-block > twe-trade-detail > tds-card > div > tds-card-body > div.twe-flex-button-wrap > button:nth-child(2)",
timeout=5000,
).click()
except PlaywrightTimeoutError:
Expand All @@ -220,10 +215,7 @@ def place_order(

try:
warning = self.session.page.wait_for_selector(
"body > twe-root > main > twe-trade > form > div > div.row >"
" div.col-lg-6.col-xxl-4.tds-mb-9.d-none.d-xxl-block > twe-trade-detail"
" > tds-card > div > tds-card-body > div:nth-child(3) > div > tds-card"
" > div > tds-card-body",
"body > twe-root > main > twe-trade > form > div > div.row > div.col-lg-6.col-xxl-4.tds-mb-9.d-none.d-xxl-block > twe-trade-detail > tds-card > div > tds-card-body > div:nth-child(3) > div > tds-card > div > tds-card-body",
timeout=5000,
)
warning_header_selector = warning.query_selector("p")
Expand All @@ -239,14 +231,12 @@ def place_order(

try:
order_preview = self.session.page.wait_for_selector(
"body > twe-root > main > twe-preview > div > div > div.col-lg-7 >"
" tds-card > div > tds-card-body > twe-order-details",
".col-lg-7 > tds-card:nth-child(1) > div:nth-child(1) > tds-card-body:nth-child(1)",
timeout=5000,
)
order_preview_text = order_preview.text_content()
preview_parts = re.split(
r"(Account|Transaction|Shares|Security|Order"
r" type|Duration|Commission|Estimated amount|\*)",
r"(Account|Transaction|Shares|Security|Order type|Duration|Commission|Estimated amount|\*)",
order_preview_text,
)
order_preview = {
Expand All @@ -261,28 +251,24 @@ def place_order(
"Note": preview_parts[20],
}
order_messages["ORDER PREVIEW"] = order_preview
if not dry_run:
try:
self.session.page.click(
"//button[text()=' Submit Order ']", timeout=10000
)
except PlaywrightTimeoutError:
raise Exception("No place order button found cannot continue.")
else:
if dry_run:
return order_messages
try:
self.session.page.click(
"//button[text()=' Submit Order ']", timeout=10000
)
except PlaywrightTimeoutError:
raise Exception("No place order button found cannot continue.")
except PlaywrightTimeoutError:
order_messages["ORDER PREVIEW"] = "No order preview page found."

try:
order_handle_one = self.session.page.wait_for_selector(
"body > twe-root > main > twe-confirm > div > div >"
" div.col-lg-7.order-first.order-lg-last.tds-mb-4.tds-mb-m-9 > h2",
"body > twe-root > vg-vgn-nav > div > main > twe-confirm > div > div > div.col-lg-7.order-first.order-lg-last.tds-mb-4.tds-mb-m-9 > h2",
timeout=5000,
)
order_handle_two = self.session.page.wait_for_selector(
"body > twe-root > main > twe-confirm > div > div >"
" div.col-lg-7.order-first.order-lg-last.tds-mb-4.tds-mb-m-9 >"
" div.page-heading.tds-mb-7",
"body > twe-root > vg-vgn-nav > div > main > twe-confirm > div > div > div.col-lg-7.order-first.order-lg-last.tds-mb-4.tds-mb-m-9 > div.page-heading.tds-mb-7 > p",
timeout=5000,
)
order_number_text = order_handle_one.text_content()
Expand Down

0 comments on commit 04dd46e

Please sign in to comment.