Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions examples/trailing-stop-loss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Binance = require('node-binance-api');
const binance = new Binance().options('options.json');

const quantity = 1;
const price = 2000;
const trailingDelta = 500;

await binance.sell("ETHUSDT", quantity, price, {
timeInForce: 'GTC',
trailingDelta: trailingDelta,
type: 'STOP_LOSS_LIMIT'
})
1 change: 1 addition & 0 deletions node-binance-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ let api = function Binance( options = {} ) {
* LIMIT_MAKER
*/
if ( typeof flags.icebergQty !== 'undefined' ) opt.icebergQty = flags.icebergQty;
if ( typeof flags.trailingDelta !== 'undefined' ) opt.trailingDelta = flags.trailingDelta;
if ( typeof flags.stopPrice !== 'undefined' ) {
opt.stopPrice = flags.stopPrice;
if ( opt.type === 'LIMIT' ) throw Error( 'stopPrice: Must set "type" to one of the following: STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, TAKE_PROFIT_LIMIT' );
Expand Down
13 changes: 12 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ describe('Buy order advanced', function () {
});

describe('Sell Stop loess', function () {
it('Attempt to create a stop loss order', function (done) {
it('Attempt to create a stop loss order with a trailing delta', function (done) {
let type = 'STOP_LOSS';
let quantity = 1;
let price = 0.069;
Expand All @@ -307,6 +307,17 @@ describe('Sell Stop loess', function () {
}).timeout(TIMEOUT);
});

describe('Sell with trailing Stop loss', function () {
it('Attempt to create a stop loss order', function (done) {
let type = 'STOP_LOSS_LIMIT';
let quantity = 1;
let price = 0.069;
let delta = 100;
assert(typeof (binance.sell('ETHBTC', quantity, price, { trailingDelta: delta, type: type })) === 'undefined', WARN_SHOULD_BE_UNDEFINED);
done();
}).timeout(TIMEOUT);
});

describe('Iceberg sell order', function () {
it('Attempt to create a sell order', function (done) {
let quantity = 1;
Expand Down