Skip to content
This repository was archived by the owner on Jul 17, 2021. It is now read-only.

Commit e927236

Browse files
committed
Add logger for Gridbot createOrder errors
1 parent 1fc4838 commit e927236

File tree

1 file changed

+40
-16
lines changed

1 file changed

+40
-16
lines changed

src/grid_bot/index.ts

Lines changed: 40 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import SandExchange from 'sand-ex';
1111
import { floor } from 'lodash';
1212

1313
import { OHLCV, OrderStatus, OrderType, OrderSide } from 'sand-ex/build/types';
14+
import { logger } from '../logger';
1415

1516
const DEFAULT_PRECISION = 8;
1617

@@ -127,26 +128,49 @@ export class GridBot {
127128
// Buy
128129
if (currentPrice >= priceLow && activeOrderId === null && ownedQuantity === 0) {
129130
const requiredQuantity = maxQuantity;
130-
const orderInfo = this.exchange.createNewOrder({
131-
side: OrderSide.BUY,
132-
type: OrderType.LIMIT,
133-
price: priceLow,
134-
quantity: requiredQuantity,
135-
});
136-
137-
return { ...grid, ...{ activeOrderId: orderInfo.orderId } };
131+
132+
try {
133+
const orderInfo = this.exchange.createNewOrder({
134+
side: OrderSide.BUY,
135+
type: OrderType.LIMIT,
136+
price: priceLow,
137+
quantity: requiredQuantity,
138+
});
139+
140+
return { ...grid, ...{ activeOrderId: orderInfo.orderId } };
141+
} catch (err) {
142+
logger.error(
143+
`Gridbot createNewOrder error, details: ${JSON.stringify({
144+
side: OrderSide.BUY,
145+
type: OrderType.LIMIT,
146+
price: priceLow,
147+
quantity: requiredQuantity,
148+
})} `,
149+
);
150+
}
138151
}
139152

140153
// Sell
141154
if (currentPrice <= priceHigh && activeOrderId === null && ownedQuantity !== 0) {
142-
const orderInfo = this.exchange.createNewOrder({
143-
side: OrderSide.SELL,
144-
type: OrderType.LIMIT,
145-
price: priceHigh,
146-
quantity: ownedQuantity,
147-
});
148-
149-
return { ...grid, ...{ activeOrderId: orderInfo.orderId } };
155+
try {
156+
const orderInfo = this.exchange.createNewOrder({
157+
side: OrderSide.SELL,
158+
type: OrderType.LIMIT,
159+
price: priceHigh,
160+
quantity: ownedQuantity,
161+
});
162+
163+
return { ...grid, ...{ activeOrderId: orderInfo.orderId } };
164+
} catch (err) {
165+
logger.error(
166+
`Gridbot createNewOrder error, details: ${JSON.stringify({
167+
side: OrderSide.SELL,
168+
type: OrderType.LIMIT,
169+
price: priceHigh,
170+
quantity: ownedQuantity,
171+
})} `,
172+
);
173+
}
150174
}
151175

152176
return { ...grid };

0 commit comments

Comments
 (0)