Module: IB::OrderPrototype
- Included in:
- AtAuction, Combo, Discretionary, ForexLimit, Limit, LimitIfTouched, LimitOnClose, LimitOnOpen, Market, MarketIfTouched, MarketOnClose, MarketOnOpen, Pegged2Benchmark, Pegged2Market, Pegged2Primary, Pegged2Stock, SimpleStop, StopLimit, StopProtected, Sweep2Fill, TrailingStop, TrailingStopLimit, Volatility
- Defined in:
- lib/ib/order-prototypes.rb,
lib/ib/order_prototypes/abstract.rb
Instance Method Summary collapse
- #aliases ⇒ Object
- #alternative_parameters ⇒ Object
- #defaults ⇒ Object
- #optional ⇒ Object
- #order(**fields) ⇒ Object
- #parameters ⇒ Object
- #requirements ⇒ Object
Instance Method Details
#aliases ⇒ Object
88 89 90 |
# File 'lib/ib/order-prototypes.rb', line 88 def aliases { total_quantity: :size } end |
#alternative_parameters ⇒ Object
73 74 75 |
# File 'lib/ib/order-prototypes.rb', line 73 def alternative_parameters {} end |
#defaults ⇒ Object
80 81 82 |
# File 'lib/ib/order-prototypes.rb', line 80 def defaults { tif: :good_till_cancelled } end |
#optional ⇒ Object
84 85 86 |
# File 'lib/ib/order-prototypes.rb', line 84 def optional { account: 'Account(number) to trade on' } end |
#order(**fields) ⇒ Object
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 |
# File 'lib/ib/order-prototypes.rb', line 43 def order **fields # special treatment of size: positive numbers --> buy order, negative: sell if fields[:size].present? && fields[:action].blank? error "Size = 0 is not possible" if fields[:size].zero? fields[:action] = fields[:size] >0 ? :buy : :sell fields[:size] = fields[:size].abs end # change aliases to the original. We are modifying the fields-hash. fields.keys.each{|x| fields[aliases.key(x)] = fields.delete(x) if aliases.has_value?(x)} # inlcude defaults (arguments override defaults) the_arguments = defaults.merge fields # check if requirements are fullfilled necessary = requirements.keys.detect{|y| the_arguments[y].nil?} if necessary.present? msg =self.name + ".order -> A necessary field is missing: #{necessary}: --> #{requirements[necessary]}" error msg, :args, nil end if alternative_parameters.present? unless ( alternative_parameters.keys & the_arguments.keys ).size == 1 msg =self.name + ".order -> One of the alternative fields needs to be specified: \n\t:" + "#{alternative_parameters.map{|x| x.join ' => '}.join(" or \n\t:")}" error msg, :args, nil end end # initialise order with given attributes IB::Order.new **the_arguments end |
#parameters ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/ib/order-prototypes.rb', line 92 def parameters the_output = ->(var){ var.map{|x| x.join(" --> ") }.join("\n\t: ")} "Required : " + the_output[requirements] + "\n --------------- \n" + "Optional : " + the_output[optional] + "\n --------------- \n" end |
#requirements ⇒ Object
76 77 78 |
# File 'lib/ib/order-prototypes.rb', line 76 def requirements { action: IB::VALUES[:side], total_quantity: 'also aliased as :size' } end |