LUCIT-Systems-and-Development / unicorn-binance-rest-api

A Python SDK by LUCIT to use the Binance REST API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, us, tr) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-rest-api.docs.lucit.tech
Other
60 stars 17 forks source link

Support for hidden private endpoints #53

Open casper-hansen opened 1 year ago

casper-hansen commented 1 year ago

Is your feature request related to a problem? Please describe.

The problem with Binance's Futures API is that your take profit, once hit, does not cancel your stop loss, and vice versa. If you can implement the private endpoint, you would eliminate a lot of overhead like listening to the user stream to monitor if you need to cancel a take profit or stop loss.

Describe the solution you'd like.

Upon inspection of the URL Binance uses on their exchange, I found the following. You can use their URL and parameters to open a position through the private endpoint.

URL: https://www.binance.com/bapi/futures/v1/private/future/strategy/place-order

Params:

{
    'strategyType': 'OTOCO',
    'subOrderList': [
        {
            "strategySubId": 1,
            "firstDrivenId": 0,
            "secondDrivenId": 0,
            "side": "BUY",
            "positionSide": "BOTH",
            "symbol": "BTCUSDT",
            "type": "MARKET",
            "quantity": 0.005,
            "securityType": "USDT_FUTURES",
            "reduceOnly": False
        },
        {
            "side": "SELL",
            "positionSide": "BOTH",
            "symbol": "BTCUSDT",
            "securityType": "USDT_FUTURES",
            "firstTrigger": "PLACE_ORDER",
            "firstDrivenOn": "PARTIALLY_FILLED_OR_FILLED",
            "timeInForce": "GTE_GTC",
            "reduceOnly": True,
            "quantity": 0.005,
            "strategySubId": 2,
            "firstDrivenId": 1,
            "secondDrivenId": 3,
            "secondDrivenOn": "PARTIALLY_FILLED_OR_FILLED",
            "secondTrigger": "CANCEL_ORDER",
            "stopPrice": "21248.4",
            "workingType": "MARK_PRICE",
            "type": "TAKE_PROFIT_MARKET",
            "priceProtect": True
        },
        {
            "side": "SELL",
            "positionSide": "BOTH",
            "symbol": "BTCUSDT",
            "securityType": "USDT_FUTURES",
            "firstTrigger": "PLACE_ORDER",
            "firstDrivenOn": "PARTIALLY_FILLED_OR_FILLED",
            "timeInForce": "GTE_GTC",
            "reduceOnly": True,
            "quantity": 0.005,
            "strategySubId": 3,
            "firstDrivenId": 1,
            "secondDrivenId": 2,
            "secondDrivenOn": "PARTIALLY_FILLED_OR_FILLED",
            "secondTrigger": "CANCEL_ORDER",
            "stopPrice": "20827.6",
            "workingType": "MARK_PRICE",
            "type": "STOP_MARKET",
            "priceProtect": True
        }
    ]
}

Describe alternatives you've considered

You can use LUCIT's Binance websocket repository to listen to the user stream, however, this is extremely inconvenient compared to just putting in this type of order on futures.

Additional context

Note that Binance Spot API already has this type of support in their API.

More on these types of orders: https://www.binance.com/en-ZA/support/faq/what-are-limit-tp-sl-orders-strategy-order-and-frequently-asked-questions-e1ee1738141c49718550fa9061be4bf3

oliver-zehentleitner commented 1 year ago

Will be done next week!

oliver-zehentleitner commented 1 year ago

Sorry, this came in between: https://github.com/LUCIT-Systems-and-Development/unicorn-binance-websocket-api/issues/319

Will continue here after finishing that...

oliver-zehentleitner commented 1 month ago

I would like to implement this. Is that also available for Spot? I will analyze the Binance frontend myself. Since there is no documentation here, we would have to reverse engineer the paremeters and create one ourselves in the wiki.