Skip to content

Instantly share code, notes, and snippets.

@danielvlopes
Last active January 19, 2018 20:40
Show Gist options
  • Save danielvlopes/1d9aa98ddc4df715653f02ede7021f2d to your computer and use it in GitHub Desktop.
Save danielvlopes/1d9aa98ddc4df715653f02ede7021f2d to your computer and use it in GitHub Desktop.
require 'net/http'
require 'json'
def run(coins_goal, current_coins, current_price=nil)
if current_price.nil?
result = Net::HTTP.get(URI('https://api.gdax.com/products/ETH-USD/stats'))
current_price = JSON.parse(result)["open"].to_f
end
capital = current_coins * current_price.to_f
one_order_price = capital / coins_goal
two_orders_capital = capital / 2
two_order_price_one = one_order_price + 5
coins_from_first_order = two_orders_capital / two_order_price_one
coins_need_for_second_order = coins_goal - coins_from_first_order
two_order_price_two = two_orders_capital / coins_need_for_second_order
puts "-------------------------"
puts "For one order:"
puts "$ #{one_order_price}"
puts "-------------------------"
puts "For two orders:"
puts "$ #{two_order_price_one}"
puts "$ #{two_order_price_two}"
puts ""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment