Sha256: be99348a48cbcc5f6cc0e4a9d7e05b24106c3230efe46d475b63443387b9383a

Contents?: true

Size: 1.83 KB

Versions: 7

Compression:

Stored size: 1.83 KB

Contents

class Iro::PriceItem
  include Mongoid::Document
  include Mongoid::Timestamps
  store_in collection: 'iro_price_items'

  ## PUT, CALL, STOCK
  field :putCall,         type: String
  field :symbol,          type: String
  field :ticker,          type: String

  field :bid,             type: Float
  field :bidSize,         type: Integer
  field :ask,             type: Float
  field :askSize,         type: Integer
  field :last,            type: Float

  field :openPrice,       type: Float
  field :lowPrice,        type: Float
  field :highPrice,       type: Float
  field :closePrice,      type: Float

  field :quoteTimeInLong, type: Integer
  field :timestamp,       type: Integer
  field :totalVolume,     type: Integer
  field :mark,            type: Float
  field :exchangeName,    type: String
  field :volatility,      type: Float

  def self.my_find props={}
    lookup = { '$lookup': {
      'from':         'iro_price_items',
      'localField':   'date',
      'foreignField': 'date',
      'pipeline': [
        { '$sort': { 'value': -1 } },
      ],
      'as':           'dates',
    } }
    lookup_merge = { '$replaceRoot': {
      'newRoot': { '$mergeObjects': [
        { '$arrayElemAt': [ "$dates", 0 ] }, "$$ROOT"
      ] }
    } }


    match = { '$match': {
      'date': {
        '$gte': props[:begin_on],
        '$lte': props[:end_on],
      }
    } }

    group = { '$group': {
      '_id': "$date",
      'my_doc': { '$first': "$$ROOT" }
    } }

    outs = Iro::Date.collection.aggregate([
      match,

      lookup,
      lookup_merge,

      group,
      { '$replaceRoot': { 'newRoot': "$my_doc" } },
      # { '$replaceRoot': { 'newRoot': "$my_doc" } },


      { '$project': { '_id': 0, 'date': 1, 'value': 1 } },
      { '$sort': { 'date': 1 } },
    ])

    puts! 'result'
    pp outs.to_a
    # puts! outs.to_a, 'result'
  end

end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
iron_warbler-2.0.7.26 app/models/iro/price_item.rb
iron_warbler-2.0.7.25 app/models/iro/price_item.rb
iron_warbler-2.0.7.24 app/models/iro/price_item.rb
iron_warbler-2.0.7.23 app/models/iro/price_item.rb
iron_warbler-2.0.7.22 app/models/iro/price_item.rb
iron_warbler-2.0.7.21 app/models/iro/price_item.rb
iron_warbler-2.0.7.20 app/models/iro/price_item.rb