To use the features described, include the ib-orientdb Gem in the Gemfile.

OrientDB is a Not Only SQL Database owned and maintained by SAP.

The [wiki of ActiveOrient](https://github.com/topofocus/active-orient/wiki/Initialisation) gives an overview of the features of the ruby-implementation.

It aims to be “the first Multi-Model Open Source NOSQL DBMS that brings together the power of graphs and the flexibility of documents into one scalable high-performance operational database.” Through Active-Orient it acts as an object-orientated SQL-RDBMS-Database with graph capabilities.

The IB-OrientDB-Gem connects a running IB-api-client to a running OrientDB-Database-Server and provides methods to store data provided by the Interactive Brokers TWS into the database.

This is shown in the following example. To reproduce, clone ib-orientdb and run the ./console script in /bin.

We create a IB::Stock-object, verify through the TWS and subsequently store it in the database.
Then we query the database and fetch some historical data. No conversion of any kind is required as objects received via the TWS-API are identical to those stored in the database.

# Create a new Contract
> f =  IB::Stock.new symbol: 'F'
# Inspect its class hierarchy
> f.class.ancestors   # edited result:
 => IB::Stock, IB::Contract, V, ActiveOrient::Model, ActiveOrient::Base  
# Note: The Stock-Object is indeed Child of a OrientDB Vertex-Class "V" 

# Now store it and check its presence in the database 
> f.rid              => ":"    #  its not saved jet
> f.save             => false  #  it cannot be saved, because its not verified
                               #  ( no con_id is present  )
> verified_f = f.verify.first
> verified_f.save
> verified_f.rid    => "59:0" # the object is updated 

> new_f =  V.get "59:0"       # retrieve from the database. Note that we do not 
                              # have to specify the appropriate class. 
> new_f.class       => IB::Stock 
> new_f == verified_f  => true #  its a copy of the original
# Query the database and ask the TWS for historical data
> puts  IB::Stock.where( symbol: 'F' ).first.eod( duration: '10 d' ).to_human
# INFO->MATCH {class: ib_stock, as: ib_stocks, where: ( symbol = 'F') } 
<Bar: 2020-11-13 wap 8.452 OHLC 8.31 8.57 8.16 8.52 trades 79407 vol 764141>
<Bar: 2020-11-16 wap 8.761 OHLC 8.65 8.91 8.57 8.8 trades 90727 vol 826969>
<Bar: 2020-11-17 wap 8.739 OHLC 8.75 8.85 8.63 8.73 trades 54007 vol 455313>
<Bar: 2020-11-18 wap 8.951 OHLC 8.76 9.05 8.74 8.9 trades 75730 vol 724330>
<Bar: 2020-11-19 wap 8.802 OHLC 8.87 8.94 8.74 8.77 trades 54895 vol 545472>
<Bar: 2020-11-20 wap 8.742 OHLC 8.73 8.87 8.68 8.76 trades 66661 vol 550186>
<Bar: 2020-11-23 wap 8.885 OHLC 8.76 8.98 8.75 8.93 trades 75533 vol 662582>
<Bar: 2020-11-24 wap 9.386 OHLC 8.92 9.56 8.91 9.56 trades 110795 vol 959114>
<Bar: 2020-11-25 wap 9.089 OHLC 9.33 9.41 9.0 9.12 trades 98761 vol 925084>
<Bar: 2020-11-27 wap 9.078 OHLC 9.13 9.15 9.03 9.1 trades 32327 vol 270936>

Tags: