class Kucoin::Models::OrderBook
Constants
- INDEX_MAPPING
Attributes
asks[RW]
bids[RW]
symbol[RW]
timestamp[RW]
Public Class Methods
new(hash, type: :nil)
click to toggle source
# File lib/kucoin/models/order_book.rb, line 12 def initialize(hash, type: :nil) self.symbol = hash.fetch("symbol", nil) self.timestamp = ::Kucoin::Utilities::Parsing.epoch_to_time(hash.fetch("timestamp", nil), ms: true) if hash.has_key?("timestamp") && !hash.fetch("timestamp", nil).to_s.empty? self.bids = [] self.asks = [] process(hash.fetch("data", []), type: type) end
Public Instance Methods
process(data, type: nil)
click to toggle source
# File lib/kucoin/models/order_book.rb, line 22 def process(data, type: nil) pp data if data.is_a?(Hash) ["BUY", "SELL"].each do |type| process_orders(data.fetch(type.to_s, []), type: type) end elsif data.is_a?(Array) process_orders(data, type: type) end end
process_orders(orders, type: "BUY")
click to toggle source
# File lib/kucoin/models/order_book.rb, line 34 def process_orders(orders, type: "BUY") orders.each do |item| data = {} item.each_with_index do |value, index| data[INDEX_MAPPING[index]] = value end case type when "BUY" self.bids << data when "SELL" self.asks << data end end end