Skip to content

Instantly share code, notes, and snippets.

@romanmichaelpaolucci
Last active September 22, 2020 13:31
Show Gist options
  • Save romanmichaelpaolucci/ebd7ad92c64cf70f32a243b5bd1f24f3 to your computer and use it in GitHub Desktop.
Save romanmichaelpaolucci/ebd7ad92c64cf70f32a243b5bd1f24f3 to your computer and use it in GitHub Desktop.
IB Connection
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()
@suchislife801
Copy link

So, for people who learn by example, are you going to add the meaningful API calls that makes trading possible or just stop here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment