Last active
January 19, 2018 20:40
-
-
Save danielvlopes/1d9aa98ddc4df715653f02ede7021f2d to your computer and use it in GitHub Desktop.
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
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