@@ -11,6 +11,7 @@ import SandExchange from 'sand-ex';
1111import { floor } from 'lodash' ;
1212
1313import { OHLCV , OrderStatus , OrderType , OrderSide } from 'sand-ex/build/types' ;
14+ import { logger } from '../logger' ;
1415
1516const 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