-
Notifications
You must be signed in to change notification settings - Fork 61
Order Prototypes
Interactive Brokers offers more than 60 ordertypes to its clients.
There might be a reason for each and everyone. It' s virtually impossible to know all of them, and even for less common, but very usefull ordertypes, one must think carefully, which attributes are required.
**IB-Ruby** offers Order-Prototypes to simplify the ordering process.
-
Market,MarketIfTouched,MarketOnClose,MarketOnOpen,AtAuction -
Limit,Discretionary,Sweep2Fill,LimitIfTouched,LimitOnClose,LimitOnOpen -
SimpleStop,StopLimit,StopProtected,TrailingStop,TrailingStopLimit ForexLimitVolatilityCombo-
Pegged2Primary,Pegged2Market,Pegged2Stock,Pegged2Benchmark
For every OrderPrototpye, a handy command line autocomplete mechanism is provided.
> o = Limit.order
(...)
IB::ArgumentError (IB::Limit.order -> A necessary field is missing: action: --> {"B"=>:buy, "S"=>:sell, "T"=>:short, "X"=>:short_exempt})
> o = Limit.order action: :buy
(...)
IB::ArgumentError (IB::Limit.order -> A necessary field is missing: total_quantity: --> also aliased as :size)
> o = Limit.order action: :buy, size: 100
(...)
IB::ArgumentError (IB::Limit.order -> A necessary field is missing: limit_price: --> also aliased as :price)
> o = Limit.order action: :buy, size: 100, price: 15
=> #<IB::Order:0x0000000002fa5fd0 @attributes={:tif=>"GTC", :order_type=>"LMT", :side=>"B", :total_quantity=>100, :limit_price=>15, :created_at=>2018-03-22 08:50:57 +0000, :active_start_time=>"", :active_stop_time=>"", :algo_strategy=>"", :algo_id=>"", :auction_strategy=>0, :conditions=>[], :continuous_update=>0, :designated_location=>"", :display_size=>0, :discretionary_amount=>0, :etrade_only=>true, :exempt_code=>-1, :ext_operator=>"", :firm_quote_only=>true, :not_held=>false, :oca_type=>0, :open_close=>1, :opt_out_smart_routing=>false, :origin=>0, :outside_rth=>false, :parent_id=>0, :random_size=>false, :random_price=>false, :scale_auto_reset=>false, :scale_random_percent=>false, :scale_table=>"", :short_sale_slot=>0, :solicided=>false, :transmit=>true, :trigger_method=>0, :what_if=>false, :leg_prices=>[], :algo_params=>{}, :combo_params=>[], :soft_dollar_tier_params=>{"name"=>"", "val"=>"", "display_name"=>""}}, @order_states=[#<IB::OrderState:0x0000000002f9b670 @attributes={:status=>"New", :filled=>0, :remaining=>0, :price=>0, :average_price=>0, :created_at=>2018-03-22 08:50:57 +0000}>]>
Order-Prototypes provide a summary class-method
> print Limit.summary
A Limit order is an order to buy or sell at a specified price or better.
The Limit order ensures that if the order fills, it will not fill at a price less favorable than
your limit price, but it does not guarantee a fill.
It appears in the orderbook.
The :size attribute is primarily an alias for :total_quantity.
However, as in real live, size an be a negative number. If the size-attribute is specified without noticing any :action, the sign is interpreted as intention for the :action, ie.
> Limit.order( price: 34, size: 5) ==> IB:.Order attributes: action: :buy, total_quantity: 5, limit_price: 34
> Limit.order( price: 24, size: -5) ==> IB:.Order attributes: action: :sell, total_quantity: 5, limit_price: 34Order-Prototypes are just a wrapper for IB::Order.new. Other arguments(properties) can specified as usual
> C.place_order order, IB::Symbols::Stocks.wfc
09:00:50.168 Got message 4 (IB::Messages::Incoming::Alert)
I, [2018-03-22T09:00:50.168223 #1501] INFO -- : TWS Error 436: You must specify an allocation (either a single account, group, or profile).
> order = Limit.order action: :buy, size: 100, price: 15, account: 'DU167349', transmit: true
> C.place_order order, IB::Symbols::Stocks.wfc
> 09:03:23.600 Got message 5 (IB::Messages::Incoming::OpenOrder)
09:03:23.601 Got message 3 (IB::Messages::Incoming::OrderStatus)
I, [2018-03-22T09:03:23.601694 #1501] INFO -- : <OrderStatus: <OrderState: Submitted #13/1114784592 from 2000 filled 0.0/100.0 at 0.0/0.0 why_held >>
In the example-section Order-Prototypes are used to demonstrate the placement-processs
- Setup Ruby and Install the Program
- Console
- Gateway
- Watchlists
- Immutable Objects
- Flex Queries
- Messages
- Account
- Orders
- Contracts
- Case Studies