Skip to content

Commit

Permalink
fix: addpair should prevent adding same base and quote assets (#1559)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsercano committed Oct 21, 2020
1 parent c958e86 commit 69f502f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/grpc/getGrpcError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const getGrpcError = (err: any) => {
case orderErrorCodes.MIN_QUANTITY_VIOLATED:
case orderErrorCodes.QUANTITY_DOES_NOT_MATCH:
case swapErrorCodes.REMOTE_IDENTIFIER_MISSING:
case orderErrorCodes.DUPLICATE_PAIR_CURRENCIES:
code = status.INVALID_ARGUMENT;
break;
case orderErrorCodes.PAIR_DOES_NOT_EXIST:
Expand Down
3 changes: 3 additions & 0 deletions lib/orderbook/OrderBook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ class OrderBook extends EventEmitter {

public addPair = async (pair: Pair) => {
const pairId = derivePairId(pair);
if (pair.baseCurrency.toLowerCase() === pair.quoteCurrency.toLowerCase()) {
throw errors.DUPLICATE_PAIR_CURRENCIES(pair.baseCurrency, pair.quoteCurrency);
}
if (this.pairInstances.has(pairId)) {
throw errors.PAIR_ALREADY_EXISTS(pairId);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/orderbook/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const errorCodes = {
INSUFFICIENT_OUTBOUND_BALANCE: codesPrefix.concat('.12'),
MIN_QUANTITY_VIOLATED: codesPrefix.concat('.13'),
QUANTITY_ON_HOLD: codesPrefix.concat('.15'),
DUPLICATE_PAIR_CURRENCIES: codesPrefix.concat('.16'),
};

const errors = {
Expand Down Expand Up @@ -75,6 +76,10 @@ const errors = {
message: `order with local id ${localId} has a quantity of ${holdQuantity} satoshis on hold, try again later`,
code: errorCodes.QUANTITY_DOES_NOT_MATCH,
}),
DUPLICATE_PAIR_CURRENCIES: (baseCurrency: string, quoteCurrency: string) => ({
message: `base asset (${baseCurrency}) and quote asset (${quoteCurrency}) have to be different`,
code: errorCodes.DUPLICATE_PAIR_CURRENCIES,
}),
};

export { errorCodes };
Expand Down

0 comments on commit 69f502f

Please sign in to comment.