Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wiseplat
GitHub Repository: wiseplat/python-code
Path: blob/master/ invest-robot-contest_sirius-master/api_calls/sandbox_buy.py
5932 views
1
import logging
2
3
from api_calls.common_requests import make_api_request
4
5
sandbox_service_path = "tinkoff.public.invest.api.contract.v1.SandboxService/"
6
7
8
def sandbox_place_order(account_id, figi, quantity, deal_type):
9
if deal_type == 'buy':
10
direction = "ORDER_DIRECTION_BUY"
11
elif deal_type == 'sell':
12
direction = "ORDER_DIRECTION_SELL"
13
else:
14
return
15
16
data = {
17
"figi": figi,
18
"quantity": quantity,
19
"direction": direction,
20
"accountId": account_id,
21
"orderType": "ORDER_TYPE_MARKET",
22
"orderId": ""
23
}
24
res = make_api_request(sandbox_service_path + 'PostSandboxOrder', data)
25
logging.debug("Sandbox place order: {}".format(res))
26
return res
27
28
29
def sandbox_get_order_state(account_id, order_id):
30
data = {
31
"accountId": account_id,
32
"orderId": order_id
33
}
34
res = make_api_request(sandbox_service_path + 'GetSandboxOrderState', data)
35
logging.debug("Sandbox order state: {}".format(res))
36
return res
37
38
39
def sandbox_cancel_order(account_id, order_id):
40
data = {
41
"accountId": account_id,
42
"orderId": order_id
43
}
44
res = make_api_request(sandbox_service_path + 'CancelSandboxOrder', data)
45
logging.debug("Sandbox cancel order: {}".format(res))
46
return res
47
48