Skip to content

Commit

Permalink
feat: if order placed and raiden disabled throw error (#991)
Browse files Browse the repository at this point in the history
feat: if order placed and raiden disabled throw error
  • Loading branch information
sangaman authored Aug 15, 2019
2 parents ab5778c + 72335a0 commit 4ecaf7b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/grpc/GrpcService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Order, isOwnOrder, OrderPortion, PlaceOrderResult, PlaceOrderEvent, Pla
import { errorCodes as orderErrorCodes } from '../orderbook/errors';
import { errorCodes as serviceErrorCodes } from '../service/errors';
import { errorCodes as p2pErrorCodes } from '../p2p/errors';
import { errorCodes as swapErrors } from '../swaps/errors';
import { errorCodes as lndErrorCodes } from '../lndclient/errors';
import { LndInfo } from '../lndclient/types';
import { SwapSuccess, SwapFailure } from '../swaps/types';
Expand Down Expand Up @@ -158,6 +159,8 @@ class GrpcService {
case orderErrorCodes.CURRENCY_CANNOT_BE_REMOVED:
case orderErrorCodes.MARKET_ORDERS_NOT_ALLOWED:
case serviceErrorCodes.NOMATCHING_MODE_IS_REQUIRED:
case orderErrorCodes.INSUFFICIENT_OUTBOUND_BALANCE:
case swapErrors.SWAP_CLIENT_NOT_FOUND:
code = status.FAILED_PRECONDITION;
break;
case lndErrorCodes.LND_IS_UNAVAILABLE:
Expand Down
17 changes: 13 additions & 4 deletions lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,21 @@ class OrderBook extends EventEmitter {

if (!this.nobalancechecks) {
// check if sufficient outbound channel capacity exists
const { outboundCurrency, outboundAmount } = Swaps.calculateInboundOutboundAmounts(order.quantity, order.price, order.isBuy, order.pairId);
const swapClient = this.swaps.swapClientManager.get(outboundCurrency);
if (!swapClient) {
const { outboundCurrency, inboundCurrency, outboundAmount } =
Swaps.calculateInboundOutboundAmounts(order.quantity, order.price, order.isBuy, order.pairId);
const outboundSwapClient = this.swaps.swapClientManager.get(outboundCurrency);
const inboundSwapClient = this.swaps.swapClientManager.get(inboundCurrency);

// check if clients exists
if (!outboundSwapClient) {
throw swapsErrors.SWAP_CLIENT_NOT_FOUND(outboundCurrency);
}
const maximumOutboundAmount = swapClient.maximumOutboundCapacity(outboundCurrency);

if (!inboundSwapClient) {
throw swapsErrors.SWAP_CLIENT_NOT_FOUND(inboundCurrency);
}

const maximumOutboundAmount = outboundSwapClient.maximumOutboundCapacity(outboundCurrency);
if (outboundAmount > maximumOutboundAmount) {
throw errors.INSUFFICIENT_OUTBOUND_BALANCE(outboundCurrency, outboundAmount, maximumOutboundAmount);
}
Expand Down

0 comments on commit 4ecaf7b

Please sign in to comment.