-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
examples: add oco_order example (#1497)
- Loading branch information
1 parent
d043588
commit f5c63e1
Showing
1 changed file
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import os | ||
import sys | ||
|
||
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
sys.path.append(root) | ||
|
||
from binance.client import Client | ||
|
||
|
||
api_key = "" # your api_key here | ||
secret = "" # your secret here | ||
client = Client(api_key, secret, testnet=True) | ||
|
||
|
||
# create oco order | ||
def create_oco_order(): | ||
order = client.create_oco_order( | ||
symbol="LTCUSDT", | ||
side="SELL", | ||
quantity=0.3, | ||
aboveType="LIMIT_MAKER", | ||
belowType="STOP_LOSS", | ||
abovePrice=200, | ||
belowStopPrice=120, | ||
) | ||
print(order) | ||
# { | ||
# "orderListId": 9365, | ||
# "contingencyType": "OCO", | ||
# "listStatusType": "EXEC_STARTED", | ||
# "listOrderStatus": "EXECUTING", | ||
# "listClientOrderId": "x-HNA2TXFJa9965a63237a3621d3f9df", | ||
# "transactionTime": 1733229295138, | ||
# "symbol": "LTCUSDT", | ||
# "orders": [ | ||
# { | ||
# "symbol": "LTCUSDT", | ||
# "orderId": 5836416, | ||
# "clientOrderId": "MxXFhDAC8h13wH8X3rXNKG", | ||
# }, | ||
# { | ||
# "symbol": "LTCUSDT", | ||
# "orderId": 5836417, | ||
# "clientOrderId": "a2UltweB2UB1XOdUTqOrzw", | ||
# }, | ||
# ], | ||
# "orderReports": [ | ||
# { | ||
# "symbol": "LTCUSDT", | ||
# "orderId": 5836416, | ||
# "orderListId": 9365, | ||
# "clientOrderId": "MxXFhDAC8h13wH8X3rXNKG", | ||
# "transactTime": 1733229295138, | ||
# "price": "0.00000000", | ||
# "origQty": "0.30000000", | ||
# "executedQty": "0.00000000", | ||
# "origQuoteOrderQty": "0.00000000", | ||
# "cummulativeQuoteQty": "0.00000000", | ||
# "status": "NEW", | ||
# "timeInForce": "GTC", | ||
# "type": "STOP_LOSS", | ||
# "side": "SELL", | ||
# "stopPrice": "120.00000000", | ||
# "workingTime": -1, | ||
# "selfTradePreventionMode": "EXPIRE_MAKER", | ||
# }, | ||
# { | ||
# "symbol": "LTCUSDT", | ||
# "orderId": 5836417, | ||
# "orderListId": 9365, | ||
# "clientOrderId": "a2UltweB2UB1XOdUTqOrzw", | ||
# "transactTime": 1733229295138, | ||
# "price": "200.00000000", | ||
# "origQty": "0.30000000", | ||
# "executedQty": "0.00000000", | ||
# "origQuoteOrderQty": "0.00000000", | ||
# "cummulativeQuoteQty": "0.00000000", | ||
# "status": "NEW", | ||
# "timeInForce": "GTC", | ||
# "type": "LIMIT_MAKER", | ||
# "side": "SELL", | ||
# "workingTime": 1733229295138, | ||
# "selfTradePreventionMode": "EXPIRE_MAKER", | ||
# }, | ||
# ], | ||
# } | ||
|
||
|
||
def main(): | ||
create_oco_order() | ||
|
||
main() |