unicorn-binance-rest-api icon indicating copy to clipboard operation
unicorn-binance-rest-api copied to clipboard

Support for hidden private endpoints

Open casper-hansen opened this issue 2 years ago • 3 comments

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

casper-hansen avatar Jan 19 '23 22:01 casper-hansen

Will be done next week!

oliver-zehentleitner avatar Apr 01 '23 08:04 oliver-zehentleitner

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 avatar Apr 10 '23 02:04 oliver-zehentleitner

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.

oliver-zehentleitner avatar May 14 '24 11:05 oliver-zehentleitner