Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gen preview iceberg test #61

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
4 changes: 4 additions & 0 deletions test/lib/iceberg/events/orders_order_fill.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ describe('iceberg:events:orders_order_fill', () => {

onOrderFill({
...instance,
state: {
...instance.state,
remainingAmount: 100
},
h: {
...instance.h,
emit: (eName, gid, orders, cancelDelay) => {
Expand Down
49 changes: 49 additions & 0 deletions test/lib/iceberg/meta/gen_preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* eslint-env mocha */
'use strict'

const assert = require('assert')
const genPreview = require('../../../../lib/iceberg/meta/gen_preview')

const getState = (argOverrides = {}) => {
return {
amount: 42,
sliceAmount: 10,
symbol: 'tBTCUSD',
price: 50000,
orderType: 'LIMIT',
...argOverrides
}
}

describe('iceberg:meta:init_state', () => {
it('generates the sliced order a/c to given input', () => {
const o = genPreview(getState())
const [slicedOrder] = o

assert.deepStrictEqual(o.length, 1, 'no order created')
assert.deepStrictEqual(slicedOrder.amount, 10, 'invalid sliced amount')
assert.deepStrictEqual(slicedOrder.symbol, 'tBTCUSD', 'invalid order symbol')
assert.deepStrictEqual(slicedOrder.price, 50000, 'invalid order price')
})

it('generates the correct sliced order for float amounts', () => {
const o = genPreview(getState({
excessAsHidden: true,
amount: 0.3,
sliceAmount: 0.1
}))
const [excessOrder, slicedOrder] = o

assert.deepStrictEqual(excessOrder.amount, 0.2, 'invalid excess sliced amount')
assert.deepStrictEqual(slicedOrder.amount, 0.1, 'invalid sliced amount')
})

it('generates an extra hidden order for excess amount', () => {
const o = genPreview(getState({ excessAsHidden: true }))
const [excessOrder] = o

assert.deepStrictEqual(o.length, 2, 'did not create an order for excess amount')
assert.ok(excessOrder.hidden, 'did not create a hidden order for excess amount')
assert.deepStrictEqual(excessOrder.amount, 32, 'invalid excess amount')
})
})