Module: Cryptum::OrderBook::Generate
- Defined in:
- lib/cryptum/order_book/generate.rb
Class Method Summary collapse
-
.help ⇒ Object
Display Usage for this Module.
-
.new_order_book(opts = {}) ⇒ Object
- Supported Method Parameters
-
Cryptum::OrderBook.generate( symbol: ‘required - target symbol (e.g. btc-usd)’, this_product: ‘required - this_product’, ).
Class Method Details
.help ⇒ Object
Display Usage for this Module
104 105 106 107 108 109 110 111 |
# File 'lib/cryptum/order_book/generate.rb', line 104 public_class_method def self.help puts "USAGE: order_book = #{self}.new_order_book( symbol: 'required - target symbol (e.g. btc-usd)', this_product: 'required - this_product' ) " end |
.new_order_book(opts = {}) ⇒ Object
- Supported Method Parameters
-
Cryptum::OrderBook.generate(
symbol: 'required - target symbol (e.g. btc-usd)', this_product: 'required - this_product',
)
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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/cryptum/order_book/generate.rb', line 18 public_class_method def self.new_order_book(opts = {}) start_time = opts[:start_time] option_choice = opts[:option_choice] env = opts[:env] session_root = option_choice.session_root symbol = option_choice.symbol order_book_file = "#{session_root}/order_books/#{symbol}.ORDER_BOOK.json" # Only need to retrieve a product list once / session. products = Cryptum::API.get_products( option_choice: option_choice, env: env ) this_product_arr = products.select do |product| product if product[:id] == option_choice.symbol.to_s.gsub('_', '-').upcase end this_product = this_product_arr.last order_book = { path: order_book_file, 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, sequence: -1, this_product: this_product, portfolio: [], fiat_portfolio: [], fees: [], order_plan: [], last_trend_reset: Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z'), last_order_exec: Time.now.strftime('%Y-%m-%d %H:%M:%S.%N%z'), market_trend: { buy: 0, buy_start: '--', buy_end: '--', sell: 0, sell_start: '--', sell_end: '--' }, order_history: [], order_history_meta: [] } # Order History Retention ---------------------------------------# # Instantiate Event History attr_accessible # Object to Keep Track of Everything as Events # are Parsed. 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 if option_choice.reset_session_countdown event_history.order_book[:order_plan] = [] event_history.order_book[:market_trend][:buy] = 0 event_history.order_book[:market_trend][:sell] = 0 event_history.order_book[:last_trend_reset] = Time.now.strftime( '%Y-%m-%d %H:%M:%S.%N%z' ) event_history.order_book[:last_order_exec] = Time.now.strftime( '%Y-%m-%d %H:%M:%S.%N%z' ) end event_history rescue StandardError => e raise e end |