xhesikaruci / post_get_api_requests Goto Github PK
View Code? Open in Web Editor NEWPython automation of sending a POST request to an API, use information from the response to send another GET request and save the response in text file.
Python automation of sending a POST request to an API, use information from the response to send another GET request and save the response in text file.
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())
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()**
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.