twelvedata / twelvedata-python

Twelve Data Python Client - Financial data API & WebSocket
https://twelvedata.com
MIT License
385 stars 57 forks source link

[Bug] Python SDK does not return meta fields from `/time_series` endpoint when fetching for only ONE symbol #86

Closed rku-carta closed 1 month ago

rku-carta commented 2 months ago

Describe the bug Python SDK does not return meta fields from /time_series endpoint when fetching for only ONE symbol

To Reproduce Steps to reproduce the behavior: Run the following in Python:

from twelvedata.client import TDClient

client = TDClient(apikey=API_KEY)
client.time_series(**{'symbol': "AAPL", 'interval': "1day", 'start_date': "2024-08-08"}).price_endpoint.as_json()

Expected behavior Expected response:

{
    'AAPL': {
        'meta': {
            'symbol': 'AAPL',
            'interval': '1day',
            'currency': 'USD',
            'exchange_timezone': 'America/New_York',
            'exchange': 'NASDAQ',
            'type': 'Common Stock'
        },
        'values': [
            {
                'datetime': '2022-04-06',
                'open': '172.36000',
                'high': '173.63000',
                'low': '170.13000',
                'close': '172.08000',
                'volume': '68059930'
            }
        ],
        'status': 'ok'
    }
}

Actual behavior Actual response:

[{'datetime': '2024-08-08',                                                                                                                                                                    
  'open': '213.09500',                                                                                                                                                                         
  'high': '214.20000',
  'low': '208.83000',
  'close': '213.34000',
  'volume': '36149428'}]

Desktop (please complete the following information):

Additional context Add any other context about the problem here.

sgacode commented 1 month ago

For this purpose, you can use as_raw_json method and convert the response to json manually.

Example:

response = td.time_series(**{'symbol': "AAPL", 'interval': "1day", 'start_date': "2024-08-08"}).price_endpoint.as_raw_json()
response_data = json.loads(response)
print(response_data)