Last active
September 20, 2017 16:28
-
-
Save longkt90/e02585f66374c6ced9dbb894ea7165f4 to your computer and use it in GitHub Desktop.
Bittrex view your balances
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bittrex' # gem install bittrex | |
require 'terminal-notifier' # gem install terminal-notifier | |
require 'json' | |
Bittrex.config do |c| | |
c.key = 'readonly-key' | |
c.secret = 'readonly-secret' | |
end | |
usdt = Bittrex::Quote.current("USDT-BTC").bid | |
sum = Bittrex.client.get('account/getbalances').delete_if {|e| e['Balance'] == 0.0 }.inject(0) do |sum, account| | |
account.delete('CryptoAddress') | |
account['EstValue'] = if account['Currency'] == "BTC" | |
account['Balance'] | |
elsif account['Currency'] == "USDT" | |
account['Balance'] / usdt | |
else | |
quote = Bittrex::Quote.current("BTC-#{account['Currency']}") | |
account['LastPrice'] = sprintf('%.8f', quote.last) | |
quote.bid * account['Balance'] | |
end | |
account['EstValueUSDT'] = account['EstValue'] * usdt | |
if account['EstValueUSDT'] < 1.0 | |
sum += 0 | |
else | |
puts account | |
sum += account['EstValue'] | |
end | |
end | |
print message = "Estimate value: #{format('%.8f', sum)} BTC (#{sum * usdt} USDT)\n" | |
# TerminalNotifier.notify(message, :sound => 'Glass', timeout: 5) | |
TerminalNotifier.notify(message, sound: 'Glass', title: 'Bittrex Balance') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
while :; do ruby ~/balances.rb; sleep 60; done
to check once a minute