Last active
September 22, 2020 13:31
-
-
Save romanmichaelpaolucci/ebd7ad92c64cf70f32a243b5bd1f24f3 to your computer and use it in GitHub Desktop.
IB Connection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from ibapi.wrapper import EWrapper | |
from ibapi.client import EClient | |
from ibapi.utils import iswrapper | |
from ibapi.order import Order | |
from ibapi.common import * | |
from ibapi.contract import * | |
from ibapi.ticktype import * | |
from threading import Thread | |
import datetime | |
import time | |
# Receives Callbacks - Data can be stored in separate cache or internally | |
class ApiController(EWrapper): | |
def __init__(self): | |
pass | |
@iswrapper | |
def error(self, reqId, errorCode, errorString): | |
print("Error. Id: " , reqId, " Code: " , errorCode , " Msg: " , errorString) | |
@iswrapper | |
def connectAck(self): | |
print("\n[Connected]") | |
# Making Server Requests | |
class ApiSocket(EClient): | |
def __init__(self, wrapper): | |
super().__init__(wrapper) | |
class TradingApp(ApiController, ApiSocket): | |
def __init__(self): | |
ApiController.__init__(self) | |
ApiSocket.__init__(self, wrapper=self) | |
self.connect('127.0.0.1', 4002, 1) | |
# By running run() on its own thread queues from EClient are continuously read | |
thread = Thread(target=self.run) | |
thread.start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So, for people who learn by example, are you going to add the meaningful API calls that makes trading possible or just stop here?