anthonyng2 / ib Goto Github PK
View Code? Open in Web Editor NEWSamples code demonstrating how to use IbPy to extract information from Interactive Brokers API
Samples code demonstrating how to use IbPy to extract information from Interactive Brokers API
Great code examples. I wrote a simple code based on your examples. It prints data under historicalData but not in the main() function. How do I create a dataframe in main() with historical data? For some reason it doesnt work below.
Thanks!
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.common import *
from ibapi.contract import *
from ibapi.ticktype import TickTypeEnum
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import queue
class TestWrapper(EWrapper,EClient):
def initiate_variables(self):
setattr(self, 'historical_Data', [])
setattr(self, 'historical_DataEnd_flag', False)
def historicalData(self, reqId, bar):
historical_Data = self.historical_Data
historical_Data.append((reqId, bar.date, bar.open, bar.high, bar.low, bar.close, bar.volume))
print("data", reqId, bar.date, bar.open, bar.high, bar.low, bar.close, bar.volume)
def main():
callback = TestWrapper() # Instantiate IBWrapper. callback
tws = EClient(callback) # Instantiate EClientSocket and return data to callback
tws.connect(host='127.0.0.1', port=4002, clientId=5)
callback.initiate_variables()
contract = Contract()
contract.symbol = "EUR"
contract.secType = "CASH"
contract.currency = "USD"
contract.exchange = "IDEALPRO"
tws.reqHistoricalData(1101, contract, "", "6000", "1 min", "MIDPOINT", 0, 1, False, [])
data= pd.DataFrame(callback.historical_Data,
columns = ["reqId", "date", "open",
"high", "low", "close",
"volume"])
data[-10:]
tws.run()
print(data)
tws.disconnect()
if __name__ == '__main__':
main()
Hello,
I purchased your udemy course, and greatly enjoyed it -- however upon going to your github I'm unable to get the software to work in Ipynb -- I can get the imports to work, however can't create instances of EWrapper/IBWrapper. Even made a class and extended functionality of IBWrapper/EClient -- still no luck.
Please advise -- and yes the software/twsapi is downloaded, basic tws calls work (requesting data) in pycharm just not able to get your code working in ipynb.
Any help would be greatly appreciated.
Here's the error thrown.
TypeError: Can't instantiate abstract class EWrapper with abstract methods accountDownloadEnd, accountSummary, accountSummaryEnd, bondContractDetails, commissionReport, connectionClosed, contractDetails, contractDetailsEnd, currentTime, deltaNeutralValidation, error, error_0, error_1, execDetails, execDetailsEnd, fundamentalData, historicalData, managedAccounts, marketDataType, nextValidId, openOrder, openOrderEnd, orderStatus, position, positionEnd, realtimeBar, receiveFA, scannerData, scannerDataEnd, scannerParameters, tickEFP, tickGeneric, tickOptionComputation, tickPrice, tickSize, tickSnapshotEnd, tickString, updateAccountTime, updateAccountValue, updateMktDepth, updateMktDepthL2, updateNewsBulletin, updatePortfolio
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.