diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-09-18 22:42:52 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-09-18 22:42:52 +0800 |
commit | 0003666050c4991623cb36ec994d536e4703b4fe (patch) | |
tree | e5b38ec2c8d5194c5c593b2beef90e6a5d09df0a /packages/asset-buyer/src/asset_buyer.ts | |
parent | b947609ff18f518ac36435083a97604b983a3081 (diff) | |
download | dexon-0x-contracts-0003666050c4991623cb36ec994d536e4703b4fe.tar.gz dexon-0x-contracts-0003666050c4991623cb36ec994d536e4703b4fe.tar.zst dexon-0x-contracts-0003666050c4991623cb36ec994d536e4703b4fe.zip |
make the slippage percentage customizable by integrator
Diffstat (limited to 'packages/asset-buyer/src/asset_buyer.ts')
-rw-r--r-- | packages/asset-buyer/src/asset_buyer.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/packages/asset-buyer/src/asset_buyer.ts b/packages/asset-buyer/src/asset_buyer.ts index 76b96427e..a2c0f37c9 100644 --- a/packages/asset-buyer/src/asset_buyer.ts +++ b/packages/asset-buyer/src/asset_buyer.ts @@ -13,6 +13,7 @@ import { AssetBuyerError, AssetBuyerOrdersAndFillableAmounts, BuyQuote, + BuyQuoteRequestOpts, OrderFetcher, OrderFetcherResponse, } from './types'; @@ -160,12 +161,13 @@ export class AssetBuyer { */ public async getBuyQuoteAsync( assetBuyAmount: BigNumber, - feePercentage: number = constants.DEFAULT_FEE_PERCENTAGE, - forceOrderRefresh: boolean = false, + options: Partial<BuyQuoteRequestOpts>, ): Promise<BuyQuote> { + const { feePercentage, forceOrderRefresh, slippagePercentage } = { ...options, ...constants.DEFAULT_BUY_QUOTE_REQUEST_OPTS }; assert.isBigNumber('assetBuyAmount', assetBuyAmount); assert.isNumber('feePercentage', feePercentage); assert.isBoolean('forceOrderRefresh', forceOrderRefresh); + assert.isNumber('feePercentage', slippagePercentage); // we should refresh if: // we do not have any orders OR // we are forced to OR @@ -185,13 +187,11 @@ export class AssetBuyer { ordersAndFillableAmounts = this ._currentOrdersAndFillableAmountsIfExists as AssetBuyerOrdersAndFillableAmounts; } - // TODO: optimization - // make the slippage percentage customizable by integrator const buyQuote = buyQuoteCalculator.calculate( ordersAndFillableAmounts, assetBuyAmount, feePercentage, - constants.DEFAULT_SLIPPAGE_PERCENTAGE, + slippagePercentage, ); return buyQuote; } |