lib/cryptum/order_book/generate.rb in cryptum-0.0.321 vs lib/cryptum/order_book/generate.rb in cryptum-0.0.322

- old
+ new

@@ -18,21 +18,14 @@ public_class_method def self.new_order_book(opts = {}) start_time = opts[:start_time] option_choice = opts[:option_choice] env = opts[:env] - order_book_file = "#{option_choice.repo_root}/order_books/#{option_choice.symbol}.ORDER_BOOK.json" + session_root = option_choice.session_root + symbol = option_choice.symbol + order_book_file = "#{session_root}/order_books/#{symbol}.ORDER_BOOK.json" - order_history_meta = [] - if File.exist?(order_book_file) - last_order_book = Cryptum::OrderBook.analyze( - order_book_file: order_book_file, - option_choice: option_choice - ) - order_history_meta = last_order_book[:order_history_meta] unless last_order_book[:order_history_meta].empty? - end - # Only need to retrieve a product list once / session. products = Cryptum::API.get_products( option_choice: option_choice, env: env ) @@ -41,20 +34,18 @@ end this_product = this_product_arr.last order_book = { path: order_book_file, - symbol: option_choice.symbol, + symbol: symbol, open_24h: 0.00, high_24h: 0.00, low_24h: 0.00, volume_24h: 0.00, ticker_price: 0.00, ticker_price_second_to_last: 0.00, ticker_price_third_to_last: 0.00, - highest_pie_in_sky_buy_percent: 0.00, - highest_pie_in_sky_sell_percent: 0.00, sequence: -1, this_product: this_product, portfolio: [], fiat_portfolio: [], fees: [], @@ -68,11 +59,11 @@ sell: 0, sell_start: '--', sell_end: '--' }, order_history: [], - order_history_meta: order_history_meta + order_history_meta: [] } # Order History Retention ---------------------------------------# # Instantiate Event History attr_accessible # Object to Keep Track of Everything as Events @@ -80,9 +71,16 @@ event_history = Cryptum::Event::History.new( option_choice: option_choice, start_time: start_time, order_book: order_book ) + + if File.exist?(order_book_file) + order_book = JSON.parse( + File.read(order_book_file), + symbolize_names: true + ) + end event_history.order_book = order_book event_history rescue StandardError => e