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 #376

Open JamesJohnson3rd opened 4 years ago

JamesJohnson3rd commented 4 years ago

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

kitt-th commented 4 years ago

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 commented 4 years ago

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)

jaggedsoft commented 4 years ago

Feature request: OCO for Margin

berkinalex commented 4 years ago

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]

kitt-th commented 4 years ago

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 :)

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.