Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
use chunking when adding orders to mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
xianny committed Feb 19, 2020
1 parent 1902655 commit 03f2d03
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/services/orderbook_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export class OrderBookService {
}
public async addOrdersAsync(signedOrders: SignedOrder[]): Promise<void> {
if (this._meshClient) {
const { rejected } = await this._meshClient.addOrdersAsync(signedOrders as any);
const { rejected } = await meshUtils.addOrdersToMeshAsync(this._meshClient, signedOrders);
if (rejected.length !== 0) {
const validationErrors = rejected.map((r, i) => ({
field: `signedOrder[${i}]`,
Expand Down
4 changes: 2 additions & 2 deletions src/utils/mesh_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ export const meshUtils = {
addOrdersToMeshAsync: async (
meshClient: WSClient,
orders: SignedOrder[],
batchSize: number = 100,
batchSize: number = 200,
): Promise<ValidationResults> => {
// Mesh rpc client can't handle a large amount of orders. This results in a fragmented
// send which Mesh cannot accept.
const validationResults: ValidationResults = { accepted: [], rejected: [] };
const chunks = _.chunk(orders, batchSize);
for (const chunk of chunks) {
const results = await meshClient.addOrdersAsync(chunk as any);
const results = await meshClient.addOrdersAsync(chunk);
validationResults.accepted = [...validationResults.accepted, ...results.accepted];
validationResults.rejected = [...validationResults.rejected, ...results.rejected];
}
Expand Down

0 comments on commit 03f2d03

Please sign in to comment.