@alphapoint/apex-web 5.5.6 → 5.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/apex.integration.test.js +435 -0
- package/lib/apex.js +37 -1
- package/lib/apex.test.js +138 -0
- package/lib/components/2FA/PasskeyOption.js +126 -0
- package/lib/components/2FA/TwoFactorAuthComponent.js +24 -5
- package/lib/components/2FA/TwoFactorAuthComponent.test.js +94 -0
- package/lib/components/2FA/TwoFactorAuthContainer.js +139 -27
- package/lib/components/2FA/TwoFactorAuthContainer.test.js +627 -0
- package/lib/components/AccountsDropdown/AccountsDropdownComponent.css +6 -0
- package/lib/components/AccountsDropdown/AccountsDropdownComponent.js +6 -2
- package/lib/components/AccountsDropdown/AccountsDropdownComponent.test.js +43 -0
- package/lib/components/AccountsDropdown/AccountsDropdownContainer.js +3 -1
- package/lib/components/BalancesList/BalancesListContainer.js +4 -1
- package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.js +34 -6
- package/lib/components/ConfirmBlockTradeModal/ConfirmBlockTradeModalContainer.test.js +298 -0
- package/lib/components/ConfirmOrderModal/ConfirmOrderModalComponent.js +26 -4
- package/lib/components/ConfirmOrderModal/ConfirmOrderModalContainer.js +4 -1
- package/lib/components/DigitalAssets/digitalAssetsPriceLabel.test.js +238 -0
- package/lib/components/EnableTwoFactorAuth/Disable2FAForm.js +22 -7
- package/lib/components/EnableTwoFactorAuth/Disable2FAModal.js +15 -5
- package/lib/components/EnableTwoFactorAuth/Disable2FAModal.test.js +460 -0
- package/lib/components/EnableTwoFactorAuth/Disable2FAModalContainer.js +108 -16
- package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.js +7 -0
- package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +105 -0
- package/lib/components/EnableTwoFactorAuth/EnableTwoFactorAuthContainerFactory.js +15 -3
- package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.css +13 -0
- package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.js +246 -0
- package/lib/components/FusionAuth/UnlinkOAuthIdentityModal.test.js +521 -0
- package/lib/components/InstrumentPositions/InstrumentPositionsContainer.js +4 -1
- package/lib/components/Login/LoginFormComponent.js +1 -1
- package/lib/components/MarginBalances/MarginDepositWithdraw/MarginDepositModal/MarginDepositFormContainer.js +2 -1
- package/lib/components/NoAccountBanner/NoAccountBanner.css +9 -0
- package/lib/components/NoAccountBanner/NoAccountBanner.js +58 -0
- package/lib/components/NoAccountBanner/index.js +16 -0
- package/lib/components/NoAccountPlaceholder/NoAccountPlaceholder.css +31 -0
- package/lib/components/NoAccountPlaceholder/NoAccountPlaceholder.js +33 -0
- package/lib/components/NoAccountPlaceholder/index.js +9 -0
- package/lib/components/OrderEntryComponents/advancedForm/AdvancedOrderFormContainer.js +2 -0
- package/lib/components/OrderEntryComponents/common/FormAmountFields.js +5 -0
- package/lib/components/OrderEntryComponents/common/TwapScheduleFields.js +98 -0
- package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.js +86 -39
- package/lib/components/OrderEntryComponents/defaultForm/OrderEntryAnchoring.test.js +326 -0
- package/lib/components/OrderEntryComponents/defaultForm/OrderEntryContainer.js +10 -2
- package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/DepositsStatus/DepositsStatusComponent.test.js +99 -0
- package/lib/components/OrderHistoryComponents/InactiveOrders/InactiveOrdersComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/OpenOrders/OpenOrdersComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.js +1 -1
- package/lib/components/OrderHistoryComponents/WithdrawStatus/WithdrawStatusComponent.test.js +113 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.css +108 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCard.test.js +983 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/PasskeysSettingsCardComponent.js +500 -0
- package/lib/components/Settings/ProfileAndSecurity/PasskeysSettingsCard/index.js +9 -0
- package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.css +4 -0
- package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.js +29 -17
- package/lib/components/Settings/ProfileAndSecurity/ProfileSettingsCard/ProfileForm/SsoLinkRowComponent.test.js +135 -0
- package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.js +12 -4
- package/lib/components/Settings/ProfileAndSecurity/TwoFactorAuthSettingsCard/EnableTwoFactorAuth/EnableTwoFactorAuthComponent.test.js +268 -0
- package/lib/components/TwoFactorAuthForm/TwoFactorAuthForm.test.js +475 -0
- package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormComponent.js +26 -5
- package/lib/components/TwoFactorAuthForm/TwoFactorAuthFormContainer.js +50 -32
- package/lib/components/common/APAutoTabInput/APAutoTabInput.js +5 -2
- package/lib/components/common/APSelect/APSelect.js +3 -1
- package/lib/components/common/ErrorBoundary/ErrorBoundary.css +35 -0
- package/lib/components/common/ErrorBoundary/ErrorBoundary.js +87 -0
- package/lib/config/CONFIG.md +4 -0
- package/lib/config/configDefault.json +2 -1
- package/lib/constants/sendOrder/orderEntryFormConstants.js +23 -4
- package/lib/constants/sendOrder/timeInForceConstants.js +3 -1
- package/lib/constants/sendOrder/twapRejectReasons.js +26 -0
- package/lib/helpers/errorTextFormatter.js +13 -4
- package/lib/helpers/errorTextFormatter.test.js +26 -0
- package/lib/helpers/orderHistoryHelper.js +13 -1
- package/lib/helpers/orderHistoryHelper.test.js +58 -13
- package/lib/helpers/passkeyApi.js +228 -0
- package/lib/helpers/passkeyApi.test.js +171 -0
- package/lib/helpers/placeOrderHelper.js +76 -61
- package/lib/helpers/placeOrderHelper.test.js +169 -10
- package/lib/helpers/recalculateOrderHelper.js +4 -1
- package/lib/helpers/recalculateOrderHelper.test.js +88 -2
- package/lib/helpers/twapOrderHelper.js +265 -0
- package/lib/helpers/twapOrderHelper.test.js +467 -0
- package/lib/helpers/twoFactorAuthCancellation.js +38 -0
- package/lib/helpers/webauthnHelper.js +300 -0
- package/lib/helpers/webauthnHelper.test.js +199 -0
- package/lib/hocs/forAccount.js +33 -0
- package/lib/hocs/forAccount.test.js +50 -0
- package/lib/hocs/forVerified.js +16 -2
- package/lib/hocs/withAuthentication.js +3 -1
- package/lib/hocs/withOneSubmission.js +168 -0
- package/lib/index.js +3 -2
- package/lib/layouts/HeaderLayout/HeaderLayout.js +2 -1
- package/lib/layouts/WalletsLayout/WalletsLayoutContainer.js +3 -1
- package/lib/layouts/WalletsLayout/WalletsLayoutContainer.test.js +84 -0
- package/lib/redux/actions/apiActions.js +77 -9
- package/lib/redux/actions/apiActions.test.js +233 -0
- package/lib/redux/actions/authActions.js +514 -198
- package/lib/redux/actions/authActions.test.js +627 -47
- package/lib/redux/actions/depositActions.js +1 -1
- package/lib/redux/actions/depositActions.test.js +100 -30
- package/lib/redux/actions/fusionAuthActions.test.js +265 -84
- package/lib/redux/actions/interestAccountActions.js +12 -3
- package/lib/redux/actions/interestAccountActions.test.js +73 -0
- package/lib/redux/actions/modalActions.js +1 -0
- package/lib/redux/actions/orderEntryActions.blockTrade.test.js +306 -0
- package/lib/redux/actions/orderEntryActions.js +74 -22
- package/lib/redux/actions/orderEntryActions.test.js +63 -11
- package/lib/redux/actions/orderHistoryActions.js +20 -8
- package/lib/redux/actions/orderHistoryActions.test.js +63 -0
- package/lib/redux/actions/userActions.js +379 -179
- package/lib/redux/actions/userActions.test.js +925 -234
- package/lib/redux/actions/withdrawActions.js +62 -29
- package/lib/redux/actions/withdrawActions.test.js +246 -73
- package/lib/redux/actions/withdrawActions.travelRule.test.js +17 -3
- package/lib/redux/margin/actions/marginActions.js +6 -3
- package/lib/redux/margin/actions/marginActions.test.js +166 -0
- package/lib/redux/middlewares/authMiddleware.js +5 -0
- package/lib/redux/middlewares/authMiddleware.test.js +88 -29
- package/lib/redux/reducers/authReducer.js +1 -0
- package/lib/redux/reducers/authReducer.test.js +38 -0
- package/lib/redux/reducers/userReducer.js +10 -0
- package/lib/redux/reducers/userReducer.test.js +29 -0
- package/lib/redux/selectors/orderEntrySelector.js +19 -8
- package/lib/redux/selectors/orderEntrySelector.test.js +209 -0
- package/lib/redux/selectors/orderTotalSelector.test.js +40 -1
- package/lib/redux/selectors/recentActivitySelector.js +8 -2
- package/lib/redux/selectors/recentActivitySelector.v2.test.js +33 -0
- package/lib/redux/selectors/userSelectors.js +6 -1
- package/lib/redux/selectors/userSelectors.test.js +28 -0
- package/lib/services/fms/fms.js +2 -0
- package/lib/services/fms/fms.test.js +35 -0
- package/package.json +4 -4
|
@@ -100,6 +100,71 @@ describe('placeOrderHelper', function () {
|
|
|
100
100
|
type: 'success'
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
|
+
it('should say a TWAP has fully executed when its last slice is done', function () {
|
|
104
|
+
var order = {
|
|
105
|
+
OrderState: 'FullyExecuted',
|
|
106
|
+
OrderType: 'TWAP'
|
|
107
|
+
};
|
|
108
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)(order)).toEqual({
|
|
109
|
+
text: 'Your TWAP order has fully executed',
|
|
110
|
+
type: 'success'
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
it('should stay silent when a TWAP slice fills (a Working update with a Trade change reason)', function () {
|
|
114
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)({
|
|
115
|
+
OrderType: 'TWAP',
|
|
116
|
+
OrderState: 'Working',
|
|
117
|
+
CancelReason: 'Trade'
|
|
118
|
+
})).toEqual({});
|
|
119
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)({
|
|
120
|
+
OrderType: 'TWAP',
|
|
121
|
+
OrderState: 'Working',
|
|
122
|
+
ChangeReason: 'Trade'
|
|
123
|
+
})).toEqual({});
|
|
124
|
+
});
|
|
125
|
+
it('should still announce a TWAP being accepted', function () {
|
|
126
|
+
var order = {
|
|
127
|
+
OrderType: 'TWAP',
|
|
128
|
+
OrderState: 'Working',
|
|
129
|
+
CancelReason: 'NewInputAccepted'
|
|
130
|
+
};
|
|
131
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)(order)).toEqual({
|
|
132
|
+
text: 'Your order has been successfully added',
|
|
133
|
+
type: 'success'
|
|
134
|
+
});
|
|
135
|
+
});
|
|
136
|
+
it('should keep announcing partial fills of other order types', function () {
|
|
137
|
+
var order = {
|
|
138
|
+
OrderType: 'Limit',
|
|
139
|
+
OrderState: 'Working',
|
|
140
|
+
CancelReason: 'Trade'
|
|
141
|
+
};
|
|
142
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)(order)).toEqual({
|
|
143
|
+
text: 'Your order has been successfully added',
|
|
144
|
+
type: 'success'
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
it('should translate a TWAP reject the engine reports after SendOrder returned', function () {
|
|
148
|
+
var order = {
|
|
149
|
+
OrderType: 'TWAP',
|
|
150
|
+
OrderState: 'Rejected',
|
|
151
|
+
RejectReason: 'Twap_Slice_Below_Minimum'
|
|
152
|
+
};
|
|
153
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)(order)).toEqual({
|
|
154
|
+
text: "The TWAP slice is below the instrument's minimum quantity. Increase the amount or use fewer slices",
|
|
155
|
+
type: 'warning'
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
it('should keep the generic text for a fully executed order of another type', function () {
|
|
159
|
+
var order = {
|
|
160
|
+
OrderState: 'FullyExecuted',
|
|
161
|
+
OrderType: 'Limit'
|
|
162
|
+
};
|
|
163
|
+
expect((0, _placeOrderHelper.getOrderEventSnackbar)(order)).toEqual({
|
|
164
|
+
text: 'Your order has been successfully added',
|
|
165
|
+
type: 'success'
|
|
166
|
+
});
|
|
167
|
+
});
|
|
103
168
|
it('should return warning snackbar if `OrderState` is `Rejected` with `RejectReason`', function () {
|
|
104
169
|
var order = {
|
|
105
170
|
OrderState: 'Rejected',
|
|
@@ -125,6 +190,18 @@ describe('placeOrderHelper', function () {
|
|
|
125
190
|
});
|
|
126
191
|
});
|
|
127
192
|
});
|
|
193
|
+
describe('method getPegPriceByType', function () {
|
|
194
|
+
var level1ForInstrument = {
|
|
195
|
+
BestOffer: 11,
|
|
196
|
+
BestBid: 9,
|
|
197
|
+
LastTradedPx: 10
|
|
198
|
+
};
|
|
199
|
+
it.each([[_pegPriceTypeConstants.pegPriceType.ask, 11], [_pegPriceTypeConstants.pegPriceType.bid, 9], [_pegPriceTypeConstants.pegPriceType.last, 10]])('should return the price for peg price type %s from the given level1', function (type, price) {
|
|
200
|
+
expect((0, _placeOrderHelper.getPegPriceByType)(level1ForInstrument, {
|
|
201
|
+
pegPriceType: type
|
|
202
|
+
})).toEqual(price);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
128
205
|
describe('method getFormValuesForSubmittingOrder', function () {
|
|
129
206
|
it('should log error if not supported orderFormType is passed', function () {
|
|
130
207
|
var notSupportedFormType = 'not_supported';
|
|
@@ -196,7 +273,9 @@ describe('placeOrderHelper', function () {
|
|
|
196
273
|
expect(_typeof(form.PegPriceType)).not.toBe('undefined');
|
|
197
274
|
});
|
|
198
275
|
});
|
|
199
|
-
|
|
276
|
+
|
|
277
|
+
// The Order Entry panel lists every order type too, so both forms must build the same payloads.
|
|
278
|
+
describe.each([_orderFormTypes.orderFormTypes["default"], _orderFormTypes.orderFormTypes.advanced])('%s form, every order type', function (orderFormType) {
|
|
200
279
|
beforeEach(function () {
|
|
201
280
|
options.form = {
|
|
202
281
|
side: _orderEntryFormConstants.buyValue,
|
|
@@ -215,7 +294,7 @@ describe('placeOrderHelper', function () {
|
|
|
215
294
|
});
|
|
216
295
|
it('should return correct form for `Market` order', function () {
|
|
217
296
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.market.displayName;
|
|
218
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
297
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
219
298
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
220
299
|
Side: Number(advancedOrderEntryForm.side),
|
|
221
300
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -230,7 +309,7 @@ describe('placeOrderHelper', function () {
|
|
|
230
309
|
});
|
|
231
310
|
it('should return correct form for `Limit` order', function () {
|
|
232
311
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.limit.displayName;
|
|
233
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
312
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
234
313
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
235
314
|
Side: Number(advancedOrderEntryForm.side),
|
|
236
315
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -247,7 +326,7 @@ describe('placeOrderHelper', function () {
|
|
|
247
326
|
});
|
|
248
327
|
it('should return correct form for `StopMarket` order', function () {
|
|
249
328
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.stopMarket.displayName;
|
|
250
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
329
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
251
330
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
252
331
|
Side: Number(advancedOrderEntryForm.side),
|
|
253
332
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -264,7 +343,7 @@ describe('placeOrderHelper', function () {
|
|
|
264
343
|
});
|
|
265
344
|
it('should return correct form for `StopLimit` order', function () {
|
|
266
345
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.stopLimit.displayName;
|
|
267
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
346
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
268
347
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
269
348
|
Side: Number(advancedOrderEntryForm.side),
|
|
270
349
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -282,7 +361,7 @@ describe('placeOrderHelper', function () {
|
|
|
282
361
|
});
|
|
283
362
|
it('should return correct form for `Fill or Kill` order', function () {
|
|
284
363
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.fillOrKill.displayName;
|
|
285
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
364
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
286
365
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
287
366
|
Side: Number(advancedOrderEntryForm.side),
|
|
288
367
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -301,7 +380,7 @@ describe('placeOrderHelper', function () {
|
|
|
301
380
|
});
|
|
302
381
|
it('should return correct form for `Immediate or Cancel` order', function () {
|
|
303
382
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.immediateOrCancel.displayName;
|
|
304
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
383
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
305
384
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
306
385
|
Side: Number(advancedOrderEntryForm.side),
|
|
307
386
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -320,7 +399,7 @@ describe('placeOrderHelper', function () {
|
|
|
320
399
|
});
|
|
321
400
|
it('should return correct form for `Reserve Order', function () {
|
|
322
401
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.reserveOrder.displayName;
|
|
323
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
402
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
324
403
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
325
404
|
Side: Number(advancedOrderEntryForm.side),
|
|
326
405
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -342,9 +421,89 @@ describe('placeOrderHelper', function () {
|
|
|
342
421
|
expect(_typeof(form.TimeInForce)).not.toBe('undefined');
|
|
343
422
|
expect(_typeof(form.PegPriceType)).not.toBe('undefined');
|
|
344
423
|
});
|
|
424
|
+
describe('TWAP', function () {
|
|
425
|
+
// The matching engine implements a TWAP as order type 13: a GTD order whose ExpireTime ends the
|
|
426
|
+
// schedule and whose DisplayQuantity is the slice released at each interval.
|
|
427
|
+
var EXPIRE_NOW = Date.UTC(2026, 10, 6, 12, 0, 0);
|
|
428
|
+
var expectedExpireTicks = function expectedExpireTicks(minutes) {
|
|
429
|
+
return (EXPIRE_NOW + minutes * 60000) * 10000 + 621355968000000000;
|
|
430
|
+
};
|
|
431
|
+
beforeEach(function () {
|
|
432
|
+
options.now = EXPIRE_NOW;
|
|
433
|
+
options.priceDecimalPlaces = 2;
|
|
434
|
+
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.twap.displayName;
|
|
435
|
+
advancedOrderEntryForm.durationMinutes = '30';
|
|
436
|
+
advancedOrderEntryForm.slices = '3';
|
|
437
|
+
advancedOrderEntryForm.value = '4995';
|
|
438
|
+
advancedOrderEntryForm.postOnly = true;
|
|
439
|
+
});
|
|
440
|
+
it('sends a market-form sell by Quantity with the slice as DisplayQuantity', function () {
|
|
441
|
+
advancedOrderEntryForm.side = '1';
|
|
442
|
+
advancedOrderEntryForm.limitPrice = '';
|
|
443
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
444
|
+
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
445
|
+
Side: 1,
|
|
446
|
+
Quantity: '99.9',
|
|
447
|
+
OrderType: 13,
|
|
448
|
+
TimeInForce: 6,
|
|
449
|
+
ExpireTime: expectedExpireTicks(30),
|
|
450
|
+
DisplayQuantity: 33.3,
|
|
451
|
+
UseDisplayQuantity: true,
|
|
452
|
+
PegPriceType: _pegPriceTypeConstants.pegPriceType.bid
|
|
453
|
+
}));
|
|
454
|
+
expect(form.Value).toBeUndefined();
|
|
455
|
+
expect(form.LimitPrice).toBeUndefined();
|
|
456
|
+
expect(form.PostOnly).toBeUndefined();
|
|
457
|
+
});
|
|
458
|
+
it('sends a market-form buy by Value with the slice value as DisplayQuantity', function () {
|
|
459
|
+
advancedOrderEntryForm.side = _orderEntryFormConstants.buyValue;
|
|
460
|
+
advancedOrderEntryForm.limitPrice = '';
|
|
461
|
+
advancedOrderEntryForm.anchoredField = 'quantity';
|
|
462
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
463
|
+
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
464
|
+
Side: 0,
|
|
465
|
+
Value: 4995,
|
|
466
|
+
OrderType: 13,
|
|
467
|
+
TimeInForce: 6,
|
|
468
|
+
ExpireTime: expectedExpireTicks(30),
|
|
469
|
+
DisplayQuantity: 1665,
|
|
470
|
+
UseDisplayQuantity: false,
|
|
471
|
+
PegPriceType: _pegPriceTypeConstants.pegPriceType.ask
|
|
472
|
+
}));
|
|
473
|
+
expect(form.Quantity).toBeUndefined();
|
|
474
|
+
expect(form.LimitPrice).toBeUndefined();
|
|
475
|
+
});
|
|
476
|
+
it('sends a limit-form buy by Quantity at the limit price, dropping the synced Value', function () {
|
|
477
|
+
advancedOrderEntryForm.side = _orderEntryFormConstants.buyValue;
|
|
478
|
+
advancedOrderEntryForm.limitPrice = '0.11';
|
|
479
|
+
advancedOrderEntryForm.anchoredField = 'value';
|
|
480
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
481
|
+
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
482
|
+
Side: 0,
|
|
483
|
+
Quantity: '99.9',
|
|
484
|
+
LimitPrice: '0.11',
|
|
485
|
+
OrderType: 13,
|
|
486
|
+
TimeInForce: 6,
|
|
487
|
+
ExpireTime: expectedExpireTicks(30),
|
|
488
|
+
DisplayQuantity: 33.3,
|
|
489
|
+
UseDisplayQuantity: true,
|
|
490
|
+
PegPriceType: _pegPriceTypeConstants.pegPriceType.ask
|
|
491
|
+
}));
|
|
492
|
+
expect(form.Value).toBeUndefined();
|
|
493
|
+
});
|
|
494
|
+
it('rounds the slice up to the quantity increment so the engine never needs an extra slice', function () {
|
|
495
|
+
advancedOrderEntryForm.side = '1';
|
|
496
|
+
advancedOrderEntryForm.limitPrice = '';
|
|
497
|
+
advancedOrderEntryForm.quantity = '1.0';
|
|
498
|
+
advancedOrderEntryForm.slices = '7';
|
|
499
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
500
|
+
expect(form.DisplayQuantity).toBe(0.2);
|
|
501
|
+
expect(Math.ceil(1 / form.DisplayQuantity)).toBeLessThanOrEqual(7);
|
|
502
|
+
});
|
|
503
|
+
});
|
|
345
504
|
it('should return correct form for `Trailing Stop Market', function () {
|
|
346
505
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.trailingStopMarket.displayName;
|
|
347
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
506
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
348
507
|
expect(_typeof(form.TrailingAmount)).not.toBe('undefined');
|
|
349
508
|
expect(form.PegPriceType).toEqual(advancedOrderEntryForm.pegPriceType);
|
|
350
509
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
@@ -363,7 +522,7 @@ describe('placeOrderHelper', function () {
|
|
|
363
522
|
});
|
|
364
523
|
it('should return correct form for `Trailing Stop Limit', function () {
|
|
365
524
|
advancedOrderEntryForm.orderType = _orderEntryFormConstants.orderTypes.trailingStopLimit.displayName;
|
|
366
|
-
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(
|
|
525
|
+
var form = (0, _placeOrderHelper.getFormValuesForSubmittingOrder)(orderFormType, options);
|
|
367
526
|
expect(form).toEqual(_objectSpread(_objectSpread({}, getFormBaseValues()), {}, {
|
|
368
527
|
Side: Number(advancedOrderEntryForm.side),
|
|
369
528
|
Quantity: advancedOrderEntryForm.quantity,
|
|
@@ -9,6 +9,7 @@ var _includes = _interopRequireDefault(require("lodash/includes"));
|
|
|
9
9
|
var _apex = _interopRequireDefault(require("../apex"));
|
|
10
10
|
var _orderHelper = require("./orderHelper");
|
|
11
11
|
var _placeOrderHelper = require("./placeOrderHelper");
|
|
12
|
+
var _twapOrderHelper = require("./twapOrderHelper");
|
|
12
13
|
var _orderEntryFormConstants = require("../constants/sendOrder/orderEntryFormConstants");
|
|
13
14
|
var _orderEntrySelector = require("../redux/selectors/orderEntrySelector");
|
|
14
15
|
var _instrumentPositionSelectors = require("../redux/selectors/instrumentPositionSelectors");
|
|
@@ -52,7 +53,9 @@ var recalculateOrderFormValues = exports.recalculateOrderFormValues = /*#__PURE_
|
|
|
52
53
|
form: form
|
|
53
54
|
});
|
|
54
55
|
if (totalAmount.toString() === 'NaN') totalAmount = 0;
|
|
55
|
-
|
|
56
|
+
|
|
57
|
+
// GetOrderFee has no TWAP type: a TWAP is charged like the market or limit order its slices are.
|
|
58
|
+
payload = getBaseOptionsForGetOrderFeeRequest(store, (0, _twapOrderHelper.getFeeFormValues)(form), totalAmount, selectedInstrument);
|
|
56
59
|
_context.n = 1;
|
|
57
60
|
return _getOrderFeeForDefaultForm(payload, form, store);
|
|
58
61
|
case 1:
|
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
3
4
|
var _recalculateOrderHelper = require("./recalculateOrderHelper");
|
|
4
5
|
var _placeOrderHelper = require("./placeOrderHelper");
|
|
5
6
|
var _reduxMockStore = _interopRequireDefault(require("redux-mock-store"));
|
|
6
7
|
var _apex = _interopRequireDefault(require("../apex"));
|
|
7
8
|
var _selectors = require("../redux/margin/selectors");
|
|
8
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
11
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
13
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
14
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
15
|
+
function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i["return"]) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
|
|
16
|
+
function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
|
|
17
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
|
|
18
|
+
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; } // eslint-disable-next-line import/named
|
|
11
19
|
jest.mock('./placeOrderHelper', function () {
|
|
12
20
|
var selectedOrderType = 1;
|
|
13
21
|
return {
|
|
@@ -270,6 +278,84 @@ describe('recalculateOrderHelper', function () {
|
|
|
270
278
|
expect(_apex["default"].connection.GetOrderFee).toHaveBeenCalled();
|
|
271
279
|
});
|
|
272
280
|
});
|
|
281
|
+
describe('recalculateOrderFormValues for a TWAP', function () {
|
|
282
|
+
var state = {
|
|
283
|
+
apexCore: {
|
|
284
|
+
product: {
|
|
285
|
+
products: []
|
|
286
|
+
},
|
|
287
|
+
instrument: {
|
|
288
|
+
instruments: [{
|
|
289
|
+
0: {
|
|
290
|
+
InstrumentId: 1
|
|
291
|
+
}
|
|
292
|
+
}]
|
|
293
|
+
},
|
|
294
|
+
level1: {},
|
|
295
|
+
level2: {
|
|
296
|
+
buy: [{
|
|
297
|
+
Price: 100,
|
|
298
|
+
Quantity: 10
|
|
299
|
+
}],
|
|
300
|
+
sell: [{
|
|
301
|
+
Price: 101,
|
|
302
|
+
Quantity: 10
|
|
303
|
+
}]
|
|
304
|
+
}
|
|
305
|
+
},
|
|
306
|
+
user: {
|
|
307
|
+
userInfo: {
|
|
308
|
+
OMSId: 1,
|
|
309
|
+
AccountId: 1
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
form: {}
|
|
313
|
+
};
|
|
314
|
+
var twapForm = {
|
|
315
|
+
orderType: 'TWAP',
|
|
316
|
+
quantity: '1',
|
|
317
|
+
slices: '4',
|
|
318
|
+
durationMinutes: '10',
|
|
319
|
+
side: '1'
|
|
320
|
+
};
|
|
321
|
+
it('requests the fee of a market order for a market-form TWAP', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
|
|
322
|
+
return _regenerator().w(function (_context) {
|
|
323
|
+
while (1) switch (_context.n) {
|
|
324
|
+
case 0:
|
|
325
|
+
_context.n = 1;
|
|
326
|
+
return (0, _recalculateOrderHelper.recalculateOrderFormValues)(mockStore(state), {
|
|
327
|
+
form: twapForm,
|
|
328
|
+
formName: 'orderEntry',
|
|
329
|
+
orders: []
|
|
330
|
+
});
|
|
331
|
+
case 1:
|
|
332
|
+
expect(_placeOrderHelper.getOrderTypeByName).toHaveBeenCalledWith('Market Order');
|
|
333
|
+
expect(_apex["default"].connection.GetOrderFee).toHaveBeenCalledTimes(1);
|
|
334
|
+
case 2:
|
|
335
|
+
return _context.a(2);
|
|
336
|
+
}
|
|
337
|
+
}, _callee);
|
|
338
|
+
})));
|
|
339
|
+
it('requests the fee of a limit order for a limit-form TWAP', /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
|
|
340
|
+
return _regenerator().w(function (_context2) {
|
|
341
|
+
while (1) switch (_context2.n) {
|
|
342
|
+
case 0:
|
|
343
|
+
_context2.n = 1;
|
|
344
|
+
return (0, _recalculateOrderHelper.recalculateOrderFormValues)(mockStore(state), {
|
|
345
|
+
form: _objectSpread(_objectSpread({}, twapForm), {}, {
|
|
346
|
+
limitPrice: '100'
|
|
347
|
+
}),
|
|
348
|
+
formName: 'orderEntry',
|
|
349
|
+
orders: []
|
|
350
|
+
});
|
|
351
|
+
case 1:
|
|
352
|
+
expect(_placeOrderHelper.getOrderTypeByName).toHaveBeenCalledWith('Limit Order');
|
|
353
|
+
case 2:
|
|
354
|
+
return _context2.a(2);
|
|
355
|
+
}
|
|
356
|
+
}, _callee2);
|
|
357
|
+
})));
|
|
358
|
+
});
|
|
273
359
|
describe('getPriceForGetOrderFeeRequest', function () {
|
|
274
360
|
it('should return correct price for sell `Market Order`', function () {
|
|
275
361
|
(0, _placeOrderHelper.setOrderType)(1);
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseSlices = exports.isTwapSliceBelowMinimum = exports.isTwapOrderType = exports.isTwapByValue = exports.hasLimitPrice = exports.getTwapSlicesError = exports.getTwapSliceSize = exports.getTwapSliceCount = exports.getTwapSchedule = exports.getTwapOrderFields = exports.getTwapOmittedFields = exports.getTwapIntervalSeconds = exports.getTwapExpireTimeTicks = exports.getTwapEndTime = exports.getTwapDurationError = exports.getFeeFormValues = exports.formatTwapInterval = exports.TWAP_MAX_SLICES = exports.TWAP_MAX_DURATION_MINUTES = void 0;
|
|
7
|
+
var _bignumber = _interopRequireDefault(require("bignumber.js"));
|
|
8
|
+
var _orderEntryFormConstants = require("../constants/sendOrder/orderEntryFormConstants");
|
|
9
|
+
var _timeInForceConstants = require("../constants/sendOrder/timeInForceConstants");
|
|
10
|
+
var _numberFormatter = require("./numberFormatter");
|
|
11
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
12
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
13
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
14
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
15
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
18
|
+
/**
|
|
19
|
+
* TWAP (time-weighted average price) orders, as the matching engine implements them (apex
|
|
20
|
+
* docs/features/twap-orders.md): one order of type TWAP (13), sent through SendOrder as a GTD
|
|
21
|
+
* order whose ExpireTime ends the schedule and whose DisplayQuantity is the slice the engine
|
|
22
|
+
* releases at equal intervals. Two forms:
|
|
23
|
+
*
|
|
24
|
+
* - Market form (no LimitPrice): each slice takes the market. A sell is sized by Quantity and a
|
|
25
|
+
* buy by Value (quote currency), so DisplayQuantity is then a slice value.
|
|
26
|
+
* - Limit form (LimitPrice): each slice rests at the price if it cannot trade; sized by Quantity.
|
|
27
|
+
*
|
|
28
|
+
* The form asks for a duration in minutes and a number of slices; this module derives the wire
|
|
29
|
+
* fields from them and the estimates the form and the confirm modal show.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
/** The engine and gateway cap a TWAP at this many slices. */
|
|
33
|
+
var TWAP_MAX_SLICES = exports.TWAP_MAX_SLICES = 100;
|
|
34
|
+
|
|
35
|
+
/** Longest schedule the form accepts, in minutes (7 days). The engine itself has no cap. */
|
|
36
|
+
var TWAP_MAX_DURATION_MINUTES = exports.TWAP_MAX_DURATION_MINUTES = 7 * 24 * 60;
|
|
37
|
+
|
|
38
|
+
/** .NET ticks (100ns) at 1970-01-01T00:00:00Z, the same constant dateHelper.ticksToDateString uses. */
|
|
39
|
+
var TICKS_AT_UNIX_EPOCH = new _bignumber["default"]('621355968000000000');
|
|
40
|
+
var TICKS_PER_MILLISECOND = 10000;
|
|
41
|
+
var isTwapOrderType = exports.isTwapOrderType = function isTwapOrderType(orderType) {
|
|
42
|
+
return orderType === _orderEntryFormConstants.orderTypes.twap.displayName;
|
|
43
|
+
};
|
|
44
|
+
var hasLimitPrice = exports.hasLimitPrice = function hasLimitPrice(_ref) {
|
|
45
|
+
var limitPrice = _ref.limitPrice;
|
|
46
|
+
if (limitPrice === undefined || limitPrice === null || limitPrice === '') return false;
|
|
47
|
+
var price = new _bignumber["default"](limitPrice);
|
|
48
|
+
return price.isFinite() && price.gt(0);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/** A market-form TWAP buy: the engine sizes it by Value and the slice is a value, not a quantity. */
|
|
52
|
+
var isTwapByValue = exports.isTwapByValue = function isTwapByValue(formValues) {
|
|
53
|
+
return isTwapOrderType(formValues.orderType) && formValues.side === _orderEntryFormConstants.buyValue && !hasLimitPrice(formValues);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/** When a schedule of `durationMinutes` starting at `now` ends, as a Date; null without a usable duration. */
|
|
57
|
+
var getTwapEndTime = exports.getTwapEndTime = function getTwapEndTime(durationMinutes) {
|
|
58
|
+
var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
|
|
59
|
+
var minutes = Number(durationMinutes);
|
|
60
|
+
if (!(minutes > 0)) return null;
|
|
61
|
+
return new Date(now + minutes * 60000);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* ExpireTime for a schedule of `durationMinutes` starting now, as .NET ticks. The engine computes
|
|
66
|
+
* the schedule from the order's receive time, so the schedule is a little shorter than the
|
|
67
|
+
* duration by the time the order reaches the engine.
|
|
68
|
+
*/
|
|
69
|
+
var getTwapExpireTimeTicks = exports.getTwapExpireTimeTicks = function getTwapExpireTimeTicks(durationMinutes) {
|
|
70
|
+
var now = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Date.now();
|
|
71
|
+
var end = getTwapEndTime(durationMinutes, now);
|
|
72
|
+
if (end === null) return null;
|
|
73
|
+
return new _bignumber["default"](end.getTime()).times(TICKS_PER_MILLISECOND).plus(TICKS_AT_UNIX_EPOCH).integerValue(_bignumber["default"].ROUND_FLOOR).toNumber();
|
|
74
|
+
};
|
|
75
|
+
var parseSlices = exports.parseSlices = function parseSlices(slices) {
|
|
76
|
+
var n = Number(slices);
|
|
77
|
+
return Number.isInteger(n) && n > 0 ? n : null;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Slice size for `total` split into `slices` slices, rounded UP to `decimalPlaces` so that the
|
|
82
|
+
* engine's ceil(total / slice) is never more than the requested number of slices (rounding down
|
|
83
|
+
* could add a hundred-and-first slice). Null when the inputs are not usable yet.
|
|
84
|
+
*/
|
|
85
|
+
var getTwapSliceSize = exports.getTwapSliceSize = function getTwapSliceSize(total, slices, decimalPlaces) {
|
|
86
|
+
var totalBN = new _bignumber["default"](total === '' || total === null || total === undefined ? NaN : total);
|
|
87
|
+
var n = parseSlices(slices);
|
|
88
|
+
if (!totalBN.isFinite() || totalBN.lte(0) || n === null) return null;
|
|
89
|
+
return totalBN.div(n).dp(decimalPlaces, _bignumber["default"].ROUND_UP);
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The number of slices the engine runs for `total` split into slices of `sliceSize`: ceil(total /
|
|
94
|
+
* slice), the last slice taking whatever is left. Fewer than the trader asked for when the slice
|
|
95
|
+
* size rounded up (1 BTC in 6 slices at a 0.1 increment is 5 slices of 0.2). Null without a slice.
|
|
96
|
+
*/
|
|
97
|
+
var getTwapSliceCount = exports.getTwapSliceCount = function getTwapSliceCount(total, sliceSize) {
|
|
98
|
+
if (sliceSize === null || sliceSize === undefined) return null;
|
|
99
|
+
var totalBN = new _bignumber["default"](total === '' || total === null || total === undefined ? NaN : total);
|
|
100
|
+
var size = new _bignumber["default"](sliceSize);
|
|
101
|
+
if (!totalBN.isFinite() || totalBN.lte(0) || !size.isFinite() || size.lte(0)) return null;
|
|
102
|
+
return totalBN.div(size).integerValue(_bignumber["default"].ROUND_CEIL).toNumber();
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
/** Seconds between slice releases (the engine releases slice 0 on entry). */
|
|
106
|
+
var getTwapIntervalSeconds = exports.getTwapIntervalSeconds = function getTwapIntervalSeconds(durationMinutes, slices) {
|
|
107
|
+
var minutes = Number(durationMinutes);
|
|
108
|
+
var n = parseSlices(slices);
|
|
109
|
+
if (!(minutes > 0) || n === null) return null;
|
|
110
|
+
return minutes * 60 / n;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Whether a quantity-sized TWAP's slice is under the instrument's minimum quantity, which the engine
|
|
115
|
+
* rejects (Twap_Slice_Below_Minimum). A value-sized TWAP has no quantity slice to check.
|
|
116
|
+
*/
|
|
117
|
+
var isTwapSliceBelowMinimum = exports.isTwapSliceBelowMinimum = function isTwapSliceBelowMinimum(formValues, instrument, quantityDecimalPlaces) {
|
|
118
|
+
if (!instrument || !(Number(instrument.MinimumQuantity) > 0) || isTwapByValue(formValues)) return false;
|
|
119
|
+
var sliceSize = getTwapSliceSize(formValues.quantity, formValues.slices, quantityDecimalPlaces);
|
|
120
|
+
return sliceSize !== null && sliceSize.lt(instrument.MinimumQuantity);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Everything the form and the confirm modal need to describe the schedule, as the engine will run
|
|
125
|
+
* it: `slices` and `intervalSeconds` follow from the rounded slice size, not the number entered.
|
|
126
|
+
* `instrument` is the selected instrument record; `marketPrice` the touch on the order's side.
|
|
127
|
+
* `quantityDecimalPlaces` / `valueDecimalPlaces` are those of the amount and value inputs.
|
|
128
|
+
*/
|
|
129
|
+
var getTwapSchedule = exports.getTwapSchedule = function getTwapSchedule(formValues, instrument, marketPrice, quantityDecimalPlaces, valueDecimalPlaces) {
|
|
130
|
+
var byValue = isTwapByValue(formValues);
|
|
131
|
+
var requestedSlices = parseSlices(formValues.slices);
|
|
132
|
+
var total = byValue ? formValues.value : formValues.quantity;
|
|
133
|
+
var sliceDecimalPlaces = byValue ? valueDecimalPlaces : quantityDecimalPlaces;
|
|
134
|
+
var sliceSize = getTwapSliceSize(total, requestedSlices, sliceDecimalPlaces);
|
|
135
|
+
var slices = sliceSize === null ? requestedSlices : getTwapSliceCount(total, sliceSize);
|
|
136
|
+
var price = hasLimitPrice(formValues) ? new _bignumber["default"](formValues.limitPrice) : new _bignumber["default"](marketPrice || 0);
|
|
137
|
+
var sliceValue = sliceSize === null ? null : byValue ? sliceSize : sliceSize.times(price);
|
|
138
|
+
return {
|
|
139
|
+
byValue: byValue,
|
|
140
|
+
isLimit: hasLimitPrice(formValues),
|
|
141
|
+
requestedSlices: requestedSlices,
|
|
142
|
+
slices: slices,
|
|
143
|
+
durationMinutes: Number(formValues.durationMinutes) > 0 ? Number(formValues.durationMinutes) : null,
|
|
144
|
+
intervalSeconds: getTwapIntervalSeconds(formValues.durationMinutes, slices),
|
|
145
|
+
sliceSize: sliceSize,
|
|
146
|
+
sliceDecimalPlaces: sliceDecimalPlaces,
|
|
147
|
+
sliceSymbol: byValue ? instrument === null || instrument === void 0 ? void 0 : instrument.Product2Symbol : instrument === null || instrument === void 0 ? void 0 : instrument.Product1Symbol,
|
|
148
|
+
sliceValue: sliceValue,
|
|
149
|
+
belowMinimumQuantity: isTwapSliceBelowMinimum(formValues, instrument, quantityDecimalPlaces)
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Validation of the schedule inputs, for the redux-form validators of the duration and slices
|
|
155
|
+
* fields. Each returns an `{ key, vars }` for the `order` namespace, or undefined when valid.
|
|
156
|
+
*/
|
|
157
|
+
var getTwapDurationError = exports.getTwapDurationError = function getTwapDurationError(value) {
|
|
158
|
+
var minutes = Number(value);
|
|
159
|
+
// t('Must be greater than {{a}}', { ns: 'translation' })
|
|
160
|
+
if (!(minutes > 0)) return {
|
|
161
|
+
key: 'Must be greater than {{a}}',
|
|
162
|
+
vars: {
|
|
163
|
+
a: 0,
|
|
164
|
+
ns: 'translation'
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
if (minutes > TWAP_MAX_DURATION_MINUTES) {
|
|
168
|
+
// t('Must be less than {{a}}', { ns: 'translation' })
|
|
169
|
+
return {
|
|
170
|
+
key: 'Must be less than {{a}}',
|
|
171
|
+
vars: {
|
|
172
|
+
a: TWAP_MAX_DURATION_MINUTES + 1,
|
|
173
|
+
ns: 'translation'
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return undefined;
|
|
178
|
+
};
|
|
179
|
+
var getTwapSlicesError = exports.getTwapSlicesError = function getTwapSlicesError(value, formValues, instrument, quantityDecimalPlaces) {
|
|
180
|
+
var slices = parseSlices(value);
|
|
181
|
+
if (slices === null || slices > TWAP_MAX_SLICES) {
|
|
182
|
+
// t('Must be a whole number between {{min}} and {{max}}')
|
|
183
|
+
return {
|
|
184
|
+
key: 'Must be a whole number between {{min}} and {{max}}',
|
|
185
|
+
vars: {
|
|
186
|
+
min: 1,
|
|
187
|
+
max: TWAP_MAX_SLICES
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
if (isTwapSliceBelowMinimum(_objectSpread(_objectSpread({}, formValues), {}, {
|
|
192
|
+
slices: slices
|
|
193
|
+
}), instrument, quantityDecimalPlaces)) {
|
|
194
|
+
return {
|
|
195
|
+
// t('Each slice must be at least {{min}} {{symbol}}. Increase the amount or use fewer slices')
|
|
196
|
+
key: 'Each slice must be at least {{min}} {{symbol}}. Increase the amount or use fewer slices',
|
|
197
|
+
vars: {
|
|
198
|
+
min: (0, _numberFormatter.formatNumberToLocale)(instrument.MinimumQuantity, quantityDecimalPlaces),
|
|
199
|
+
symbol: instrument.Product1Symbol
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
return undefined;
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Wire fields SendOrder needs for a TWAP, derived from the form. The caller spreads them over the
|
|
208
|
+
* order it built for a plain advanced order, so this also removes the fields a TWAP form must not
|
|
209
|
+
* send (Value on a quantity-sized order, Quantity and LimitPrice on a value-sized one).
|
|
210
|
+
*/
|
|
211
|
+
var getTwapOrderFields = exports.getTwapOrderFields = function getTwapOrderFields(formValues, _ref2) {
|
|
212
|
+
var quantityDecimalPlaces = _ref2.quantityDecimalPlaces,
|
|
213
|
+
priceDecimalPlaces = _ref2.priceDecimalPlaces,
|
|
214
|
+
now = _ref2.now;
|
|
215
|
+
var byValue = isTwapByValue(formValues);
|
|
216
|
+
var fields = {
|
|
217
|
+
TimeInForce: _timeInForceConstants.timeInForceForOrderType[_orderEntryFormConstants.orderTypes.twap.displayName],
|
|
218
|
+
ExpireTime: getTwapExpireTimeTicks(formValues.durationMinutes, now)
|
|
219
|
+
};
|
|
220
|
+
if (byValue) {
|
|
221
|
+
var _getTwapSliceSize;
|
|
222
|
+
fields.Value = _bignumber["default"].isBigNumber(formValues.value) ? formValues.value.toNumber() : Number(formValues.value);
|
|
223
|
+
fields.DisplayQuantity = (_getTwapSliceSize = getTwapSliceSize(formValues.value, formValues.slices, priceDecimalPlaces)) === null || _getTwapSliceSize === void 0 ? void 0 : _getTwapSliceSize.toNumber();
|
|
224
|
+
// The gateway sets UseDisplayQuantity itself for a quantity-sized TWAP; for a value-sized one the
|
|
225
|
+
// reserve-order checks do not apply, and it reads DisplayQuantity as the slice value.
|
|
226
|
+
fields.UseDisplayQuantity = false;
|
|
227
|
+
} else {
|
|
228
|
+
var _getTwapSliceSize2;
|
|
229
|
+
fields.DisplayQuantity = (_getTwapSliceSize2 = getTwapSliceSize(formValues.quantity, formValues.slices, quantityDecimalPlaces)) === null || _getTwapSliceSize2 === void 0 ? void 0 : _getTwapSliceSize2.toNumber();
|
|
230
|
+
fields.UseDisplayQuantity = true;
|
|
231
|
+
}
|
|
232
|
+
return fields;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Fields a TWAP must not carry, by form. Removed from the order after the generic builder ran: a
|
|
237
|
+
* value-sized buy has no Quantity, a quantity-sized order no Value, the market form no LimitPrice
|
|
238
|
+
* (the gateway reads an empty one as 0 but need not), and no TWAP is PostOnly.
|
|
239
|
+
*/
|
|
240
|
+
var getTwapOmittedFields = exports.getTwapOmittedFields = function getTwapOmittedFields(formValues) {
|
|
241
|
+
if (isTwapByValue(formValues)) return ['Quantity', 'LimitPrice', 'PostOnly'];
|
|
242
|
+
return hasLimitPrice(formValues) ? ['Value', 'PostOnly'] : ['Value', 'LimitPrice', 'PostOnly'];
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* GetOrderFee knows nothing about TWAP: a market-form TWAP is charged like a market order and a
|
|
247
|
+
* limit-form one like a limit order, so the fee estimate is requested as that order type.
|
|
248
|
+
*/
|
|
249
|
+
var getFeeFormValues = exports.getFeeFormValues = function getFeeFormValues(formValues) {
|
|
250
|
+
if (!isTwapOrderType(formValues.orderType)) return formValues;
|
|
251
|
+
return _objectSpread(_objectSpread({}, formValues), {}, {
|
|
252
|
+
orderType: hasLimitPrice(formValues) ? _orderEntryFormConstants.orderTypes.limit.displayName : _orderEntryFormConstants.orderTypes.market.displayName
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
/** "5 min" for whole minutes, "514 s" otherwise. `t` is the i18next function of the `order` namespace. */
|
|
257
|
+
var formatTwapInterval = exports.formatTwapInterval = function formatTwapInterval(intervalSeconds, t) {
|
|
258
|
+
if (!(intervalSeconds > 0)) return '-';
|
|
259
|
+
if (intervalSeconds % 60 === 0) return t('{{n}} min', {
|
|
260
|
+
n: intervalSeconds / 60
|
|
261
|
+
});
|
|
262
|
+
return t('{{n}} s', {
|
|
263
|
+
n: Math.round(intervalSeconds)
|
|
264
|
+
});
|
|
265
|
+
};
|