jyotirmay
jyotirmay

Reputation: 37

How to get data of a python code in pandas dataframe

The following is a python code which prints live data from an API of a data feed vendor. I want the data in the panda's data frame but it prints only the following result "Empty DataFrame Columns: [] Index: []"

from truedata_ws.websocket.TD import TD
import time
import pandas as pd
username = ''
password = ''
realtime_port = 8084
url = 'push.truedata.in'
symbols = []
td_obj = TD(username, password, live_port=realtime_port, url=url, log_level=logging.DEBUG, log_format="%(message)s")

print('\nStarting Real Time Feed.... ')

req_ids = td_obj.start_live_data(symbols)
live_data_objs = {}

time.sleep(1)  

for req_id in req_ids:
    print(f'touchlinedata -> {td_obj.touchline_data[req_id]}')
    df=pd.DataFrame(live_data_objs)
    print(df)

@td_obj.trade_callback
def strategy_callback(symbol_id, tick_data):
    print(f'Trade  update > {tick_data}')

while True:
    time.sleep(120)

Upvotes: 1

Views: 180

Answers (1)

Alireza75
Alireza75

Reputation: 501

In your code, you pass an empty dictionary as an argument for creating a Data-frame, the Data-Frame you will get back for passing an empty dictionary will be Empty

Upvotes: 2

Related Questions