Skip to content

Commit d8b5f17

Browse files
authored
Merge pull request #77 from avsek477/add-visible-on-hit-hidden-orders
Add visible on hit hidden orders
2 parents 3151edd + d41b2cb commit d8b5f17

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#1.6.2
2+
- feature: visible on hit option supported for hidden orders
3+
14
# 1.6.0
25
- feature: Core settings model
36

lib/order.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const _isEmpty = require('lodash/isEmpty')
88
const _compact = require('lodash/compact')
99
const _flatten = require('lodash/flatten')
1010
const _includes = require('lodash/includes')
11+
const _isBoolean = require('lodash/isBoolean')
1112
const _isUndefined = require('lodash/isUndefined')
1213
const { prepareAmount, preparePrice } = require('bfx-api-node-util')
1314

@@ -101,6 +102,7 @@ class Order extends Model {
101102

102103
if (!this.flags) this.flags = 0
103104
if (!_isUndefined(data.hidden)) this.setHidden(data.hidden)
105+
if (!_isUndefined(data.visibleOnHit)) this.setVisibleOnHit(data.visibleOnHit)
104106
if (!_isUndefined(data.postonly)) this.setPostOnly(data.postonly)
105107
if (!_isUndefined(data.reduceonly)) this.setReduceOnly(data.reduceonly)
106108
if (!_isUndefined(data.oco)) {
@@ -159,6 +161,7 @@ class Order extends Model {
159161
/market/.test(type.toLowerCase()) ? 'MARKET' : preparePrice(price),
160162

161163
this.isHidden() && 'hidden',
164+
this.isVisibleOnHit() && 'visible-on-hit',
162165
this.isPostOnly() && 'post-only',
163166
this.isReduceOnly() && 'reduce-only',
164167
this.isPositionClose() && 'pos-close',
@@ -182,6 +185,13 @@ class Order extends Model {
182185
return !!(this.flags & Order.flags.HIDDEN)
183186
}
184187

188+
/**
189+
* @returns {boolean} visibleOnHit
190+
*/
191+
isVisibleOnHit () {
192+
return !!(this.isHidden() && this.meta && this.meta.make_visible)
193+
}
194+
185195
/**
186196
* @returns {boolean} postonly
187197
*/
@@ -236,9 +246,32 @@ class Order extends Model {
236246
* @returns {number} finalFlags
237247
*/
238248
setHidden (v) {
249+
if (!v && this.meta) {
250+
delete this.meta.make_visible
251+
}
239252
return this.modifyFlag(Order.flags.HIDDEN, v)
240253
}
241254

255+
/**
256+
* Update the meta object. The rest part of the hidden order will be visible
257+
* after first hit(partial execution).
258+
*
259+
* @param {boolean} v - visibleOnHit value
260+
* @returns {number} meta
261+
*/
262+
setVisibleOnHit (v) {
263+
if (!this.isHidden() || !_isBoolean(v)) {
264+
return
265+
}
266+
267+
this.meta = {
268+
...(this.meta || {}),
269+
make_visible: +v
270+
}
271+
272+
return this.meta
273+
}
274+
242275
/**
243276
* Update the post-only flag value. If post-only and the order would
244277
* immediately fill, the order is automatically cancelled.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bfx-api-node-models",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "Object models for usage with the Bitfinex node API",
55
"engines": {
66
"node": ">=8.3.0"

test/lib/models/order.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,23 @@ describe('Order model', () => {
169169
assert(o.isHidden())
170170
})
171171

172+
it('isVisibleOnHit, setVisibleOnHit: updates/reads if the hidden orders are visible on hit or not', () => {
173+
const o = new Order()
174+
assert(!o.isHidden())
175+
assert(!o.isVisibleOnHit())
176+
177+
o.setVisibleOnHit(true)
178+
assert(!o.isVisibleOnHit())
179+
180+
o.setHidden(true)
181+
o.setVisibleOnHit(true)
182+
assert(o.isVisibleOnHit())
183+
184+
o.setHidden(false)
185+
assert(!o.isHidden())
186+
assert(!o.isVisibleOnHit())
187+
})
188+
172189
it('isPostOnly, setPostOnly: updates/reads postonly flag', () => {
173190
const o = new Order()
174191
assert(!o.isPostOnly())

0 commit comments

Comments
 (0)