Currently I am trying to request data from the IB API, but I have a small formatting issue.
The API gives me the following output:
AAPL; 20190507 16:20:00; price; price; price; price; number
I would like the data to return as:
AAPL; 20190507; 16:20:00; price; price; price; price; number
I am using the following code
from ibapi.client import EClient
from ibapi.wrapper import EWrapper
from ibapi.contract import Contract
class TestApp(EWrapper, EClient):
def __init__(self):
EClient.__init__(self, self)
def error(self, reqId, errorCode, errorString):
print("error: ", reqId, " ", errorCode, " ", errorString)
def historicalData(self, reqId, bar):
print("AAPL", ";", bar.date, ";", bar.open, ";", bar.high, ";", bar.low, ";", bar.close, ";", bar.volume)
def main():
app = TestApp()
app.connect("127.0.0.1", 7497, 0)
contract = Contract ()
contract.symbol = "AAPL"
contract.secType = "STK"
contract.exchange = "SMART"
contract.currency = "USD"
contract.primaryExchange = "NASDAQ"
app.reqHistoricalData(0, contract, "", "1 D", "1 min", "TRADES", 0, 1, False, [])
app.run()
if __name__ == "__main__":
main()
bar.date in this case gives me the date and time
print("AAPL", ";", bar.date, ";", bar.open, ";", bar.high, ";", bar.low, ";", bar.close, ";", bar.volume)
Could anyone help me out with this?