GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • IB-Ruby Doc
  • Nav
  • GitHub
  • News

This view

  • Original page
  • New address

GeezerVison is showing ib-ruby.github.io — Jupyter Notebooks | IB-Ruby documentation

  • ib-ruby
  • Overview
    • The IB-Ruby Project
    • Introduction
    • Support
  • Installation
    • Setup Ruby and Install the Software.
    • Create a new Project
  • Connection / Plugins
    • Connect to the TWS
    • IB-Connection
    • IB-Ruby Console
    • Jupyter Notebooks
  • Messages
    • List of Messages
    • Request-ID
    • Request Market-Data
  • Contracts
    • Specify and Query
    • Verify
    • Market Price
    • Historical Data
    • Expiry vs. Last-Trading-Day
    • Watchlists
    • Spread Prototypes
    • Rolling of Options and Futures
    • Option-Chains
    • Option-Greeks
  • Orders
    • Prototypes
    • Placing Orders (plain vanilla)
    • Placing Orders (advanced)
  • Accounts
    • Overview
  • Database & Rails Integration
    • Overview

Jupyter Notebooks

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-api'

# Connect to IB TWS.
C = IB::Gateway.new   port:  4002  
A sample file is included in 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 
The use of terminal tables is covered in the ib-examples-Notebook: /account/inspect_portfolio.ipynb

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.