Skip to content

Commit

Permalink
fixed matching
Browse files Browse the repository at this point in the history
  • Loading branch information
egerj committed Apr 1, 2021
1 parent 47233f6 commit eab053b
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions src/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ export class OrderService {
const orderDeleted = new OrderDeletedDto(order);
await order.delete();
this.msSocket.server.to('stockmarket').emit('update-orderbook');
await this.httpService.post(order.onDelete, orderDeleted).toPromise();
try {
await this.httpService.post(order.onDelete, orderDeleted).toPromise();
} catch (error) {
console.error("Request URL doesn't exist.");
}
}
}

Expand All @@ -113,12 +117,16 @@ export class OrderService {
timestamp: new Date().getTime(),
});

await this.httpService
.post(order.onPlace, {
jobId: jobId.toString(),
...order.toJSON(),
})
.toPromise();
try {
await this.httpService
.post(order.onPlace, {
jobId: jobId.toString(),
...order.toJSON(),
})
.toPromise();
} catch (error) {
console.error("Request URL doesn't exist.");
}

await this.orderPlaced(order);
}
Expand Down Expand Up @@ -151,9 +159,14 @@ export class OrderService {
const readyForDelete = await this.orderModel.find({ amount: { $lte: 0 } });
await Promise.all(
readyForDelete.map(async (d) => {
await this.httpService
.post(d.onComplete, new OrderCompletedDto(d))
.toPromise();
try {
await this.httpService
.post(d.onComplete, new OrderCompletedDto(d))
.toPromise();
} catch (error) {
console.error("Request URL doesn't exist.");
}

await d.delete();
}),
);
Expand Down Expand Up @@ -322,12 +335,16 @@ export class OrderService {
await this.updateOrderAmount(iOrder, amount, price);
await this.updateOrderAmount(mOrder, amount, price);

await this.httpService
.post(iOrder.onMatch, new OrderMatchedDto(iOrder, remaining))
.toPromise();
await this.httpService
.post(mOrder.onMatch, new OrderMatchedDto(mOrder, remaining))
.toPromise();
try {
await this.httpService
.post(iOrder.onMatch, new OrderMatchedDto(iOrder, remaining))
.toPromise();
await this.httpService
.post(mOrder.onMatch, new OrderMatchedDto(mOrder, remaining))
.toPromise();
} catch (error) {
console.error("Request URL doesn't exist.");
}

remaining -= amount;

Expand Down

0 comments on commit eab053b

Please sign in to comment.