Skip to content

Instantly share code, notes, and snippets.

@longkt90
Last active September 20, 2017 16:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save longkt90/e02585f66374c6ced9dbb894ea7165f4 to your computer and use it in GitHub Desktop.
Save longkt90/e02585f66374c6ced9dbb894ea7165f4 to your computer and use it in GitHub Desktop.
Bittrex view your balances
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')
@longkt90
Copy link
Author

while :; do ruby ~/balances.rb; sleep 60; done to check once a minute

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment