From efde8b079959c4734deb926e221422d9ab42b566 Mon Sep 17 00:00:00 2001 From: Eric Dahl Date: Tue, 10 Jul 2018 10:45:30 -0500 Subject: [PATCH 1/2] Initial trailing buy attempt --- inc/trailing_buy.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 inc/trailing_buy.rb diff --git a/inc/trailing_buy.rb b/inc/trailing_buy.rb new file mode 100644 index 0000000..dd36e9c --- /dev/null +++ b/inc/trailing_buy.rb @@ -0,0 +1,30 @@ + +# frozen_string_literal: true + +def trailing_buy(_percent_of_portfolio, pair = 'LTC-USD') + redis = Redis.new + + last_spot = redis.get("spot_#{pair.split('-')[0]}_#{pair.split('-')[1]}").to_f + # rest_api = Coinbase::Exchange::Client.new(ENV['GDAX_TOKEN'], ENV['GDAX_SECRET'], ENV['GDAX_PW'], product_id: pair) + + # color = :light_yellow + # bg_color = :default + + market_low = last_spot + spot_array = [] + + loop do + sleep 1.0 / 100 + spot = redis.get("spot_#{pair.split('-')[0]}_#{pair.split('-')[1]}").to_f + spot_array << spot + spot_array = spot_array.last(500) + spot_sma = spot_array.sma.round(5) + + if spot_sma < market_low + market_low = spot + # t_stop_price = spot - (spot * t_stop / 100) + end + puts "#{market_low} | #{spot} | #{spot_sma}" + end + # order_size = (bal(pair) * percent_of_portfolio) / redis.get("spot_#{pair.split('-')[0]}_#{pair.split('-')[1]}").to_f +end From 0932ccff276cc6051933a67f8b5636adc40d43c9 Mon Sep 17 00:00:00 2001 From: Eric Dahl Date: Thu, 30 Aug 2018 12:23:22 -0500 Subject: [PATCH 2/2] todo --- inc/trailing_buy.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/inc/trailing_buy.rb b/inc/trailing_buy.rb index dd36e9c..4e452f4 100644 --- a/inc/trailing_buy.rb +++ b/inc/trailing_buy.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true +# @todo Get trailing buy working +# @body This one is gonna be sweet + + def trailing_buy(_percent_of_portfolio, pair = 'LTC-USD') redis = Redis.new