diff options
author | Fabio Berger <me@fabioberger.com> | 2017-06-01 02:10:09 +0800 |
---|---|---|
committer | Fabio Berger <me@fabioberger.com> | 2017-06-01 02:10:09 +0800 |
commit | 52c3330487c9cb1e3fc78cda752717b684deca38 (patch) | |
tree | abd79bd20a038408b389ae8e3608a3e0b9593d49 /src/contract_wrappers | |
parent | 595656d3fc06a221274eb6bee89e7ba6e4e8ae61 (diff) | |
download | dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.tar dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.tar.gz dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.tar.bz2 dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.tar.lz dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.tar.xz dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.tar.zst dexon-sol-tools-52c3330487c9cb1e3fc78cda752717b684deca38.zip |
Implement getUnavailableTakerAmountAsync, getFilledTakerAmountAsync and getCanceledTakerAmountAsync
Diffstat (limited to 'src/contract_wrappers')
-rw-r--r-- | src/contract_wrappers/exchange_wrapper.ts | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/contract_wrappers/exchange_wrapper.ts b/src/contract_wrappers/exchange_wrapper.ts index 3f6eb0dab..74303cf82 100644 --- a/src/contract_wrappers/exchange_wrapper.ts +++ b/src/contract_wrappers/exchange_wrapper.ts @@ -1,4 +1,5 @@ import * as _ from 'lodash'; +import * as BigNumber from 'bignumber.js'; import {Web3Wrapper} from '../web3_wrapper'; import {ECSignature, ZeroExError, ExchangeContract} from '../types'; import {assert} from '../utils/assert'; @@ -37,6 +38,38 @@ export class ExchangeWrapper extends ContractWrapper { ); return isValidSignature; } + /** + * Returns the unavailable takerAmount of an order. Unavailable amount is defined as the total + * amount that has been filled or cancelled. The remaining takerAmount can be calculated by + * subtracting the unavailable amount from the total order takerAmount. + */ + public async getUnavailableTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> { + assert.isValidOrderHash('orderHashHex', orderHashHex); + + const exchangeContract = await this.getExchangeContractAsync(); + const unavailableAmountInBaseUnits = await exchangeContract.getUnavailableValueT.call(orderHashHex); + return unavailableAmountInBaseUnits; + } + /** + * Retrieve the takerAmount of an order that has already been filled. + */ + public async getFilledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> { + assert.isValidOrderHash('orderHashHex', orderHashHex); + + const exchangeContract = await this.getExchangeContractAsync(); + const fillAmountInBaseUnits = await exchangeContract.filled.call(orderHashHex); + return fillAmountInBaseUnits; + } + /** + * Retrieve the takerAmount of an order that has been cancelled. + */ + public async getCanceledTakerAmountAsync(orderHashHex: string): Promise<BigNumber.BigNumber> { + assert.isValidOrderHash('orderHashHex', orderHashHex); + + const exchangeContract = await this.getExchangeContractAsync(); + const cancelledAmountInBaseUnits = await exchangeContract.cancelled.call(orderHashHex); + return cancelledAmountInBaseUnits; + } private async getExchangeContractAsync(): Promise<ExchangeContract> { if (!_.isUndefined(this.exchangeContractIfExists)) { return this.exchangeContractIfExists; |