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/prod_buy.py
5932 views
1
import logging
2
import uuid
3
4
from api_calls.common_requests import make_api_request
5
6
orders_path = "tinkoff.public.invest.api.contract.v1.OrdersService/"
7
8
9
def prod_place_order(account_id, figi, quantity, deal_type):
10
if deal_type == 'buy':
11
direction = "ORDER_DIRECTION_BUY"
12
elif deal_type == 'sell':
13
direction = "ORDER_DIRECTION_SELL"
14
else:
15
return
16
17
data = {
18
"figi": figi,
19
"quantity": quantity,
20
"direction": direction,
21
"accountId": account_id,
22
"orderType": "ORDER_TYPE_MARKET",
23
"orderId": str(uuid.uuid4())
24
}
25
res = make_api_request(orders_path + 'PostOrder', data)
26
logging.debug("Prod place order: {}".format(res))
27
return res
28
29
30
def prod_get_order_state(account_id, order_id):
31
data = {
32
"accountId": account_id,
33
"orderId": order_id
34
}
35
res = make_api_request(orders_path + 'GetOrderState', data)
36
logging.debug("Sandbox order state: {}".format(res))
37
return res
38
39
40
def prod_cancel_order(account_id, order_id):
41
data = {
42
"accountId": account_id,
43
"orderId": order_id
44
}
45
res = make_api_request(orders_path + 'CancelOrder', data)
46
logging.debug("Sandbox cancel order: {}".format(res))
47
return res
48
49