Repository navigation
Expand file tree
/
Copy pathSellAtTargetOnly.py
More file actions
71 lines (58 loc) · 2.31 KB
/
Copy pathSellAtTargetOnly.py
File metadata and controls
71 lines (58 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
def time_sleep(t):
for i in range(t):
time.sleep(1)
print(t - i)
PRICE = "766"
# Initialize WebDriver (Assuming you are using Chrome)
driver = webdriver.Chrome()
try:
# Load the initial webpage
driver.get("https://tms58.nepsetms.com.np/tms/me/memberclientorderentry")
# Wait for 20 seconds to allow manual login
done = input("Done? (Press Enter if done)")
# Reload the webpage to ensure proper loading post-login
driver.get("https://tms58.nepsetms.com.np/tms/me/memberclientorderentry")
# Wait for 25 seconds to allow manual setting of stock symbol and quantity
done = input("Entered script and quantity and pressed toggle? (Press Enter if done)")
# Locate the price input box and the sell button
price_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input.form-control.form-control-sm.form-price"))
)
print("Price input box located")
price_input.clear()
price_input.send_keys(PRICE)
# Define a more specific selector for the SELL button
sell_button_selector = "button.btn.btn-sm.btn-danger[type='submit']"
noErrFlag = False
while not noErrFlag:
try:
print("Trying to locate sell button")
sell_button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, sell_button_selector))
)
print("sell button found and clickable")
noErrFlag = True
except Exception as e:
print(f"Exception occurred: {e}")
noErrFlag = False
pass
# Function to enter the price and click the sell button
def enter_price_and_sell():
print("Entering price")
price_input.clear()
price_input.send_keys(PRICE)
print("Clicking sell button")
sell_button.click()
# Continuously enter the price and press the sell button every 10 seconds
while True:
print("Calling enter_price_and_sell")
enter_price_and_sell()
time.sleep(0.1)
finally:
driver.quit()