Skip to content

Commit

Permalink
Add timeInForce for limit orders
Browse files Browse the repository at this point in the history
  • Loading branch information
balthazar committed Jan 21, 2018
1 parent 3c726b8 commit 6180a35
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,23 @@ console.log(await client.order({
|icebergQty|Number|false||Used with iceberg orders|
|recvWindow|Number|false|

Additional mandatory parameters based on `type`:

Type | Additional mandatory parameters
------------ | ------------
`LIMIT` | `timeInForce`, `quantity`, `price`
`MARKET` | `quantity`
`STOP_LOSS` | `quantity`, `stopPrice`
`STOP_LOSS_LIMIT` | `timeInForce`, `quantity`, `price`, `stopPrice`
`TAKE_PROFIT` | `quantity`, `stopPrice`
`TAKE_PROFIT_LIMIT` | `timeInForce`, `quantity`, `price`, `stopPrice`
`LIMIT_MAKER` | `quantity`, `price`

* `LIMIT_MAKER` are `LIMIT` orders that will be rejected if they would immediately match and trade as a taker.
* `STOP_LOSS` and `TAKE_PROFIT` will execute a `MARKET` order when the `stopPrice` is reached.
* Any `LIMIT` or `LIMIT_MAKER` type order can be made an iceberg order by sending an `icebergQty`.
* Any order with an `icebergQty` MUST have `timeInForce` set to `GTC`.

<details>
<summary>Output</summary>

Expand Down
9 changes: 7 additions & 2 deletions src/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,14 @@ const candles = payload =>
* Create a new order wrapper for market order simplicity
*/
const order = (pCall, payload = {}, url) => {
const newPayload =
['LIMIT', 'STOP_LOSS_LIMIT', 'TAKE_PROFIT_LIMIT'].includes(payload.type) || !payload.type
? { timeInForce: 'GTC', ...payload }
: payload

return (
checkParams('order', payload, ['symbol', 'side', 'quantity']) &&
pCall(url, { type: 'LIMIT', ...payload }, 'POST')
checkParams('order', newPayload, ['symbol', 'side', 'quantity']) &&
pCall(url, { type: 'LIMIT', ...newPayload }, 'POST')
)
}

Expand Down

0 comments on commit 6180a35

Please sign in to comment.