Class: Devilicious::Arbitrer
- Inherits:
-
Object
- Object
- Devilicious::Arbitrer
- Defined in:
- lib/devilicious/arbitrer.rb
Instance Method Summary collapse
Instance Method Details
#markets ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/devilicious/arbitrer.rb', line 3 def markets @markets ||= [ Market::Kraken, Market::BitcoinDe, Market::BtcE, Market::HitBtc, Market::Bitcurex, Market::Bitstamp, Market::BitNz, Market::AnxBtc, ].map { |market| market.new } end |
#run! ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/devilicious/arbitrer.rb', line 18 def run! @market_queue = [] spawn_observers! loop do sleep 1 while @market_queue.empty? market_1 = @market_queue.shift markets.each do |market_2| next if market_1 == market_2 if market_1.order_book.nil? || market_2.order_book.nil? Log.debug "Order book(s) not available, skipping" next end # dup everything to avoid race conditions while calculating opportunities order_book_1 = market_1.order_book.dup order_book_2 = market_2.order_book.dup order_book_1.market = market_1.dup order_book_2.market = market_2.dup check_for_opportunity(order_book_1, order_book_2) check_for_opportunity(order_book_2, order_book_1) end end end |