Module: RbtcArbitrage::TraderHelpers::Notifier

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

Instance Method Summary collapse

Instance Method Details

#notificationObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rbtc_arbitrage/trader/notifier.rb', line 33

def notification
  lower_ex = @buy_client.exchange.to_s.capitalize
  higher_ex = @sell_client.exchange.to_s.capitalize
  <<-eos
  Update from your friendly rbtc_arbitrage trader:

  -------------------

  #{lower_ex}: $#{buyer[:price].round(2)}
  #{higher_ex}: $#{seller[:price].round(2)}
  buying #{@options[:volume]} btc from #{lower_ex} for $#{@paid.round(2)}
  selling #{@options[:volume]} btc on #{higher_ex} for $#{@received.round(2)}
  profit: $#{(@received - @paid).round(2)} (#{@percent.round(2)}%)

  -------------------

  options:

  #{options.reject{|k,v| v.is_a?(Logger)}.collect{|k,v| "#{k}: #{v.to_s}"}.join(" | ")}

  -------------------

  https://github.com/hstove/rbtc_arbitrage
  eos
end

#notifyObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/rbtc_arbitrage/trader/notifier.rb', line 4

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'],
  })
end

#setup_ponyObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/rbtc_arbitrage/trader/notifier.rb', line 16

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