Skip to content

Commit

Permalink
Merge pull request #38 from xenohunter/master
Browse files Browse the repository at this point in the history
Added getTradableBalance method
  • Loading branch information
Phil Filippak authored May 29, 2017
2 parents 9fc5cfd + 6b73340 commit 9b1d1ee
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 17 deletions.
33 changes: 25 additions & 8 deletions distr/wavesplatform-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -2844,30 +2844,30 @@ Decimal.config({toExpNeg: -(Currency.WAVES.precision + 1)});

function WavesMatcherApiService (rest, utilityService, cryptoService) {
var apiRoot = rest.all('matcher');
var orderBookRoot = apiRoot.all('orderbook');
var orderbookRoot = apiRoot.all('orderbook');

this.createOrder = function (signedOrderRequest) {
return orderBookRoot.post(signedOrderRequest);
return orderbookRoot.post(signedOrderRequest);
};

this.cancelOrder = function (firstAssetId, secondAssetId, signedCancelRequest) {
return orderBookRoot
return orderbookRoot
.all(normalizeId(firstAssetId))
.all(normalizeId(secondAssetId))
.all('cancel')
.post(signedCancelRequest);
};

this.deleteOrder = function (firstAssetId, secondAssetId, signedCancelRequest) {
return orderBookRoot
return orderbookRoot
.all(normalizeId(firstAssetId))
.all(normalizeId(secondAssetId))
.all('delete')
.post(signedCancelRequest);
};

this.orderStatus = function (firstAssetId, secondAssetId, orderId) {
return orderBookRoot
return orderbookRoot
.all(normalizeId(firstAssetId))
.all(normalizeId(secondAssetId))
.get(orderId);
Expand All @@ -2878,7 +2878,7 @@ Decimal.config({toExpNeg: -(Currency.WAVES.precision + 1)});
};

this.loadOrderbook = function (firstAssetId, secondAssetId) {
return orderBookRoot.all(normalizeId(firstAssetId)).get(normalizeId(secondAssetId))
return orderbookRoot.all(normalizeId(firstAssetId)).get(normalizeId(secondAssetId))
.then(function (response) {
response.pair.amountAsset = denormalizeId(response.pair.amountAsset);
response.pair.priceAsset = denormalizeId(response.pair.priceAsset);
Expand All @@ -2903,7 +2903,7 @@ Decimal.config({toExpNeg: -(Currency.WAVES.precision + 1)});
var timestamp = Date.now(),
signature = buildLoadUserOrdersSignature(timestamp, sender);

return orderBookRoot
return orderbookRoot
.all(normalizeId(amountAsset))
.all(normalizeId(priceAsset))
.all('publicKey')
Expand All @@ -2914,7 +2914,7 @@ Decimal.config({toExpNeg: -(Currency.WAVES.precision + 1)});
};

this.loadAllMarkets = function () {
return orderBookRoot.get('').then(function (response) {
return orderbookRoot.get('').then(function (response) {
var pairs = [];
_.forEach(response.markets, function (market) {
var id = normalizeId(market.amountAsset) + '/' + normalizeId(market.priceAsset);
Expand All @@ -2940,6 +2940,23 @@ Decimal.config({toExpNeg: -(Currency.WAVES.precision + 1)});
return pairs;
});
};

this.getTradableBalance = function (amountAsset, priceAsset, address) {
var normAmountAsset = normalizeId(amountAsset),
normPriceAsset = normalizeId(priceAsset);

return orderbookRoot
.all(normAmountAsset)
.all(normPriceAsset)
.all('tradableBalance')
.get(address)
.then(function (response) {
var result = {};
result[denormalizeId(normAmountAsset)] = response[normAmountAsset];
result[denormalizeId(normPriceAsset)] = response[normPriceAsset];
return result;
});
};
}

WavesMatcherApiService.$inject = ['MatcherRestangular', 'utilityService', 'cryptoService'];
Expand Down
Loading

0 comments on commit 9b1d1ee

Please sign in to comment.