twelvedata / twelvedata-python

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

[Bug] Batch Request behavior failing (does not achieve README description) #73

Closed cbishup closed 1 year ago

cbishup commented 1 year ago

Description Batch requests as described in this documentation are not operating as expected. Instead of making one API request for 12 symbols as per the README "With batch requests up to 120 symbols might be returned per single API call." Instead I get an error stating 12 API credits were used, which is over the trial allowance of 8 per minute.

To Reproduce Steps to reproduce the behavior: Python version 3.8.18 twelvedata version 1.2.12

example_stocks = "AA, AAL, AAPL, ACN, ADBE, AMZN, AVGO, PFE, NEM, TSLA, LEVI, CCL"
ts = td.time_series(symbol=example_stocks, interval='1day', outputsize=5)
print(ts.as_json())

Expected behavior Up to 120 time series returned in a single json response using a single API call.

Error Message

Traceback (most recent call last):
  File "/main.py", line 10, in <module>
    print(ts.as_json())
  File "/lib/python3.8/site-packages/twelvedata/time_series.py", line 41, in as_json
    time_series_json = self.price_endpoint.as_json()
  File "/lib/python3.8/site-packages/twelvedata/mixins.py", line 12, in as_json
    resp = self.execute(format="JSON")
  File "/lib/python3.8/site-packages/twelvedata/endpoints.py", line 299, in execute
    return self.ctx.http_client.get(endpoint, params=params)
  File "/lib/python3.8/site-packages/twelvedata/http_client.py", line 50, in get
    self._raise_error(error_code, message)
  File "/lib/python3.8/site-packages/twelvedata/http_client.py", line 63, in _raise_error
    raise TwelveDataError(message)
twelvedata.exceptions.TwelveDataError: You have run out of API credits for the current minute. 12 API credits were used, with the current limit being 8. Wait for the next minute or consider switching to a higher tier plan

Additional context Same response using the other format symbol=["V", "RY", "AUD/CAD", "BTC/USD:Huobi"] and also for .as_cvs().

midasSSS commented 1 year ago

You're charged based on the number of symbols requested. 1 batch API call with 12 symbols is equivalent to 12 API calls with a single symbol. You can read more about batch requests here.