Giter Club home page Giter Club logo

post_get_api_requests's People

Contributors

xhesikaruci avatar

post_get_api_requests's Issues

Need to know how to save response from IB API reqMktData in Python

This is the code i have. It displays the result however struggling to save it in variable or array for further processing..

import ib
from ib.ext.Contract import Contract
from ib.opt import ibConnection, message
from time import sleep
from ibapi.utils import iswrapper

import pandas as pd
from pandas import ExcelWriter
from pandas import ExcelFile

df = pd.read_excel('c:\CodePython\sample1.xls', sheetname='Sheet1')

print("Column headings:")
print(df.columns)

print(df.index)
print(df['Week1'])
for i in df.index:
print(df['Week2'][i])

class Downloader(object):
field4price = ''

def reply_handler(msg):
    print("Reply:", msg)    

def my_callback_handler(self,msg):
    if msg.field == 4:
        self.price_field = msg.price
    else:
        print(msg)
        
def __init__(self,debug=False):
    self.tws = ibConnection('localhost', 7496, 999)
    self.tws.register(self.my_callback_handler)

    if debug:
        self.tws.registerAll(self.debugHandler)

    self.tws.connect()
    self._reqId = 1 # current request id

def debugHandler(self,msg):
    print ('[debug]', msg)

def tickPriceHandler(self,msg):
    if msg.field == 4:
        self.field4price = msg.price
        print ('[debug12]', msg.price)
    
def closeconn(self):   
    print ('[debug]', self.tws.disconnect())

def requestData(self,contract):
    self.tws.reqMktData(self._reqId,c,'',1)
    self._reqId+=1
    #return "???"

if name=='main':
dl = Downloader(debug=True)
c = Contract()
c.m_symbol = 'TLYS'
c.m_secType = 'STK'
c.m_exchange = 'SMART'
c.m_currency = 'USD'
df = dl.requestData(c)
#print ("DATa" ,laststockpricefield4)
sleep(3)
#print ("DATa111" ,dl.field4price)
sleep(3)

print("disconnect",dl.closeconn())

Getting unhandled exception in EReader thread

I have the below code to print price from IB response. If i comment out the If and self.disconnect, there is no issue. But since i like the session to be terminated after count 2, i have this condition and getting the error "Tick Price. Ticker ID 1101 ticktype CLOSE Price 37.14 count 1
unhandled exception in EReader thread

def tickPrice(self, reqId, tickType, price, attrib):
    #print("Tick Price. Ticker ID", reqId, "ticktype", TickTypeEnum.to_str(tickType), "Price" , price, end=' ')
    if(TickTypeEnum.to_str(tickType) == 'CLOSE'):
        print("Tick Price. Ticker ID", reqId, "ticktype", TickTypeEnum.to_str(tickType), "Price" , price, end=' ')
        self.count += 1
        print("count", self.count)
        **if self.count > 1: 
           self.disconnect()**

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.