lib/rbtc_arbitrage/trader/notifier.rb in rbtc_arbitrage-2.4.0 vs lib/rbtc_arbitrage/trader/notifier.rb in rbtc_arbitrage-2.4.1

- old
+ new

@@ -2,16 +2,25 @@ module TraderHelpers module Notifier def notify return false unless options[:notify] return false unless @percent > options[:cutoff] - setup_pony - options[:logger].info "Sending email to #{ENV['SENDGRID_EMAIL']}" - Pony.mail({ - body: notification, - to: ENV['SENDGRID_EMAIL'], - }) + if (sendgrid_email = ENV['SENDGRID_EMAIL']).present? + setup_pony + options[:logger].info "Sending email to #{sendgrid_email}" + Pony.mail({ + body: notification, + to: sendgrid_email, + }) + end + + if (stathat_api_key = ENV['STATHAT_API_KEY']).present? + options[:logger].info "Notifying #{ stathat_api_key } via stathat" + + StatHat::SyncAPI.ez_post_value("#{@buy_client.exchange}_to_#{@sell_client.exchange}_percent", stathat_api_key, @percent) + StatHat::SyncAPI.ez_post_value("#{@buy_client.exchange}_to_#{@sell_client.exchange}_profit", stathat_api_key, @received - @paid) + end end def setup_pony Pony.options = { from: ENV['FROM_EMAIL'] || "info@example.org", \ No newline at end of file