Skip to content

Commit

Permalink
Merge pull request #216 from stoqey/issue203
Browse files Browse the repository at this point in the history
Issue Unprocessed Data #203 bug fix (server version >= 177)
  • Loading branch information
rylorin authored Jun 13, 2024
2 parents fd6732b + 61c3457 commit 691e6a6
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
14 changes: 11 additions & 3 deletions src/core/io/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -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 = {};
Expand Down Expand Up @@ -2804,6 +2806,7 @@ export class Decoder {

/**
* Decode a [[ComboLeg]] object from data queue.
* @deprecated to remove
*/
private decodeComboLeg(): ComboLeg {
return {
Expand Down Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
Expand Down
35 changes: 19 additions & 16 deletions src/tests/unit/api/order/placeConditionalOrder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -138,7 +138,7 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});

test("placeOrder with ExecutionCondition", (done) => {
Expand All @@ -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) {
Expand Down Expand Up @@ -195,7 +195,7 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});

test("placeOrder with MarginCondition", (done) => {
Expand All @@ -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) {
Expand Down Expand Up @@ -252,7 +252,7 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});

test("placeOrder with PercentChangeCondition", (done) => {
Expand All @@ -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) {
Expand Down Expand Up @@ -309,7 +309,7 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});

test("placeOrder with TimeCondition", (done) => {
Expand All @@ -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,
(
Expand All @@ -366,7 +369,7 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});

test("placeOrder with VolumeCondition", (done) => {
Expand All @@ -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) {
Expand Down Expand Up @@ -423,7 +426,7 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});

test("placeOrder with all conditions", (done) => {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -487,6 +490,6 @@ describe("Place Conditional Orders", () => {
},
);

ib.connect().reqOpenOrders();
ib.connect();
});
});
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 691e6a6

Please sign in to comment.