Throw error if price or size is too small

This commit is contained in:
Gary Wang 2020-08-15 22:27:50 -07:00
parent 9223575e6f
commit 7848262c4d
2 changed files with 15 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@project-serum/serum",
"version": "0.4.1",
"version": "0.4.2",
"description": "Library for interacting with the serum dex",
"license": "MIT",
"repository": "project-serum/serum-js",

View File

@ -210,6 +210,12 @@ export class Market {
} else {
openOrdersAddress = openOrdersAccounts[0].address;
}
if (this.baseSizeNumberToLots(size).lte(new BN(0))) {
throw new Error('size too small');
}
if (this.priceNumberToLots(price).lte(new BN(0))) {
throw new Error('invalid price');
}
transaction.add(
DexInstructions.newOrder({
market: this.address,
@ -372,6 +378,14 @@ export class Market {
return native.div(this._decoded.quoteLotSize);
}
get minOrderSize() {
return this.baseSizeLotsToNumber(new BN(1));
}
get tickSize() {
return this.priceLotsToNumber(new BN(1));
}
async matchOrders(connection: Connection, feePayer: Account, limit: number) {
const tx = new Transaction();
tx.add(