11# ib-api
22Ruby interface to Interactive Brokers' TWS API
33
4- Reimplementation of the basic functions of ib-ruby
4+ Reimplementation of ib-ruby
5+
6+ ---
7+ __ STATUS: Gem-Release is still pending
58
69---
710
@@ -13,9 +16,7 @@ Try the V10 branch (TWS V 10.19 and above)
1316__ Documentation: [ https://ib-ruby.github.io/ib-doc/ ] ( https://ib-ruby.github.io/ib-doc/ ) __ (_ work in progress_ )
1417
1518----
16- ` ib-ruby ` offers a modular access to the TWS-API-Interface of Interactive Brokers.
17-
18- ` ib-api ` provides a simple interface to low-level TWS API-calls.
19+ ` ib-api ` offers a modular access to the TWS-API-Interface of Interactive Brokers.
1920
2021----
2122
@@ -25,7 +26,7 @@ Install in the usual way
2526$ gem install ib-api
2627```
2728
28- In its plain vanilla usage, it just exchanges messages with the TWS. Any response is stored in the ` recieved-Array ` .
29+ In its plain vanilla usage, it just exchanges messages with the TWS. Any response is stored in the ` received-array ` .
2930
3031It needs just a few lines of code to place an order
3132
@@ -54,53 +55,43 @@ puts ib.recieved[:OrderStatus].to_human
5455
5556```
5657
57- ##### User-specific Actions
58- Besides storing any TWS-response in an array, callbacks are implemented.
58+ ## Plugins
59+
60+ ** IB-API** ships with simple plugins to facilitate automations
5961
60- The user subscribes to a certain response and defines the actions in a typically ruby manner. These actions
61- can be defined globaly
6262``` ruby
63- ib = IB ::Connection .new do |tws |
64- # Subscribe to TWS alerts/errors and order-related messages
65- tws.subscribe(:Alert , :OpenOrder , :OrderStatus , :OpenOrderEnd ) { |msg | puts msg.to_human }
66- end
63+ require ' ib-api'
64+ # connect with default parameters
65+ ib = IB ::Connection .new do | c |
66+ c.activate_plugin " verify"
67+ end
6768
69+ g = IB ::Stock .new symbol: ' GE'
70+ puts g.verify.first.attributes
71+ {:symbol =>" GE" , :sec_type =>" STK" , :last_trading_day =>" " , :strike =>0.0 , :right =>" " , :exchange =>" SMART" , :currency =>" USD" , :local_symbol =>" GE" , :trading_class =>" GE" , :con_id =>498843743 , :multiplier =>0 , :primary_exchange =>" NYSE" , }
6872```
6973
70- or occationally
74+ Currently implemented plugins
75+
76+ * connection-tools: ensure that a connection is established and active
77+ * verify: get contract details from the tws
78+ * symbols: use predefined symbols
79+ * managed-accounts: fetch and organize account- and portfoliovalues
80+ * advanced-account: perform account-based previewing, opening, modifying and closing of Positions
81+ * process-orders: account-based bookkeeping of orders
82+ * auto-adjust: properly adjust the orderprice to the next valid min-tick of the contract
83+ * market-price: fetch the current market-price of a contract
84+ * eod: retrieve EOD-Data for the given contract
85+ * greeks: read current option greeks
86+ * roll: easy rolling of futures and options
87+ * option-chain: build option-chains for given strikes and expiries
88+ * spread-prototypes: create limit, stop, market, etc. orders through prototypes
89+ * probability-of-expiring: calculate the probability of expiring for the option-contract
90+
7191
72- ``` ruby
73- # first define actions
74- q = Queue .new # Initialize as Queue
75- request_id = nil # declare variable
76- a = ib.subscribe(:Alert , :ContractData , :ContractDataEnd ) do |msg |
77- case msg
78- when Messages ::Incoming ::Alert
79- q.close if msg.code == 200 # No security found
80- when Messages ::Incoming ::ContractData # security returned
81- q.push msg.contract if msg.request_id == request_id
82- when Messages ::Incoming ::ContractDataEnd
83- q.close if msg.request_id == request_id
84- end # case
85- end
86- # perform request
87- request_id = ib.send_message :RequestContractData , :contract => Stock .new (symbol: ' T' )
88-
89- while contract = q.pop
90- puts contract.as_table
91- end
92- ┌───────┬────────┬──────────┬──────────┬────────┬────────────┬───────────────┬───────┬────────┬──────────┐
93- │ │ symbol │ con_id │ exchange │ expiry │ multiplier │ trading- class │ right │ strike │ currency │
94- ╞═══════╪════════╪══════════╪══════════╪════════╪════════════╪═══════════════╪═══════╪════════╪══════════╡
95- │ Stock │ T │ 37018770 │ SMART │ │ │ T │ │ │ USD │
96- └───────┴────────┴──────────┴──────────┴────────┴────────────┴───────────────┴───────┴────────┴──────────┘
97-
98- ib.unsubscribe a # release subscriptions
99-
100- ```
10192## Minimal TWS-Version
10293
103- ` ib-api ` is tested via the _ stable IB-Gateway_ (Version 10.12 ) and should work with any current tws-installation.
94+ ` ib-api ` is tested via the _ stable IB-Gateway_ (Version 10.19 ) and should work with any current tws-installation.
10495
10596## Tests
10697
0 commit comments