Skip to content

Commit

Permalink
handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
amityadav0 committed Dec 24, 2024
1 parent 4530a5e commit 39c619b
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions x/tradeshield/keeper/msg_server_execute_orders.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,32 @@ func (k msgServer) ExecuteOrders(goCtx context.Context, msg *types.MsgExecuteOrd
switch spotOrder.OrderType {
case types.SpotOrderType_STOPLOSS:
// execute the stop loss order
_, err = k.ExecuteStopLossOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteStopLossOrder(cachedCtx, spotOrder)
if err == nil {
write()
}

Check warning on line 34 in x/tradeshield/keeper/msg_server_execute_orders.go

View check run for this annotation

Codecov / codecov/patch

x/tradeshield/keeper/msg_server_execute_orders.go#L30-L34

Added lines #L30 - L34 were not covered by tests
case types.SpotOrderType_LIMITSELL:
// execute the limit sell order
_, err = k.ExecuteLimitSellOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteLimitSellOrder(cachedCtx, spotOrder)
if err == nil {
write()
}

Check warning on line 41 in x/tradeshield/keeper/msg_server_execute_orders.go

View check run for this annotation

Codecov / codecov/patch

x/tradeshield/keeper/msg_server_execute_orders.go#L37-L41

Added lines #L37 - L41 were not covered by tests
case types.SpotOrderType_LIMITBUY:
// execute the limit buy order
_, err = k.ExecuteLimitBuyOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteLimitBuyOrder(cachedCtx, spotOrder)
if err == nil {
write()
}
case types.SpotOrderType_MARKETBUY:
// execute the market buy order
_, err = k.ExecuteMarketBuyOrder(ctx, spotOrder)
cachedCtx, write := ctx.CacheContext()
_, err = k.ExecuteMarketBuyOrder(cachedCtx, spotOrder)
if err == nil {
write()
}

Check warning on line 55 in x/tradeshield/keeper/msg_server_execute_orders.go

View check run for this annotation

Codecov / codecov/patch

x/tradeshield/keeper/msg_server_execute_orders.go#L51-L55

Added lines #L51 - L55 were not covered by tests
}

// log the error if any
Expand All @@ -61,7 +77,11 @@ func (k msgServer) ExecuteOrders(goCtx context.Context, msg *types.MsgExecuteOrd
switch perpetualOrder.PerpetualOrderType {
case types.PerpetualOrderType_LIMITOPEN:
// execute the limit open order
err = k.ExecuteLimitOpenOrder(ctx, perpetualOrder)
cachedCtx, write := ctx.CacheContext()
err = k.ExecuteLimitOpenOrder(cachedCtx, perpetualOrder)
if err == nil {
write()
}
// Disable for v1
// case types.PerpetualOrderType_LIMITCLOSE:
// // execute the limit close order
Expand Down

0 comments on commit 39c619b

Please sign in to comment.