forked from ChipaDevTeam/BinaryOptionsTools-v2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_raw_order.py
More file actions
53 lines (44 loc) · 1.82 KB
/
create_raw_order.py
File metadata and controls
53 lines (44 loc) · 1.82 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
import asyncio
from datetime import timedelta
from BinaryOptionsToolsV2.pocketoption import PocketOptionAsync
from BinaryOptionsToolsV2.validator import Validator
async def main(ssid: str):
# Initialize the API client
api = PocketOptionAsync(ssid)
await asyncio.sleep(5) # Wait for connection to establish
# Basic raw order example
try:
validator = Validator.contains('"status":"success"')
response = await api.create_raw_order('42["signals/subscribe"]', validator)
print(f"Basic raw order response: {response}")
except Exception as e:
print(f"Basic raw order failed: {e}")
# Raw order with timeout example
try:
validator = Validator.regex(r'{"type":"signal","data":.*}')
response = await api.create_raw_order_with_timeout(
'42["signals/load"]', validator, timeout=timedelta(seconds=5)
)
print(f"Raw order with timeout response: {response}")
except TimeoutError:
print("Order timed out after 5 seconds")
except Exception as e:
print(f"Order with timeout failed: {e}")
# Raw order with timeout and retry example
try:
# Create a validator that checks for both conditions
validator = Validator.all(
[
Validator.contains('"type":"trade"'),
Validator.contains('"status":"completed"'),
]
)
response = await api.create_raw_order_with_timeout_and_retry(
'42["trade/subscribe"]', validator, timeout=timedelta(seconds=10)
)
print(f"Raw order with retry response: {response}")
except Exception as e:
print(f"Order with retry failed: {e}")
if __name__ == "__main__":
ssid = input("Please enter your ssid: ")
asyncio.run(main(ssid))