forked from Awethon/open-api-python-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.py
More file actions
60 lines (47 loc) · 1.77 KB
/
rest.py
File metadata and controls
60 lines (47 loc) · 1.77 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
from openapi_client import openapi
from datetime import datetime, timedelta
from pytz import timezone
token = 'YOUR TOKEN'
client = openapi.sandbox_api_client(token)
client.sandbox.sandbox_register_post()
client.sandbox.sandbox_clear_post()
client.sandbox.sandbox_currencies_balance_post(sandbox_set_currency_balance_request={"currency": "USD", "balance": 1000})
def set_balance():
balance_set = client.sandbox.sandbox_currencies_balance_post({"currency": "USD", "balance": 10000})
print("balance")
print(balance_set)
print()
def print_24hr_operations():
now = datetime.now(tz=timezone('Europe/Moscow'))
yesterday = now - timedelta(days=1)
ops = client.operations.operations_get(_from=yesterday.isoformat(), to=now.isoformat())
print("operations")
print(ops)
print()
def print_orders():
orders = client.orders.orders_get()
print("active orders")
print(orders)
print()
def make_order():
order_response = client.orders.orders_limit_order_post(figi='BBG009S39JX6',
limit_order_request={"lots": 1,
"operation": "Buy",
"price": 0.01})
print("make order")
print(order_response)
print()
return order_response
# won't work in sandbox - orders are being instantly executed
def cancel_order(order_id):
cancellation_result = client.orders.orders_cancel_post(order_id=order_id)
print("cancel order")
print(cancellation_result)
print()
set_balance()
print_24hr_operations()
print_orders()
order_response = make_order()
print_orders()
# cancel_order(order_response.payload.order_id)
# print_orders()