mirror of
https://github.com/cmallwitz/Financials-Extension.git
synced 2026-08-24 10:04:10 -05:00
Fix some minor issue
This commit is contained in:
+1
-1
@@ -182,7 +182,7 @@ class BaseClient:
|
||||
elif datacode == Datacode.EXCHANGE.value and data[Datacode.EXCHANGE]:
|
||||
return data[Datacode.EXCHANGE]
|
||||
|
||||
elif datacode == Datacode.CURRENCY.value and data[Datacode.CURRENCY]:
|
||||
elif datacode == Datacode.CURRENCY.value and Datacode.CURRENCY in data:
|
||||
return data[Datacode.CURRENCY]
|
||||
|
||||
elif datacode == Datacode.NAME.value and data[Datacode.NAME]:
|
||||
|
||||
+12
-1
@@ -26,6 +26,11 @@ def log(str):
|
||||
# print(str, file=sys.stderr)
|
||||
pass
|
||||
|
||||
# TODO migrate to:
|
||||
# https://www.google.com/search?q=NYSE:IBM&tbm=fin
|
||||
# https://www.google.com/search?q=NASDAQ:INTC&tbm=fin
|
||||
# https://www.google.com/search?q=LON:VOD&tbm=fin
|
||||
# https://www.google.com/search?q=EURGBP
|
||||
|
||||
class Google(BaseClient):
|
||||
def __init__(self, ctx):
|
||||
@@ -78,7 +83,10 @@ class Google(BaseClient):
|
||||
for key, value in result:
|
||||
|
||||
if key == 'exchangeTimezone':
|
||||
pass
|
||||
try:
|
||||
tick[Datacode.TIMEZONE] = str(value)
|
||||
except:
|
||||
pass
|
||||
|
||||
elif key == 'priceChange':
|
||||
try:
|
||||
@@ -139,6 +147,9 @@ class Google(BaseClient):
|
||||
|
||||
tick[Datacode.TIMESTAMP] = time.time()
|
||||
|
||||
if tick[Datacode.EXCHANGE] == 'CURRENCY' and not Datacode.CURRENCY in tick:
|
||||
tick[Datacode.CURRENCY] = ''
|
||||
|
||||
log(tick)
|
||||
|
||||
except BaseException as e:
|
||||
|
||||
@@ -21,6 +21,10 @@ class TestGoogle(unittest.TestCase):
|
||||
s = financials.getRealtime('EURGBP', Datacode.LAST_PRICE.value, 'GOOGLE')
|
||||
self.assertEqual(type(s), float, 'test_currency LAST_PRICE')
|
||||
|
||||
s = financials.getRealtime('EURGBP', Datacode.CURRENCY.value, 'GOOGLE')
|
||||
self.assertEqual(type(s), str, 'test_currency CURRENCY')
|
||||
self.assertEqual(s, '', 'test_currency CURRENCY')
|
||||
|
||||
def test_UK_equity(self):
|
||||
s = financials.getRealtime('EURGBP', Datacode.LAST_PRICE.value, 'GOOGLE')
|
||||
self.assertEqual(type(s), float, 'test_UK_equity LAST_PRICE')
|
||||
@@ -78,6 +82,9 @@ class TestGoogle(unittest.TestCase):
|
||||
s = financials.getRealtime('FRA:SAP', '21', 'GOOGLE')
|
||||
self.assertEqual(type(s), float, 'test_DE_equity \'21\'')
|
||||
|
||||
s = financials.getRealtime('FRA:SAP', Datacode.TIMEZONE.value, 'GOOGLE')
|
||||
self.assertEqual(s, 'Europe/Berlin', 'test_DE_equity TIMEZONE')
|
||||
|
||||
def test_DE_ETF(self):
|
||||
s = financials.getRealtime('FRA:C060', Datacode.LAST_PRICE.value, 'GOOGLE')
|
||||
self.assertEqual(type(s), float, 'test_DE_ETF LAST_PRICE')
|
||||
@@ -131,6 +138,9 @@ class TestGoogle(unittest.TestCase):
|
||||
s = financials.getRealtime('NYSE:IBM', Datacode.TIMESTAMP.value, 'GOOGLE')
|
||||
self.assertEqual(s, 'Data doesn\'t exist - 999', 'test_US_equity TIMESTAMP')
|
||||
|
||||
s = financials.getRealtime('NYSE:IBM', Datacode.TIMEZONE.value, 'GOOGLE')
|
||||
self.assertEqual(s, 'America/New_York', 'test_US_equity TIMEZONE')
|
||||
|
||||
def test_US_mutuals(self):
|
||||
s = financials.getRealtime('MUTF:VFIAX', Datacode.LAST_PRICE.value, 'GOOGLE')
|
||||
self.assertEqual(type(s), float, 'test_US_mutuals LAST_PRICE')
|
||||
|
||||
@@ -16,6 +16,8 @@ from datacode import Datacode
|
||||
|
||||
financials = financials.createInstance(None)
|
||||
|
||||
# TODO migrate to:
|
||||
# https://finance.yahoo.com/quote/EURGBP=X?p=EURGBP=X
|
||||
|
||||
class TestYahoo(unittest.TestCase):
|
||||
|
||||
@@ -48,6 +50,17 @@ class TestYahoo(unittest.TestCase):
|
||||
s = financials.getRealtime('IBM', Datacode.TIMEZONE.value, 'YAHOO')
|
||||
self.assertEqual(s, 'America/New_York', 'test_realtime_US_equity TIMEZONE {}'.format(s))
|
||||
|
||||
def test_realtime_US_mutuals(self):
|
||||
|
||||
s = financials.getRealtime('VFIAX', Datacode.LAST_PRICE.value, 'YAHOO')
|
||||
self.assertEqual(type(s), float, 'test_realtime_US_mutuals LAST_PRICE {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('VFIAX', Datacode.LAST_PRICE_DATE.value, 'YAHOO')
|
||||
self.assertEqual(type(s), str, 'test_realtime_US_mutuals LAST_PRICE_DATE {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('VFIAX', Datacode.LAST_PRICE_TIME.value, 'YAHOO')
|
||||
self.assertEqual(type(s), str, 'test_realtime_US_mutuals LAST_PRICE_TIME {}'.format(s))
|
||||
|
||||
def test_realtime_UK_ETF(self):
|
||||
|
||||
s = financials.getRealtime('VERX.L', Datacode.LAST_PRICE.value, 'YAHOO')
|
||||
|
||||
+18
-9
@@ -32,6 +32,15 @@ def log(str):
|
||||
pass
|
||||
|
||||
|
||||
def raw(price, key, default=0.0):
|
||||
try:
|
||||
return price[key]['raw']
|
||||
except:
|
||||
pass
|
||||
|
||||
return default
|
||||
|
||||
|
||||
class Yahoo(baseclient.BaseClient):
|
||||
def __init__(self, ctx):
|
||||
super().__init__()
|
||||
@@ -148,15 +157,15 @@ class Yahoo(baseclient.BaseClient):
|
||||
|
||||
tick = self.realtime[ticker]
|
||||
|
||||
tick[Datacode.PREV_CLOSE] = float(price['regularMarketPreviousClose']['raw'])
|
||||
tick[Datacode.OPEN] = float(price['regularMarketOpen']['raw'])
|
||||
tick[Datacode.CHANGE] = float(price['regularMarketChange']['raw'])
|
||||
tick[Datacode.CHANGE_IN_PERCENT] = float(price['regularMarketChangePercent']['raw'])
|
||||
tick[Datacode.LOW] = float(price['regularMarketDayLow']['raw'])
|
||||
tick[Datacode.HIGH] = float(price['regularMarketDayHigh']['raw'])
|
||||
tick[Datacode.LAST_PRICE] = float(price['regularMarketPrice']['raw'])
|
||||
tick[Datacode.VOLUME] = float(price['regularMarketVolume']['raw'])
|
||||
tick[Datacode.AVG_DAILY_VOL_3MOMTH] = float(price['averageDailyVolume3Month']['raw'])
|
||||
tick[Datacode.PREV_CLOSE] = float(raw(price, 'regularMarketPreviousClose'))
|
||||
tick[Datacode.OPEN] = float(raw(price, 'regularMarketOpen'))
|
||||
tick[Datacode.CHANGE] = float(raw(price, 'regularMarketChange'))
|
||||
tick[Datacode.CHANGE_IN_PERCENT] = 100*float(raw(price, 'regularMarketChangePercent'))
|
||||
tick[Datacode.LOW] = float(raw(price, 'regularMarketDayLow'))
|
||||
tick[Datacode.HIGH] = float(raw(price, 'regularMarketDayHigh'))
|
||||
tick[Datacode.LAST_PRICE] = float(raw(price, 'regularMarketPrice'))
|
||||
tick[Datacode.VOLUME] = float(raw(price, 'regularMarketVolume'))
|
||||
tick[Datacode.AVG_DAILY_VOL_3MOMTH] = float(raw(price, 'averageDailyVolume3Month'))
|
||||
|
||||
if quoteType:
|
||||
t = int(price['regularMarketTime'])
|
||||
|
||||
Reference in New Issue
Block a user