Module: RbtcArbitrage::TraderHelpers::Notifier

Included in:
RbtcArbitrage::Trader
Defined in:
lib/rbtc_arbitrage/trader/notifier.rb

Instance Method Summary collapse

Instance Method Details

#notificationObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/rbtc_arbitrage/trader/notifier.rb', line 42

def notification
  lower_ex = @buy_client.exchange.to_s.capitalize
  higher_ex = @sell_client.exchange.to_s.capitalize
  "  Update from your friendly rbtc_arbitrage trader:\n\n  -------------------\n\n  \#{lower_ex}: $\#{buyer[:price].round(2)}\n  \#{higher_ex}: $\#{seller[:price].round(2)}\n  buying \#{@options[:volume]} btc from \#{lower_ex} for $\#{@paid.round(2)}\n  selling \#{@options[:volume]} btc on \#{higher_ex} for $\#{@received.round(2)}\n  profit: $\#{(@received - @paid).round(2)} (\#{@percent.round(2)}%)\n\n  -------------------\n\n  options:\n\n  \#{options.reject{|k,v| v.is_a?(Logger)}.collect{|k,v| \"\#{k}: \#{v.to_s}\"}.join(\" | \")}\n\n  -------------------\n\n  https://github.com/hstove/rbtc_arbitrage\n  eos\nend\n"

#notifyObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rbtc_arbitrage/trader/notifier.rb', line 4

def notify
  return false unless options[:notify]
  return false unless @percent > options[:cutoff]

  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

#setup_ponyObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/rbtc_arbitrage/trader/notifier.rb', line 25

def setup_pony
  Pony.options = {
    from: ENV['FROM_EMAIL'] || "[email protected]",
    subject: "rbtc_arbitrage notification",
    via: :smtp,
    via_options: {
      address: 'smtp.sendgrid.net',
      port: '587',
      domain: 'heroku.com',
      user_name: ENV['SENDGRID_USERNAME'],
      password: ENV['SENDGRID_PASSWORD'],
      authentication: :plain,
      enable_starttls_auto: true
    }
  }
end