diff --git a/package.json b/package.json index 120bb137..ff87b895 100644 --- a/package.json +++ b/package.json @@ -75,18 +75,18 @@ }, "devDependencies": { "@types/jest": "^29.5.12", - "@types/node": "^18.19.33", + "@types/node": "^18.19.34", "@types/source-map-support": "^0.5.10", "@typescript-eslint/eslint-plugin": "^7.1.1", "@typescript-eslint/parser": "^7.1.1", - "ajv": "^8.13.0", + "ajv": "^8.16.0", "eslint": "^8.57.0", "eslint-plugin-jest": "^27.9.0", "eslint-plugin-rxjs": "^5.0.3", "jest": "^29.7.0", "jest-environment-node": "^29.7.0", "jest-junit": "^16.0.0", - "ts-jest": "^29.1.2", + "ts-jest": "^29.1.4", "typedoc": "^0.25.13", "typescript": "^5.4.5" }, diff --git a/src/core/io/decoder.ts b/src/core/io/decoder.ts index 72c28a47..77b3be0e 100644 --- a/src/core/io/decoder.ts +++ b/src/core/io/decoder.ts @@ -460,7 +460,7 @@ export class Decoder { * Read a token from queue and return it as boolean value. */ readBool(): boolean { - return !!parseInt(this.readStr(), 10); + return parseInt(this.readStr()) != 0; } /** @@ -2665,6 +2665,7 @@ export class Decoder { /** * Decode a [[Contract]] object from data queue. + * @deprecated to remove */ private decodeContract(version: number): Contract { const contract: Contract = {}; @@ -2693,6 +2694,7 @@ export class Decoder { /** * Decode a [[Order]] object from data queue. + * @deprecated to remove */ private decodeOrder(version: number): Order { const order: Order = {}; @@ -2804,6 +2806,7 @@ export class Decoder { /** * Decode a [[ComboLeg]] object from data queue. + * @deprecated to remove */ private decodeComboLeg(): ComboLeg { return { @@ -2998,7 +3001,8 @@ class OrderDecoder { this.order.faGroup = this.decoder.readStr(); this.order.faMethod = this.decoder.readStr(); this.order.faPercentage = this.decoder.readStr(); - this.order.faProfile = this.decoder.readStr(); + if (this.version < MIN_SERVER_VER.FA_PROFILE_DESUPPORT) + this.order.faProfile = this.decoder.readStr(); } } @@ -3278,7 +3282,11 @@ class OrderDecoder { this.order.scalePriceIncrement = this.decoder.readDoubleOrUndefined(); } - if (this.version >= 28 && this.order.scalePriceIncrement > 0.0) { + if ( + this.version >= 28 && + this.order.scalePriceIncrement && + this.order.scalePriceIncrement > 0.0 + ) { this.order.scalePriceAdjustValue = this.decoder.readDoubleOrUndefined(); this.order.scalePriceAdjustInterval = this.decoder.readIntOrUndefined(); this.order.scaleProfitOffset = this.decoder.readDoubleOrUndefined(); diff --git a/src/tests/unit/api/order/placeConditionalOrder.test.ts b/src/tests/unit/api/order/placeConditionalOrder.test.ts index c3caac0a..e95f32be 100644 --- a/src/tests/unit/api/order/placeConditionalOrder.test.ts +++ b/src/tests/unit/api/order/placeConditionalOrder.test.ts @@ -103,7 +103,7 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { if (orderId == refId && !isDone) { @@ -138,7 +138,7 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); test("placeOrder with ExecutionCondition", (done) => { @@ -160,7 +160,7 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { if (orderId == refId && !isDone) { @@ -195,7 +195,7 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); test("placeOrder with MarginCondition", (done) => { @@ -217,7 +217,7 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { if (orderId == refId && !isDone) { @@ -252,7 +252,7 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); test("placeOrder with PercentChangeCondition", (done) => { @@ -274,7 +274,7 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { if (orderId == refId && !isDone) { @@ -309,7 +309,7 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); test("placeOrder with TimeCondition", (done) => { @@ -331,16 +331,19 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { - if (orderId == refId && !isDone) { + if (orderId == refId) { isDone = true; expect(contract.symbol).toEqual(refContract.symbol); expect(order.totalQuantity).toEqual(refOrder.totalQuantity); - done(); } }) + .on(EventName.openOrderEnd, () => { + if (isDone) done(); + else done("failed"); + }) .on( EventName.error, ( @@ -366,7 +369,7 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); test("placeOrder with VolumeCondition", (done) => { @@ -388,7 +391,7 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { if (orderId == refId && !isDone) { @@ -423,7 +426,7 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); test("placeOrder with all conditions", (done) => { @@ -452,7 +455,7 @@ describe("Place Conditional Orders", () => { let isDone = false; ib.once(EventName.nextValidId, (orderId: number) => { refId = orderId; - ib.placeOrder(refId, refContract, refOrder); + ib.placeOrder(refId, refContract, refOrder).reqOpenOrders(); }) .on(EventName.openOrder, (orderId, contract, order, _orderState) => { if (orderId == refId && !isDone) { @@ -487,6 +490,6 @@ describe("Place Conditional Orders", () => { }, ); - ib.connect().reqOpenOrders(); + ib.connect(); }); }); diff --git a/yarn.lock b/yarn.lock index ff3a243c..84dce2e3 100644 --- a/yarn.lock +++ b/yarn.lock @@ -825,10 +825,10 @@ resolved "https://registry.yarnpkg.com/@types/node/-/node-18.16.19.tgz#cb03fca8910fdeb7595b755126a8a78144714eea" integrity sha512-IXl7o+R9iti9eBW4Wg2hx1xQDig183jj7YLn8F7udNceyfkbn1ZxmzZXuak20gR40D7pIkIY1kYGx5VIGbaHKA== -"@types/node@^18.19.33": - version "18.19.33" - resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.33.tgz#98cd286a1b8a5e11aa06623210240bcc28e95c48" - integrity sha512-NR9+KrpSajr2qBVp/Yt5TU/rp+b5Mayi3+OlMlcg2cVCfRmcG5PWZ7S4+MG9PZ5gWBoc9Pd0BKSRViuBCRPu0A== +"@types/node@^18.19.34": + version "18.19.34" + resolved "https://registry.yarnpkg.com/@types/node/-/node-18.19.34.tgz#c3fae2bbbdb94b4a52fe2d229d0dccce02ef3d27" + integrity sha512-eXF4pfBNV5DAMKGbI02NnDtWrQ40hAN558/2vvS4gMpMIxaf6JmD7YjnZbq0Q9TDSSkKBamime8ewRoomHdt4g== dependencies: undici-types "~5.26.4" @@ -1027,10 +1027,10 @@ ajv@^6.12.4: json-schema-traverse "^0.4.1" uri-js "^4.2.2" -ajv@^8.13.0: - version "8.13.0" - resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.13.0.tgz#a3939eaec9fb80d217ddf0c3376948c023f28c91" - integrity sha512-PRA911Blj99jR5RMeTunVbNXMF6Lp4vZXnk5GQjcnUWUTsrXtekg/pnmFFI2u/I36Y/2bITGS30GZCXei6uNkA== +ajv@^8.16.0: + version "8.16.0" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-8.16.0.tgz#22e2a92b94f005f7e0f9c9d39652ef0b8f6f0cb4" + integrity sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw== dependencies: fast-deep-equal "^3.1.3" json-schema-traverse "^1.0.0" @@ -3137,10 +3137,10 @@ ts-api-utils@^1.0.1: resolved "https://registry.yarnpkg.com/ts-api-utils/-/ts-api-utils-1.0.2.tgz#7c094f753b6705ee4faee25c3c684ade52d66d99" integrity sha512-Cbu4nIqnEdd+THNEsBdkolnOXhg0I8XteoHaEKgvsxpsbWda4IsUut2c187HxywQCvveojow0Dgw/amxtSKVkQ== -ts-jest@^29.1.2: - version "29.1.2" - resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.2.tgz#7613d8c81c43c8cb312c6904027257e814c40e09" - integrity sha512-br6GJoH/WUX4pu7FbZXuWGKGNDuU7b8Uj77g/Sp7puZV6EXzuByl6JrECvm0MzVzSTkSHWTihsXt+5XYER5b+g== +ts-jest@^29.1.4: + version "29.1.4" + resolved "https://registry.yarnpkg.com/ts-jest/-/ts-jest-29.1.4.tgz#26f8a55ce31e4d2ef7a1fd47dc7fa127e92793ef" + integrity sha512-YiHwDhSvCiItoAgsKtoLFCuakDzDsJ1DLDnSouTaTmdOcOwIkSzbLXduaQ6M5DRVhuZC/NYaaZ/mtHbWMv/S6Q== dependencies: bs-logger "0.x" fast-json-stable-stringify "2.x"