mirror of
https://github.com/LBRYFoundation/LBRY-Vault.git
synced 2025-08-23 17:47:31 +00:00
fix timestamp of data in get_historical_rates
This commit is contained in:
parent
0a1542e249
commit
26d09b4915
1 changed files with 19 additions and 18 deletions
|
@ -68,40 +68,41 @@ class ExchangeBase(PrintError):
|
||||||
try:
|
try:
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
h = json.loads(f.read())
|
h = json.loads(f.read())
|
||||||
|
h['timestamp'] = timestamp
|
||||||
except:
|
except:
|
||||||
h = None
|
h = None
|
||||||
else:
|
else:
|
||||||
h = None
|
h = None
|
||||||
timestamp = False
|
|
||||||
if h:
|
if h:
|
||||||
self.history[ccy] = h
|
self.history[ccy] = h
|
||||||
self.on_history()
|
self.on_history()
|
||||||
return h, timestamp
|
return h
|
||||||
|
|
||||||
def get_historical_rates_safe(self, ccy, cache_dir):
|
def get_historical_rates_safe(self, ccy, cache_dir):
|
||||||
h, timestamp = self.read_historical_rates(ccy, cache_dir)
|
try:
|
||||||
if h is None or time.time() - timestamp < 24*3600:
|
self.print_error("requesting fx history for", ccy)
|
||||||
try:
|
h = self.request_history(ccy)
|
||||||
self.print_error("requesting fx history for", ccy)
|
self.print_error("received fx history for", ccy)
|
||||||
h = self.request_history(ccy)
|
except BaseException as e:
|
||||||
self.print_error("received fx history for", ccy)
|
self.print_error("failed fx history:", e)
|
||||||
self.on_history()
|
return
|
||||||
except BaseException as e:
|
filename = os.path.join(cache_dir, self.name() + '_' + ccy)
|
||||||
self.print_error("failed fx history:", e)
|
with open(filename, 'w') as f:
|
||||||
return
|
f.write(json.dumps(h))
|
||||||
filename = os.path.join(cache_dir, self.name() + '_' + ccy)
|
h['timestamp'] = time.time()
|
||||||
with open(filename, 'w') as f:
|
|
||||||
f.write(json.dumps(h))
|
|
||||||
self.history[ccy] = h
|
self.history[ccy] = h
|
||||||
self.on_history()
|
self.on_history()
|
||||||
|
|
||||||
def get_historical_rates(self, ccy, cache_dir):
|
def get_historical_rates(self, ccy, cache_dir):
|
||||||
result = self.history.get(ccy)
|
if ccy not in self.history_ccys():
|
||||||
if not result and ccy in self.history_ccys():
|
return
|
||||||
|
h = self.history.get(ccy)
|
||||||
|
if h is None:
|
||||||
|
h = self.read_historical_rates(ccy, cache_dir)
|
||||||
|
if h is None or h['timestamp'] < time.time() - 24*3600:
|
||||||
t = Thread(target=self.get_historical_rates_safe, args=(ccy, cache_dir))
|
t = Thread(target=self.get_historical_rates_safe, args=(ccy, cache_dir))
|
||||||
t.setDaemon(True)
|
t.setDaemon(True)
|
||||||
t.start()
|
t.start()
|
||||||
return result
|
|
||||||
|
|
||||||
def history_ccys(self):
|
def history_ccys(self):
|
||||||
return []
|
return []
|
||||||
|
|
Loading…
Add table
Reference in a new issue