Last active
November 30, 2021 19:02
-
-
Save rgaufman/70e7f871b59f83fd1ea791715eb86042 to your computer and use it in GitHub Desktop.
Shows your Binance balance in GBP and BTC every hour
This file contains hidden or 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
# frozen_string_literal: true | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem 'cryptocompare' | |
gem 'binance-ruby' | |
end | |
Binance::Api::Configuration.api_key = 'xxx' | |
Binance::Api::Configuration.secret_key = 'xxx' | |
def currency_convert(amount, from, to) | |
(Cryptocompare::Price.find(from, to)[from][to] * amount).round(6) | |
end | |
def get_balances | |
info = Binance::Api::info! | |
info[:balances].reject { |b| b[:free].to_i.zero? } | |
end | |
loop do | |
@btc = 0 | |
@gbp = 0 | |
balances = get_balances | |
results = get_balances.map do |b| | |
coin = b[:asset] | |
free = b[:free].to_i | |
btc = currency_convert(free, coin, 'BTC') | |
gbp = currency_convert(free, coin, 'GBP') | |
@btc += btc | |
@gbp += gbp | |
[coin, "#{btc} BTC", "£#{gbp}"] | |
end | |
if results.size > 1 | |
puts "#{Time.now} --- £#{@gbp} :: #{@btc} BTC :::: #{results}" | |
else | |
puts "#{Time.now} --- £#{@gbp} :: #{@btc} BTC :::: #{balances[0][:asset]}" | |
end | |
sleep 60 * 60 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment