(side, symbol, quantity, price, flags = {}, callback = false)
| 372 | * @return {undefined} |
| 373 | */ |
| 374 | const order = (side, symbol, quantity, price, flags = {}, callback = false) => { |
| 375 | let endpoint = flags.type === 'OCO' ? 'v3/orderList/oco' : 'v3/order'; |
| 376 | if (typeof flags.test && flags.test) endpoint += '/test'; |
| 377 | let opt = { |
| 378 | symbol: symbol, |
| 379 | side: side, |
| 380 | type: 'LIMIT' |
| 381 | }; |
| 382 | if (typeof flags.quoteOrderQty !== undefined && flags.quoteOrderQty > 0) |
| 383 | opt.quoteOrderQty = flags.quoteOrderQty |
| 384 | else |
| 385 | opt.quantity = quantity |
| 386 | if (typeof flags.type !== 'undefined') opt.type = flags.type; |
| 387 | if (opt.type.includes('LIMIT')) { |
| 388 | opt.price = price; |
| 389 | if (opt.type !== 'LIMIT_MAKER') { |
| 390 | opt.timeInForce = 'GTC'; |
| 391 | } |
| 392 | } |
| 393 | if (opt.type == 'MARKET' && typeof flags.quoteOrderQty !== 'undefined') { |
| 394 | opt.quoteOrderQty = flags.quoteOrderQty |
| 395 | delete opt.quantity; |
| 396 | } |
| 397 | if (opt.type === 'OCO') { |
| 398 | opt.price = price; |
| 399 | opt.stopLimitPrice = flags.stopLimitPrice; |
| 400 | opt.stopLimitTimeInForce = 'GTC'; |
| 401 | delete opt.type; |
| 402 | if (typeof flags.listClientOrderId !== 'undefined') opt.listClientOrderId = flags.listClientOrderId; |
| 403 | if (typeof flags.limitClientOrderId !== 'undefined') opt.limitClientOrderId = flags.limitClientOrderId; |
| 404 | if (typeof flags.stopClientOrderId !== 'undefined') opt.stopClientOrderId = flags.stopClientOrderId; |
| 405 | } |
| 406 | if (typeof flags.timeInForce !== 'undefined') opt.timeInForce = flags.timeInForce; |
| 407 | if (typeof flags.newOrderRespType !== 'undefined') opt.newOrderRespType = flags.newOrderRespType; |
| 408 | if (typeof flags.newClientOrderId !== 'undefined') { |
| 409 | opt.newClientOrderId = flags.newClientOrderId; |
| 410 | } else { |
| 411 | opt.newClientOrderId = SPOT_PREFIX + uuid22(); |
| 412 | } |
| 413 | |
| 414 | /* |
| 415 | * STOP_LOSS |
| 416 | * STOP_LOSS_LIMIT |
| 417 | * TAKE_PROFIT |
| 418 | * TAKE_PROFIT_LIMIT |
| 419 | * LIMIT_MAKER |
| 420 | */ |
| 421 | if (typeof flags.icebergQty !== 'undefined') opt.icebergQty = flags.icebergQty; |
| 422 | if (typeof flags.stopPrice !== 'undefined') { |
| 423 | opt.stopPrice = flags.stopPrice; |
| 424 | 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'); |
| 425 | } |
| 426 | signedRequest(getSpotUrl() + endpoint, opt, (error, response) => { |
| 427 | if (!response) { |
| 428 | if (callback) callback(error, response); |
| 429 | else Binance.options.log('Order() error:', error); |
| 430 | return; |
| 431 | } |
no test coverage detected