node-binance-api icon indicating copy to clipboard operation
node-binance-api copied to clipboard

OCO orders

Open JamesJohnson3rd opened this issue 5 years ago • 6 comments

There was a fork to add OCO orders to the API. binance.sell('BNBBTC', Qty, Price, {stopPrice: stop_price, type: 'OCO'}, (error, response) => {} When trying to sell, I get a Bad Request response with: Signature for this request is not valid. Any idea where I'm going wrong on this? @gunar

JamesJohnson3rd avatar Feb 03 '20 23:02 JamesJohnson3rd

Hello, same problem here - I even tried going direct to an order this way:

binance.order("sell", symbol, amountPerLevel, price, { type:'OCO', stopPrice:sl:sl_price, stopLimitPrice:sl_limit_price }, (error, response) => { }

and got 400 Bad Request {"code":-1022,"msg":"Signature for this request is not valid."}

Any help greatly appreciated (as above)!

kitt-th avatar Feb 05 '20 17:02 kitt-th

I couldn't get a successful testnet test of OCO but on the live net worked fine with this:

binance.order('SELL', 'BNBBTC', 1, 0.0029, { type:'OCO' , stopLimitPrice: 0.001, stopPrice: 0.001 }, (error, response) => {})

or this:

binance.sell('BNBBTC', 1, 0.0029, { type:'OCO' , stopLimitPrice: 0.001, stopPrice: 0.001 }, (error, response) => {})

so I'm happy this works. (my previous error was not having 'SELL' in caps I think)

kitt-th avatar Feb 06 '20 12:02 kitt-th

Feature request: OCO for Margin

jaggedsoft avatar Feb 08 '20 01:02 jaggedsoft

Esa información está incompleta binance.sell('BNBBTC', 1, 0.0029, { type:'OCO' , stopLimitPrice: 0.001, stopPrice: 0.001 }, (error, response) => {})

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

anyone know how to use it? thanks

[SOLUCIONADO GRACIAS]

berkinalex avatar Mar 18 '20 17:03 berkinalex

Esa información está incompleta binance.sell('BNBBTC', 1, 0.0029, { type:'OCO' , stopLimitPrice: 0.001, stopPrice: 0.001 }, (error, response) => {})

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

qty = 1 profit (take profit) = 0.0029 stop-limit = 0.001 stop-price = 0.001

Everything is there :)

kitt-th avatar Apr 23 '20 12:04 kitt-th

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.

patchworkfish avatar Oct 08 '21 13:10 patchworkfish