Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display Total Account Value #246

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lendingbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
while True:
try:
Data.update_conversion_rates(output_currency, json_output_enabled)
Data.update_total_account_balance()
Lending.transfer_balances()
Lending.cancel_all()
Lending.lend_all()
Expand Down
9 changes: 9 additions & 0 deletions modules/Data.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ def get_lending_currencies():
return currencies


def update_total_account_balance():
balance_response = api.return_complete_balances('all')
balance = 0
for cur in balance_response:
balance += float(balance_response[cur]['btcValue'])
# added to BTC as value is BTC
log.updateStatusValue('BTC', 'total_account_balance', balance)


def truncate(f, n):
"""Truncates/pads a float f to n decimal places without rounding"""
# From https://stackoverflow.com/questions/783897/truncating-floats-in-python
Expand Down
10 changes: 10 additions & 0 deletions modules/Poloniex.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,16 @@ def transfer_balance(self, currency, amount, from_account, to_account):
def return_balances(self):
return self.api_query('returnBalances')


# Returns all of your balances, including available balance, balance on orders,
# and the estimated BTC value of your balance.
# By default, this call is limited to your exchange account;
# set the "account" POST parameter to "all" to include your margin and lending accounts. Sample output:
def return_complete_balances(self, account):
balances = self.api_query('returnCompleteBalances', {"account": account})
return balances


def return_available_account_balances(self, account):
balances = self.api_query('returnAvailableAccountBalances', {"account": account})
if isinstance(balances, list): # silly api wrapper, empty dict returns a list, which breaks the code later.
Expand Down
31 changes: 24 additions & 7 deletions www/lendingbot.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function updateRawValues(rawData){
table.innerHTML = "";
var currencies = Object.keys(rawData);
var totalBTCEarnings = {};
var totalAccountValueBTC = NaN;
for (var keyIndex = 0; keyIndex < currencies.length; ++keyIndex)
{
var currency = currencies[keyIndex];
Expand All @@ -82,6 +83,7 @@ function updateRawValues(rawData){
// no bids for BTC provided by poloniex
// this is added so BTC can be handled like other coins for conversions
highestBidBTC = 1;
totalAccountValueBTC = parseFloat(rawData[currency]['total_account_balance']);
}
var couple = rawData[currency]['couple'];

Expand Down Expand Up @@ -187,19 +189,34 @@ function updateRawValues(rawData){
var thead = table.createTHead();

// show account summary
if (currencies.length > 1 || summaryCoin != earningsOutputCoin) {
earnings = '';
timespans.forEach(function(timespan) {
earnings += timespan.formatEarnings( summaryCoin, totalBTCEarnings[timespan.name] * summaryCoinRate);
});
earnings = '';
timespans.forEach(function(timespan) {
earnings += timespan.formatEarnings( summaryCoin, totalBTCEarnings[timespan.name] * summaryCoinRate);
});
var row = thead.insertRow(0);
var cell = row.appendChild(document.createElement("th"));
cell.innerHTML = "Account<br/>Estimated<br/>Earnings";
cell.style.verticalAlign = "text-top";
cell = row.appendChild(document.createElement("th"));
cell.style.verticalAlign = "text-top";
cell.setAttribute("colspan", 2);
cell.innerHTML = earnings;

if( !isNaN(totalAccountValueBTC)) {
// show account total balance
var row = thead.insertRow(0);
var cell = row.appendChild(document.createElement("th"));
cell.innerHTML = "Account<br/>Estimated<br/>Earnings";
cell.innerHTML = "Account Balance";
cell.style.verticalAlign = "text-top";
cell = row.appendChild(document.createElement("th"));
cell.style.verticalAlign = "text-top";
cell.setAttribute("colspan", 2);
cell.innerHTML = earnings;
cell.innerHTML = "<div class='inlinediv' style='padding-left:0px'>"+ prettyFloat(displayUnit.multiplier * totalAccountValueBTC, 2) + " " + displayUnit.name + "</div>"
if(summaryCoin != 'BTC') {
cell.innerHTML += "<div class='inlinediv' style='padding-right:0px'>"+ prettyFloat(summaryCoinRate * totalAccountValueBTC, 2) + " " + summaryCoin + "</div>"
}
}

}

function handleLocalFile(file) {
Expand Down