To use the features described, activate process-orders plugin
require 'ib-api' ib = IB::Connection.new ib.activate_plugin :process_orders
The :process_orders
plugin works on the account-based-ordermanagement
state of IB::Connection
.
It provides useful automations for the order-process
Workflow
ib = IB::Connection.new # initialize with default parameter
ib.activate_plugin :process_order, :order_prototypes, :symbols, :auto_adjust
u = ib.clients.first
c = IB::Symbols::Stocks.msft # Microsoft
o = Limit.order size: 100, price: 500
## preview
z= u.preview order: o, contract: c
puts z.map{|x,y| [x,y.to_f].join(': ')}.join("\n")
init_margin: 25038.99
maint_margin: 22752.2
equity_with_loan: 1033590.86
commission: 1.0
### place
u.place order: o, contract: c
o.to_human
=> "<Order: LMT GTC buy 100.0 @ 300 New /#40/ from 2000/DU4035275>"
## modify
o.limit_price = 350
u.modify order: o
o.to_human
=> "<Order: LMT GTC buy 100.0 @ 350 New /#41/ from 2000/DU4035275>"
## cancel
u.cancel order: o
u.orders.to_human
=>
["<Order: LMT GTC buy 100.0 @ 350.0 Submitted #41/1699720638 from 2000/DU4035275>",
"<Order: LMT GTC buy 100.0 @ 375.0 Cancelled #42/1699720639 from 2000/DU4035275>"]
Notice: The order-object is updated in the process. It’s OK to use the same order-object for each step. Then the history is kept in OrderState
-Objects. But never use the same order object for different users or different contracts.