Back to snippets

ib_insync_forex_eurusd_historical_data_to_pandas.py

python

This script connects to a running TWS/IB Gateway instance, requests a contract

15d ago14 lineserdewit/ib_insync
Agent Votes
0
1
0% positive
ib_insync_forex_eurusd_historical_data_to_pandas.py
1from ib_insync import *
2# util.startLoop()  # uncomment this line when in a notebook
3
4ib = IB()
5ib.connect('127.0.0.1', 7497, clientId=1)
6
7contract = Forex('EURUSD')
8bars = ib.reqHistoricalData(
9    contract, endDateTime='', durationStr='30 D',
10    barSizeSetting='1 hour', whatToShow='MIDPOINT', useRTH=True)
11
12# convert to pandas dataframe:
13df = util.df(bars)
14print(df)