Class: Quant::Security
- Inherits:
-
Object
- Object
- Quant::Security
- Defined in:
- lib/quant/security.rb
Overview
A Security is a representation of a financial instrument such as a stock, option, future, or currency. It is used to represent the instrument that is being traded, analyzed, or managed.
Instance Attribute Summary collapse
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#meta ⇒ Object
readonly
Returns the value of attribute meta.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#security_class ⇒ Object
readonly
Returns the value of attribute security_class.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#updated_at ⇒ Object
readonly
Returns the value of attribute updated_at.
Instance Method Summary collapse
- #active? ⇒ Boolean
-
#initialize(symbol:, name: nil, id: nil, active: true, tradeable: true, exchange: nil, source: nil, security_class: nil, created_at: Quant.current_time, updated_at: Quant.current_time, meta: {}) ⇒ Security
constructor
A new instance of Security.
- #to_h(full: false) ⇒ Object
- #to_json(*args, full: false) ⇒ Object
- #tradeable? ⇒ Boolean
Constructor Details
#initialize(symbol:, name: nil, id: nil, active: true, tradeable: true, exchange: nil, source: nil, security_class: nil, created_at: Quant.current_time, updated_at: Quant.current_time, meta: {}) ⇒ Security
Returns a new instance of Security.
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 |
# File 'lib/quant/security.rb', line 21 def initialize( symbol:, name: nil, id: nil, active: true, tradeable: true, exchange: nil, source: nil, security_class: nil, created_at: Quant.current_time, updated_at: Quant.current_time, meta: {} ) raise ArgumentError, "symbol is required" unless symbol @symbol = symbol.to_s.upcase @name = name @id = id @tradeable = tradeable @active = active @exchange = exchange @source = source @security_class = SecurityClass.new(security_class) @created_at = created_at @updated_at = updated_at @meta = end |
Instance Attribute Details
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def created_at @created_at end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def exchange @exchange end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def id @id end |
#meta ⇒ Object (readonly)
Returns the value of attribute meta.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def @meta end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def name @name end |
#security_class ⇒ Object (readonly)
Returns the value of attribute security_class.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def security_class @security_class end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def source @source end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def symbol @symbol end |
#updated_at ⇒ Object (readonly)
Returns the value of attribute updated_at.
19 20 21 |
# File 'lib/quant/security.rb', line 19 def updated_at @updated_at end |
Instance Method Details
#active? ⇒ Boolean
49 50 51 |
# File 'lib/quant/security.rb', line 49 def active? !!@active end |
#to_h(full: false) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/quant/security.rb', line 63 def to_h(full: false) return { "s" => symbol } unless full { "s" => symbol, "n" => name, "id" => id, "t" => tradeable?, "a" => active?, "x" => exchange, "sc" => security_class.to_s, "src" => source.to_s } end |
#to_json(*args, full: false) ⇒ Object
76 77 78 |
# File 'lib/quant/security.rb', line 76 def to_json(*args, full: false) Oj.dump(to_h(full: full), *args) end |
#tradeable? ⇒ Boolean
53 54 55 |
# File 'lib/quant/security.rb', line 53 def tradeable? !!@tradeable end |