jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.58k stars 768 forks source link

OCO orders #397

Open berkinalex opened 4 years ago

berkinalex commented 4 years ago

No oco orders?

There is no information on its use on the main page, does anyone know how to use it?

Thanks

jaggedsoft commented 4 years ago

Not sure, I know this library supports OCO except for margin since binance hasn't added it yet, but the documentation is ugly. Generally you just have to pass a flag to the order function

https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md#new-oco-trade

jaggedsoft commented 4 years ago

https://github.com/jaggedsoft/node-binance-api/blob/master/node-binance-api.js#L242 Send {type: 'OCO'} as flags to any of the order functions

berkinalex commented 4 years ago

Thank you for your prompt response, but the following question arises.

Since OCO orders must have; Symbol, qty, profit and stop-limit, stop-limit

lamdoann commented 3 years ago

@berkinalex Have you solved the OCO with margin? I tried to place 2 orders with LIMIT_MAKER and STOP_LOSS_LIMIT but it cannot cancel the other.

Tom687 commented 3 years ago

@lamdoann I am having the same issue. How have you been able to place 2 orders with LIMIT_MAKER and STOP_LOSS_LIMIT ? Even it one doesn't cancel the other, it would still be better than nothing for me. Thank you very much

berkinalex commented 3 years ago

@berkinalex Have you solved the OCO with margin? I tried to place 2 orders with LIMIT_MAKER and STOP_LOSS_LIMIT but it cannot cancel the other.

Hello, I use: https://github.com/binance/binance-spot-api-docs/blob/master/rest-api.md#new-oco-trade

Tom687 commented 3 years ago

@berkinalex Hi, I am having the same issue. Are you actually using the OCO order with margin trading ? If so, are you using the endpoint /POST /api/v3/order/oco as shown in the docs, as it seems to be an endpoint only for spot trading ?

Could you please post us a code exemple of how you do these OCO margin orders and the endpoint used if different ? I can do them for spot trading but can't make it work for margin trading. Thank you very much

berkinalex commented 3 years ago

Sorry, in margin I have not used the oco commands. Even so I have changed all the orders to limit in my bot, the bot is constantly checking the price of my assets through websockets, and when it sees the closing price that corresponds to the purchase or sale it is launched, so the oco orders have become obsolete in my project.

Regards

patchworkfish commented 2 years ago

I was struggling with this for a while and pieced the following together in my node appplication: (Assume BTCGBP, current price = 40,000, sell at 41,000 or 39,000)

const Binance = require('node-binance-api');
const binance = new Binance().options({
  APIKEY: API_KEY,
  APISECRET: API_SECRET_KEY,
  useServerTime: true,
});

async function sell_oco () {
  const order_oco = util.promisify (binance.order);
  const order = await order_oco(
      side= 'SELL',
      symbol= 'BTCGBP', 
      quantity= '1.0000',                                            
      price= '41000`, 
      flags= {
          type: 'OCO',
          stopPrice: '39100',
          stopLimitPrice: '39000',
          // stopLimitTimeInForce: 'GTC', // I couldn't see this being set as an option, but is set in node-binance-api.js on line 385: opt.stopLimitTimeInForce = 'GTC';
      }
  );
  return order;
}

Hope it helps someone. It would be very helpful if the otherwise excellent main page documentation included how to place OCO order, as it can be done.