For development purposes Jupyter Notebooks are quite popular.
The IRuby Project
Its easy to setup the Jupyter Environment ready to use a Ruby Kernel. The IRuby-Project maintains Ruby Notebooks and provides a simple installation guide.
After successfully installing, Notebooks are managed by calling
$ iruby notebook
Contents of the current directory are displayed in the internet-browser and Notebooks can be managed from there.
Jupyter Notebooks use the usual bundle
environment.
Its recommended to create a setup.rb
init-file and to require it in the first statement of every Notebook.
# ------------ setup.rb ---------------
require 'bundler/setup'
require 'ib-gateway'
require 'ib/symbols'
# Connect to IB TWS.
G = IB::Gateway.new port: 4002
C = G.tws
ib-examples
: /lib/iruby_init.rb A gentle warning
Jupyter Notebooks provide an intuitive way to develop algorithms and showcases. The combination of code and documentation is charming.
BUT: There are designed for presentation purposes. Not for software development.
Notebooks are a modern alternative to old school console applications. They are not a substitute to test driven programming.
Display contents with as-table
The Terminal-Table Gem provides a comfortable output of arrays and hashes.
Every IB::Model
-Object can be printed by
> puts object.as_table
Example
3.0.0 :010 > puts Stock.new( symbol: 'GE' ).verify.first.as_table
┌───────┬────────┬────────┬──────────┬────────┬────────────┬───────────────┬───────┬────────┬──────────┐
│ │ symbol │ con_id │ exchange │ expiry │ multiplier │ trading-class │ right │ strike │ currency │
╞═══════╪════════╪════════╪══════════╪════════╪════════════╪═══════════════╪═══════╪════════╪══════════╡
│ Stock │ GE │ 7516 │ SMART │ │ │ GE │ │ │ USD │
└───────┴────────┴────────┴──────────┴────────┴────────────┴───────────────┴───────┴────────┴──────────┘
However, for complex objects his approach is no appropriate. For instance, ContractDetails
are better handled by the
traditional to_human
method
puts Stock.new( symbol: 'GE' ).verify.first.contract_detail.to_human
<ContractDetails GENERAL ELECTRIC CO, --> GE, /C/ Miscellaneous Manufactur, /I/ Industrial /SC/ Diversified Manufact Op,
md_size_multiplier:100, min_tick:0.01, price_magnifier:1, sec_id-list:{:ISIN=>"US3696041033"},
valid exchanges: SMART,AMEX,NYSE,CBOE,PHLX,ISE,CHX,ARCA,ISLAND,DRCTEDGE,BEX,BATS,EDGEA,CSFBALGO,JEFFALGO,BYX,IEX,EDGX,FOXRIVER,PEARL,NYSENAT,LTSE,MEMX,PSX; order types: ACTIVETIM,AD,ADJUST,ALERT,ALGO,ALLOC,AON,AVGCOST,BASKET,BENCHPX,CASHQTY,COND,CONDORDER,DARKONLY,DARKPOLL,DAY,DEACT,DEACTDIS,DEACTEOD,DIS,GAT,GTC,GTD,GTT,HID,IBKRATS,ICE,IMB,IOC,LIT,LMT,LOC,MIDPX,MIT,MKT,MOC,MTL,NGCOMB,NODARK,NONALGO,OCA,OPG,OPGREROUT,PEGBENCH,POSTONLY,PREOPGRTH,PRICECHK,REL,RELPCTOFS,RPI,RTH,RTHIGNOPG,SCALE,SCALEODD,SCALERST,SIZECHK,SNAPMID,SNAPMKT,SNAPREL,STP,STPLMT,SWEEP,TRAIL,TRAILLIT,TRAILLMT,TRAILMIT,WHATIF
ib-examples-Notebook
: /account/inspect_portfolio.ipynb