Skip to content

Commit

Permalink
Add exmo
Browse files Browse the repository at this point in the history
  • Loading branch information
FYYKX committed Aug 2, 2018
1 parent fcb7d98 commit c737753
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
20 changes: 18 additions & 2 deletions public/javascripts/exchange.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ app.controller('balancesController', function ($scope, $http, $rootScope, $q) {
$scope.total_binance = 0;
$scope.total_yobit = 0;
$scope.total_hitbtc = 0;
$scope.total_exmo = 0;

$scope.total_ico = 0;

Expand Down Expand Up @@ -43,6 +44,9 @@ app.controller('balancesController', function ($scope, $http, $rootScope, $q) {
$scope.$watch('total_hitbtc', function () {
$scope.total_exchange += $scope.total_hitbtc;
});
$scope.$watch('total_exmo', function () {
$scope.total_exchange += $scope.total_exmo;
});

let quoine = $http.get('balances/quoinex');
let qryptos = $http.get('balances/qryptos');
Expand All @@ -51,6 +55,7 @@ app.controller('balancesController', function ($scope, $http, $rootScope, $q) {
let binance = $http.get('balances/binance');
let yobit = $http.get('balances/yobit');
let hitbtc = $http.get('balances/hitbtc');
let exmo = $http.get('balances/exmo');

let ico = $http.get('balances/ico');

Expand All @@ -65,6 +70,7 @@ app.controller('balancesController', function ($scope, $http, $rootScope, $q) {
binance,
yobit,
hitbtc,
exmo,
ico,
cmc,
na
Expand Down Expand Up @@ -120,6 +126,15 @@ app.controller('balancesController', function ($scope, $http, $rootScope, $q) {
}
});

$scope.balance_exmo = Object.keys(r.exmo.data.balances)
.map(item => {
return {
currency: item.toUpperCase(),
balance: parseFloat(r.exmo.data.balances[item]) + parseFloat(r.exmo.data.reserved[item])
}
})
.filter(item => item.balance > 0);

$scope.balance_ico = r.ico.data;
$scope.cost_ico = $scope.ico * r.cmc.data.ETH.price;
for (var key in r.na.data) {
Expand Down Expand Up @@ -166,8 +181,9 @@ app.controller('balancesController', function ($scope, $http, $rootScope, $q) {
parseFloat($scope.balance_quoinex.find(i => i.currency == "USD").balance) +
parseFloat($scope.balance_bitfinex.find(i => i.currency == "USD").balance) +
parseFloat($scope.balance_poloniex.find(i => i.currency == "USDT").balance) +
parseFloat($scope.balance_binance.find(i => i.currency == "USDT").balance) +
parseFloat($scope.balance_binance.find(i => i.currency == "USDT").balance) +
parseFloat($scope.balance_yobit.find(i => i.currency == "USD").balance) +
parseFloat($scope.balance_hitbtc.find(i => i.currency == "USD").balance);
parseFloat($scope.balance_hitbtc.find(i => i.currency == "USD").balance) +
parseFloat($scope.balance_exmo.find(i => i.currency == "USD").balance);
});
});
45 changes: 45 additions & 0 deletions routes/exchange/exmo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
var request = require('request');
var crypto = require('crypto');
var formurlencoded = require('form-urlencoded');

var config = require('../../config');

var
api_key = config.exmo.api_key,
api_secret = config.exmo.api_secret,
baseRequest = request.defaults({
headers: {
'Key': api_key
},
baseUrl: 'https://api.exmo.com/v1/',
json: true
});

function getOptions(payload) {
payload.nonce = parseInt(Date.now() / 1000);
var data = formurlencoded(payload);
var signature = crypto.createHmac('sha512', api_secret).update(data).digest('hex');
return {
url: "/" + payload.method,
headers: {
'Sign': signature
},
form: payload
};
}

var balances = function (callback) {
var payload = {
'method': 'user_info'
};

var options = getOptions(payload);

baseRequest.post(options, function (error, response, body) {
callback(body);
});
};

module.exports = {
balances: balances
};
42 changes: 40 additions & 2 deletions views/exchange.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,15 @@
</h3>
<h3>{{total_hitbtc / (total_exchange + total_ico + total_billy) * 100 | number:2}}%</h3>
</div>
<div class="col-md-2 col-xs-4">
<h3>
<span class="label exmo">exmo</span>
</h3>
<h3>
<span class="label label-info">{{total_exmo | number:2}}</span>
</h3>
<h3>{{total_exmo / (total_exchange + total_ico + total_billy) * 100 | number:2}}%</h3>
</div>
<div class="col-md-2 col-xs-4">
<h3>
<span class="label ico">ico</span>
Expand Down Expand Up @@ -367,7 +376,36 @@
</tr>
<tr class="info">
<td colspan="2">Total</td>
<td>{{total_yobit | number:2}}</td>
<td>{{total_hitbtc | number:2}}</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
</div>
<div class="col-md-6">
<h3 class="label exmo">exmo</h3>
<table class="table">
<thead>
<tr>
<th>Currency</th>
<th>Balance</th>
<th>USD</th>
<th>Price</th>
<th>Change 24h</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="balance in balance_exmo">
<td>{{balance.currency}}</td>
<td>{{balance.balance}}</td>
<td ng-init="item = balance.balance * ticker[balance.currency].price; $parent.total_exmo = $parent.total_exmo + item">{{item | number:2}}</td>
<td>{{ticker[balance.currency].price}}</td>
<td ng-class="ticker[balance.currency].percent_change_24h > 0 ? 'success' : 'danger'">{{ticker[balance.currency].percent_change_24h}}%</td>
</tr>
<tr class="info">
<td colspan="2">Total</td>
<td>{{total_exmo | number:2}}</td>
<td></td>
<td></td>
</tr>
Expand Down Expand Up @@ -414,4 +452,4 @@
<script type="text/javascript" src="/javascripts/exchange.js"></script>
</body>

</html>
</html>

0 comments on commit c737753

Please sign in to comment.