Skip to content

Commit f5c63e1

Browse files
authored
examples: add oco_order example (sammchardy#1497)
1 parent d043588 commit f5c63e1

File tree

1 file changed

+92
-0
lines changed

1 file changed

+92
-0
lines changed

examples/create_oco_order.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import os
2+
import sys
3+
4+
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
5+
sys.path.append(root)
6+
7+
from binance.client import Client
8+
9+
10+
api_key = "" # your api_key here
11+
secret = "" # your secret here
12+
client = Client(api_key, secret, testnet=True)
13+
14+
15+
# create oco order
16+
def create_oco_order():
17+
order = client.create_oco_order(
18+
symbol="LTCUSDT",
19+
side="SELL",
20+
quantity=0.3,
21+
aboveType="LIMIT_MAKER",
22+
belowType="STOP_LOSS",
23+
abovePrice=200,
24+
belowStopPrice=120,
25+
)
26+
print(order)
27+
# {
28+
# "orderListId": 9365,
29+
# "contingencyType": "OCO",
30+
# "listStatusType": "EXEC_STARTED",
31+
# "listOrderStatus": "EXECUTING",
32+
# "listClientOrderId": "x-HNA2TXFJa9965a63237a3621d3f9df",
33+
# "transactionTime": 1733229295138,
34+
# "symbol": "LTCUSDT",
35+
# "orders": [
36+
# {
37+
# "symbol": "LTCUSDT",
38+
# "orderId": 5836416,
39+
# "clientOrderId": "MxXFhDAC8h13wH8X3rXNKG",
40+
# },
41+
# {
42+
# "symbol": "LTCUSDT",
43+
# "orderId": 5836417,
44+
# "clientOrderId": "a2UltweB2UB1XOdUTqOrzw",
45+
# },
46+
# ],
47+
# "orderReports": [
48+
# {
49+
# "symbol": "LTCUSDT",
50+
# "orderId": 5836416,
51+
# "orderListId": 9365,
52+
# "clientOrderId": "MxXFhDAC8h13wH8X3rXNKG",
53+
# "transactTime": 1733229295138,
54+
# "price": "0.00000000",
55+
# "origQty": "0.30000000",
56+
# "executedQty": "0.00000000",
57+
# "origQuoteOrderQty": "0.00000000",
58+
# "cummulativeQuoteQty": "0.00000000",
59+
# "status": "NEW",
60+
# "timeInForce": "GTC",
61+
# "type": "STOP_LOSS",
62+
# "side": "SELL",
63+
# "stopPrice": "120.00000000",
64+
# "workingTime": -1,
65+
# "selfTradePreventionMode": "EXPIRE_MAKER",
66+
# },
67+
# {
68+
# "symbol": "LTCUSDT",
69+
# "orderId": 5836417,
70+
# "orderListId": 9365,
71+
# "clientOrderId": "a2UltweB2UB1XOdUTqOrzw",
72+
# "transactTime": 1733229295138,
73+
# "price": "200.00000000",
74+
# "origQty": "0.30000000",
75+
# "executedQty": "0.00000000",
76+
# "origQuoteOrderQty": "0.00000000",
77+
# "cummulativeQuoteQty": "0.00000000",
78+
# "status": "NEW",
79+
# "timeInForce": "GTC",
80+
# "type": "LIMIT_MAKER",
81+
# "side": "SELL",
82+
# "workingTime": 1733229295138,
83+
# "selfTradePreventionMode": "EXPIRE_MAKER",
84+
# },
85+
# ],
86+
# }
87+
88+
89+
def main():
90+
create_oco_order()
91+
92+
main()

0 commit comments

Comments
 (0)