Bash script to fetch data from IB TWS and output to csv

Bash script to fetch data from IB TWS and output to csv

Closed - This job posting has been filled.

Job Description

Hi!

The job is to create a bash script to fetch options historical data from Interactive Brokers TWS.
1. The individual stock symbols are in a csv file.
2. Then the options chains for the symbols have to be fetched with twstools. ( https://github.com/rudimeier/twstools )
3. Then the options historical data will have to be fetched from IB TWS and output to a csv file in the format. The name of the csv file should be "optionsymbol.csv"
--------------
"Index","GLD.Open","GLD.High","GLD.Low","GLD.Close","GLD.Volume","GLD.Adjusted"
2004-11-18,44.43,44.49,44.07,44.38,5991500,44.38
2004-11-19,44.49,44.92,44.47,44.78,11655300,44.78
2004-11-22,44.75,44.97,44.74,44.95,11996000,44.95
-------------
Speed to complete the task is not important but a quality job and extremely good documentation is vital. When this job is completed I am looking for some more help working with the csv-files and R.

Please describe if you have done similar work before.

Full ssh access to a server with all the required tools will be provided so you will be able to start work without need to set up anything.



update:
Here is a sample bash-script to retrieve forex data and write it out to csv-files.
The thing that would have to be changed is to get the options contracts and then data for them instead of forex and write it out to individual csv files.

As you can see twstools does most of the datahandling so the script part is relatively simple.

nk@i5:~/twstools/twstools/sample$ cat get_some_forex_data.sh
#!/bin/sh

# change your host/port
TWSDO="twsdo -h 192.168.3.114 -p 7496 --maxRequests=30 --pacingInterval=305000"
WORK_CONTRACTS="sample_job_contracts_forex.xml"

# get some contract details
${TWSDO} ${WORK_CONTRACTS} > out_forex_contracts.xml \
|| exit 1

# create historical data requests for these contracts
twsgen -H -b "15 mins" -w "BID_ASK" out_forex_contracts.xml > out_forex_work_hist.xml \
|| exit 1

# process the hist data job
${TWSDO} out_forex_work_hist.xml > out_forex_hist.xml \
|| exit 1


# convert to csv and sort traded and quotes into different files
twsgen -C out_forex_hist.xml |grep "^BA" | sort |uniq > out_forex_quotes.csv

nk@i5:~/twstools/twstools/sample$

---
Skills: linux

Other open jobs by this client