From 8182da3b3180dd249634159e822d99ca02a611c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20G=C5=82ownia?= Date: Thu, 30 Nov 2023 11:25:25 +0100 Subject: [PATCH] feat(deal-ticket): fix postOnly mapping in mapFormValuesToOrderSubmission (#5375) --- .../utils/map-form-values-to-submission.ts | 14 +-- .../map-form-values-to-submisstion.spec.ts | 87 +++++++++++++++++++ 2 files changed, 96 insertions(+), 5 deletions(-) diff --git a/libs/deal-ticket/src/utils/map-form-values-to-submission.ts b/libs/deal-ticket/src/utils/map-form-values-to-submission.ts index 4f73d2989..6d9e690b3 100644 --- a/libs/deal-ticket/src/utils/map-form-values-to-submission.ts +++ b/libs/deal-ticket/src/utils/map-form-values-to-submission.ts @@ -32,15 +32,19 @@ export const mapFormValuesToOrderSubmission = ( ? toNanoSeconds(order.expiresAt) : undefined, postOnly: - order.type === Schema.OrderType.TYPE_MARKET ? false : order.postOnly, - reduceOnly: - order.type === Schema.OrderType.TYPE_LIMIT && - ![ + order.type === Schema.OrderType.TYPE_MARKET || + [ Schema.OrderTimeInForce.TIME_IN_FORCE_FOK, Schema.OrderTimeInForce.TIME_IN_FORCE_IOC, ].includes(order.timeInForce) ? false - : order.reduceOnly, + : order.postOnly, + reduceOnly: ![ + Schema.OrderTimeInForce.TIME_IN_FORCE_FOK, + Schema.OrderTimeInForce.TIME_IN_FORCE_IOC, + ].includes(order.timeInForce) + ? false + : order.reduceOnly, icebergOpts: order.type === Schema.OrderType.TYPE_LIMIT && isPersistentOrder(order.timeInForce) && diff --git a/libs/deal-ticket/src/utils/map-form-values-to-submisstion.spec.ts b/libs/deal-ticket/src/utils/map-form-values-to-submisstion.spec.ts index 2afccaf2c..a8ecc5560 100644 --- a/libs/deal-ticket/src/utils/map-form-values-to-submisstion.spec.ts +++ b/libs/deal-ticket/src/utils/map-form-values-to-submisstion.spec.ts @@ -98,4 +98,91 @@ describe('mapFormValuesToOrderSubmission', () => { ).size ).toEqual('1000'); }); + + it.each([ + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK, postOnly: false }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GFA, postOnly: true }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GFN, postOnly: true }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC, postOnly: true }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTT, postOnly: true }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_IOC, postOnly: false }, + ])( + 'sets postOnly correctly when TIF is $timeInForce', + ({ + timeInForce, + postOnly, + }: { + timeInForce: OrderTimeInForce; + postOnly: boolean; + }) => { + expect( + mapFormValuesToOrderSubmission( + { + type: OrderType.TYPE_LIMIT, + timeInForce, + postOnly: true, + } as OrderFormValues, + 'marketId', + 2, + 2 + ).postOnly + ).toEqual(postOnly); + // sets always false if type is market + expect( + mapFormValuesToOrderSubmission( + { + type: OrderType.TYPE_MARKET, + timeInForce, + postOnly: true, + } as OrderFormValues, + 'marketId', + 2, + 2 + ).postOnly + ).toEqual(false); + } + ); + + it.each([ + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_FOK, reduceOnly: true }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GFA, reduceOnly: false }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GFN, reduceOnly: false }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTC, reduceOnly: false }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_GTT, reduceOnly: false }, + { timeInForce: OrderTimeInForce.TIME_IN_FORCE_IOC, reduceOnly: true }, + ])( + 'sets reduceOnly correctly when TIF is $timeInForce', + ({ + timeInForce, + reduceOnly, + }: { + timeInForce: OrderTimeInForce; + reduceOnly: boolean; + }) => { + expect( + mapFormValuesToOrderSubmission( + { + type: OrderType.TYPE_MARKET, + timeInForce, + reduceOnly: true, + } as OrderFormValues, + 'marketId', + 2, + 2 + ).reduceOnly + ).toEqual(reduceOnly); + expect( + mapFormValuesToOrderSubmission( + { + type: OrderType.TYPE_LIMIT, + timeInForce, + reduceOnly: true, + } as OrderFormValues, + 'marketId', + 2, + 2 + ).reduceOnly + ).toEqual(reduceOnly); + } + ); });