alphavantage: request compact data if full data isn't needed.
This commit is contained in:
parent
ee8bf69dbe
commit
af297824a6
1 changed files with 10 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
import csv
|
import csv
|
||||||
import dataclasses
|
import dataclasses
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
@ -137,7 +138,7 @@ class AlphaVantage(BaseSource):
|
||||||
params = {
|
params = {
|
||||||
"function": "TIME_SERIES_DAILY_ADJUSTED",
|
"function": "TIME_SERIES_DAILY_ADJUSTED",
|
||||||
"symbol": series.base,
|
"symbol": series.base,
|
||||||
"outputsize": "full",
|
"outputsize": self._outputsize(series.start),
|
||||||
"apikey": self._apikey(),
|
"apikey": self._apikey(),
|
||||||
}
|
}
|
||||||
response = self.log_curl(requests.get(self.QUERY_URL, params=params))
|
response = self.log_curl(requests.get(self.QUERY_URL, params=params))
|
||||||
|
@ -159,7 +160,7 @@ class AlphaVantage(BaseSource):
|
||||||
"function": "FX_DAILY",
|
"function": "FX_DAILY",
|
||||||
"from_symbol": series.base,
|
"from_symbol": series.base,
|
||||||
"to_symbol": series.quote,
|
"to_symbol": series.quote,
|
||||||
"outputsize": "full",
|
"outputsize": self._outputsize(series.start),
|
||||||
"apikey": self._apikey(),
|
"apikey": self._apikey(),
|
||||||
}
|
}
|
||||||
response = self.log_curl(requests.get(self.QUERY_URL, params=params))
|
response = self.log_curl(requests.get(self.QUERY_URL, params=params))
|
||||||
|
@ -170,6 +171,13 @@ class AlphaVantage(BaseSource):
|
||||||
}
|
}
|
||||||
return normalized_data
|
return normalized_data
|
||||||
|
|
||||||
|
def _outputsize(self, start):
|
||||||
|
almost_100_days_ago = (datetime.now().date() - timedelta(days=95)).isoformat()
|
||||||
|
if start < almost_100_days_ago:
|
||||||
|
return "full"
|
||||||
|
else:
|
||||||
|
return "compact"
|
||||||
|
|
||||||
def _digital_data(self, series):
|
def _digital_data(self, series):
|
||||||
params = {
|
params = {
|
||||||
"function": "DIGITAL_CURRENCY_DAILY",
|
"function": "DIGITAL_CURRENCY_DAILY",
|
||||||
|
|
Loading…
Add table
Reference in a new issue