-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.py
183 lines (142 loc) · 5.35 KB
/
example.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import swagger_client
from BrokerAPIKeyAuthenticator import generate_signature
apiKey = "EH7tZeUqs5Bi"
apiSecret = "DiqZaC-koidsAIsan_XHlLb"
api = swagger_client.OperationsApi(swagger_client.ApiClient(swagger_client.Configuration()))
# GET ACCOUNT METRICS
acc_metrics_req_body = swagger_client.Body1()
acc_metrics_req_body.include_positions = True
message = api.api_client.sanitize_for_serialization(acc_metrics_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.get_account_metrics(**{"body": {"data": {"include_positions": True}}})
# [SINGLE ORDER]
# PLACE ORDER [Single Limit Order]
# order_code must be unique for every new order
body = {
"order_code": "0000000014",
"type": "LIMIT",
"instrument": "BTC/USD",
"quantity": 0.001,
"position_effect": "OPEN",
"side": "BUY",
"limit_price": 17551.50,
"tif": "GTC"
}
place_order_req_body = swagger_client.Body6(**body)
message = api.api_client.sanitize_for_serialization(place_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.open_account_order(**{"body": {"data": place_order_req_body}})
# CANCEL ORDER
cancel_order_req_body = swagger_client.Body2()
cancel_order_req_body.order_id = "0000000013"
message = api.api_client.sanitize_for_serialization(cancel_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.cancel_order(**{"body": {"data": cancel_order_req_body}})
# PLACE ORDER [Single Market Order]
# order_code must be unique for every new order
body = {
"order_code": "0000000035",
"type": "MARKET",
"instrument": "XRP/USD",
"quantity": 1,
"position_effect": "OPEN",
"side": "BUY",
"tif": "GTC"
}
place_order_req_body = swagger_client.Body6(**body)
message = api.api_client.sanitize_for_serialization(place_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.open_account_order(**{"body": {"data": place_order_req_body}})
# PLACE ORDER [Single Stop Order]
# order_code must be unique for every new order
body = {
"order_code": "0000000026",
"type": "STOP",
"instrument": "XRP/USD",
"quantity": 1,
"position_effect": "OPEN",
"side": "BUY",
"stop_price": 1.29500,
"tif": "GTC"
}
place_order_req_body = swagger_client.Body6(**body)
message = api.api_client.sanitize_for_serialization(place_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.open_account_order(**{"body": {"data": place_order_req_body}})
# PLACE ORDER [Single Market Order Closing Position]
# order_code must be unique for every new order
body = {
"order_code": "0000000017",
"type": "MARKET",
"instrument": "XRP/USD",
"quantity": 1,
"position_effect": "CLOSE",
"side": "BUY",
"position_code": "123",
"tif": "GTC"
}
place_order_req_body = swagger_client.Body6(**body)
message = api.api_client.sanitize_for_serialization(place_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.open_account_order(**{"body": {"data": place_order_req_body}})
# PLACE ORDER GROUP [OCO]
body = {
"orders": [
{
"orderCode": "ds_0000000061",
"type": "LIMIT",
"instrument": "XRP/USD",
"quantity": "20",
"positionEffect": "OPEN",
"side": "BUY",
"limitPrice": "1.32000",
"tif": "GTC"
},
{
"orderCode": "ds_0000000062",
"type": "STOP",
"instrument": "XRP/USD",
"quantity": "20",
"positionEffect": "OPEN",
"side": "BUY",
"stopPrice": "1.34000",
"tif": "GTC"
}
],
"contingencyType": "OCO"
}
place_order_req_body = swagger_client.Body7(**body)
message = api.api_client.sanitize_for_serialization(place_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.open_account_order(**{"body": {"data": place_order_req_body}})
# PLACE ORDER GROUP [IF-THEN]
# Multileg Order Request
body = {
"orders": [
{
"orderCode": "ds_0000000036",
"type": "LIMIT",
"instrument": "USD/CAD",
"quantity": 30,
"positionEffect": "OPEN",
"side": "BUY",
"limitPrice": 1.29500,
"tif": "GTC"
},
{
"orderCode": "ds_0000000037",
"type": "LIMIT",
"instrument": "USD/CAD",
"quantity": 0,
"positionEffect": "CLOSE",
"side": "SELL",
"limitPrice": 1.29500,
"tif": "GTC"
}
],
"contingencyType": "IF-THEN"
}
place_order_req_body = swagger_client.Body7(**body)
message = api.api_client.sanitize_for_serialization(place_order_req_body)
api.api_client.configuration.api_key = {"broAuth": "{},{}".format(apiKey, generate_signature(apiSecret, message))}
api.open_account_order(**{"body": {"data": place_order_req_body}})