mirror of
https://github.com/cmallwitz/Financials-Extension.git
synced 2026-08-24 10:04:10 -05:00
Package all Python dependencies and disable Google as source
This commit is contained in:
@@ -1,38 +1,19 @@
|
||||
# Financials-Extension
|
||||
|
||||
This is a Python based extension for LibreOffice Calc to make stock market, index and FX data available in Calc
|
||||
spreadsheets - currently supporting Yahoo's, Financial Times' and Google's (without FX data) finance websites
|
||||
using old-fashioned web scraping.
|
||||
spreadsheets - currently supporting Yahoo's and Financial Times' finance websites using old-fashioned web scraping.
|
||||
Starting with version 3 of the extension, Google was dropped as source as its finance website was changed dramatically
|
||||
requiring a complete re-work of the logic to pull data of it. No one seems to have complained, so I guess not a lot of
|
||||
people rely on it. If there is popular demand, I can take a look at adding it back. Alternatively I'm open for
|
||||
suggestions to add another provider with global exchange and asset class coverage.
|
||||
|
||||
Additionally, starting with version 3 of the extension, it contains all non-standard Python packages it uses
|
||||
(dateutil, pytz, pyparsing). Consequently, it is no longer necessary to install anything to your system.
|
||||
|
||||
### Feedback requested:
|
||||
|
||||
Please provide feedback about using the extension here: https://github.com/cmallwitz/Financials-Extension/issues/10
|
||||
|
||||
### System requirements:
|
||||
|
||||
This extension requires the following Python 3 packages (on top of standard libs): dateutil, pytz, pyparsing. These are
|
||||
from within LibreOffice, so if your LibreOffice comes with it's own Python runtime (e.g. Windows) they need to be
|
||||
installed there instead somewhere else in the system.
|
||||
|
||||
On Ubuntu 18 and 20, dateutil and pytz may already be installed, but you can get all you need by running
|
||||
- sudo apt-get install python3-dateutil python3-tz python3-pyparsing
|
||||
|
||||
On Debian 10, the following steps have worked for me (as root)
|
||||
- apt install python3-pip
|
||||
- pip3 install python-dateutil pytz pyparsing
|
||||
|
||||
Users on Windows 10 have reported this to work - as LibreOffice on Windows ships with its own, but minimal
|
||||
Python runtime a few more steps are required
|
||||
- Download the script https://bootstrap.pypa.io/get-pip.py to your computer
|
||||
- Start a Command Prompt (CMD) as Administrator
|
||||
- on this command prompt run (change path as required)
|
||||
|
||||
"c:\Program Files\LibreOffice\program\python.exe" c:\temp\get-pip.py
|
||||
|
||||
- and then
|
||||
|
||||
"c:\Program Files\LibreOffice\program\python.exe" -m pip install python-dateutil pytz pyparsing
|
||||
|
||||
### Usage:
|
||||
|
||||
Under 'Releases' on GitHub there is downloadable **Financials-Extension.oxt** file - load it into Calc
|
||||
@@ -40,7 +21,6 @@ under menu item: Tools, Extension Manager...
|
||||
|
||||
Getting data should be a simple as having this in a cell:
|
||||
- `=GETREALTIME("IBM",21,"YAHOO")`
|
||||
- `=GETREALTIME("NYSE:IBM",21,"GOOGLE")`
|
||||
- `=GETREALTIME("IBM:NYQ",21,"FT")`
|
||||
- `=GETHISTORIC("IBM",90,"2020-12-01","YAHOO")`
|
||||
|
||||
@@ -68,43 +48,43 @@ Depending on your system's language and default LibreOffice settings, you maybe
|
||||
|
||||
You can either specify numbers or names (lower or upper case) - not all bits are available from all sources and they are not necessarily consistent across sources either.
|
||||
|
||||
|Name|Code|YAHOO|FT|GOOGLE|YAHOO (historic)|Notes|
|
||||
| :--- | :--- | :---: | :---: | :---: | :---: | :---: |
|
||||
|PREV_CLOSE|5|Yes|Yes|Yes|||
|
||||
|OPEN|6|Yes|Yes|Yes|Yes||
|
||||
|CHANGE|7|Yes|Yes|Yes|||
|
||||
|LAST_PRICE_DATE|8|Yes|Yes|Yes| |yyyy-mm-dd|
|
||||
|LAST_PRICE_TIME|10|Yes|Yes|Yes|||
|
||||
|CHANGE_IN_PERCENT|11|Yes|Yes|Yes|||
|
||||
|LOW|14|Yes|Yes|Yes|Yes||
|
||||
|HIGH|16|Yes|Yes|Yes|Yes||
|
||||
|LAST_PRICE|21|Yes|Yes|Yes|||
|
||||
|BID|22|Yes|Yes|No|||
|
||||
|ASK|25|Yes|Yes|No|||
|
||||
|HIGH_52_WEEK|24|Yes|Yes|Yes|||
|
||||
|LOW_52_WEEK|26|Yes|Yes|Yes|||
|
||||
|MARKET_CAP|27|Yes|Yes|Yes|||
|
||||
|BIDSIZE|30|Yes|Yes|No|||
|
||||
|ASKSIZE|31|Yes|Yes|No|||
|
||||
|VOLUME|35|Yes|Yes|No|Yes||
|
||||
|AVG_DAILY_VOL_3MONTH|39|Yes|Yes|No|||
|
||||
|BETA|67|Yes|Yes|No|||
|
||||
|EPS|68|Yes|Yes|No|||
|
||||
|PE_RATIO|69|Yes|Yes|No|||
|
||||
|DIV|70|Yes|Yes|No|||
|
||||
|DIV_YIELD|71|Yes|Yes|No|||
|
||||
|EX_DIV_DATE|72|Yes|Yes|No| |yyyy-mm-dd|
|
||||
|PAYOUT_RATIO|73|Yes|No|No|||
|
||||
|EXPIRY_DATE|74|Yes (on options)|No|No| |yyyy-mm-dd|
|
||||
|CLOSE|90|No|No|No|Yes||
|
||||
|ADJ_CLOSE|91|No|No|No|Yes||
|
||||
|SECTOR|98|Yes|Yes|No|||
|
||||
|INDUSTRY|99|Yes|Yes|No|||
|
||||
|TICKER|101|Yes|Yes|Yes|||
|
||||
|EXCHANGE|102|Yes|No|Yes|||
|
||||
|CURRENCY|103|Yes|Yes|Yes|||
|
||||
|NAME|104|Yes|Yes|Yes|||
|
||||
|TIMEZONE|105|Yes|Yes|Yes|||
|
||||
|Name|Code|YAHOO|FT|YAHOO (historic)|Notes|
|
||||
| :--- | :--- | :---: | :---: | :---: | :---: |
|
||||
|PREV_CLOSE|5|Yes|Yes|||
|
||||
|OPEN|6|Yes|Yes|Yes||
|
||||
|CHANGE|7|Yes|Yes|||
|
||||
|LAST_PRICE_DATE|8|Yes|Yes| |yyyy-mm-dd|
|
||||
|LAST_PRICE_TIME|10|Yes|Yes|||
|
||||
|CHANGE_IN_PERCENT|11|Yes|Yes|||
|
||||
|LOW|14|Yes|Yes|Yes||
|
||||
|HIGH|16|Yes|Yes|Yes||
|
||||
|LAST_PRICE|21|Yes|Yes|||
|
||||
|BID|22|Yes|Yes|||
|
||||
|ASK|25|Yes|Yes|||
|
||||
|HIGH_52_WEEK|24|Yes|Yes|||
|
||||
|LOW_52_WEEK|26|Yes|Yes|||
|
||||
|MARKET_CAP|27|Yes|Yes|||
|
||||
|BIDSIZE|30|Yes|Yes|||
|
||||
|ASKSIZE|31|Yes|Yes|||
|
||||
|VOLUME|35|Yes|Yes|Yes||
|
||||
|AVG_DAILY_VOL_3MONTH|39|Yes|Yes|||
|
||||
|BETA|67|Yes|Yes|||
|
||||
|EPS|68|Yes|Yes|||
|
||||
|PE_RATIO|69|Yes|Yes|||
|
||||
|DIV|70|Yes|Yes|||
|
||||
|DIV_YIELD|71|Yes|Yes|||
|
||||
|EX_DIV_DATE|72|Yes|Yes| |yyyy-mm-dd|
|
||||
|PAYOUT_RATIO|73|Yes|No|||
|
||||
|EXPIRY_DATE|74|Yes (on options)|No| |yyyy-mm-dd|
|
||||
|CLOSE|90|No|No|Yes||
|
||||
|ADJ_CLOSE|91|No|No|Yes||
|
||||
|SECTOR|98|Yes|Yes|||
|
||||
|INDUSTRY|99|Yes|Yes|||
|
||||
|TICKER|101|Yes|Yes|||
|
||||
|EXCHANGE|102|Yes|No|||
|
||||
|CURRENCY|103|Yes|Yes|||
|
||||
|NAME|104|Yes|Yes|||
|
||||
|TIMEZONE|105|Yes|Yes|||
|
||||
|
||||
### Dealing with missing data:
|
||||
|
||||
@@ -138,11 +118,13 @@ python3 -m unittest discover src
|
||||
./compile.sh
|
||||
|
||||
### Tested with:
|
||||
- Windows 10 / LibreOffice Calc 7.1.2.2 / Python 3.8.8
|
||||
- Ubuntu 20.04 / LibreOffice Calc 6.4.3.2 / Python 3.8.2
|
||||
|
||||
(Previous versions)
|
||||
- Debian 10.3 / LibreOffice Calc 6.1.5.2 / Python 3.7.3
|
||||
- Ubuntu 20.10 / LibreOffice Calc 7.0.3.1 / Python 3.8.6
|
||||
- Ubuntu 20.04 / LibreOffice Calc 6.4.3.2 / Python 3.8.2
|
||||
- Ubuntu 19.10 / LibreOffice Calc 6.3.5.2 / Python 3.7.6
|
||||
- Ubuntu 19.04 / LibreOffice Calc 6.2 / Python 3.7.3
|
||||
- Ubuntu 18.04.5 / LibreOffice Calc 6 / Python 3.6.9
|
||||
- Ubuntu 18.04 / LibreOffice Calc 6 / Python 3.6.7
|
||||
- Ubuntu 16.04 / LibreOffice Calc 5 (previous versions)
|
||||
|
||||
+21
@@ -38,6 +38,27 @@ cp -f "${PWD}"/src/financials_ft.py "${PWD}"/build/
|
||||
cp -f "${PWD}"/src/financials_google.py "${PWD}"/build/
|
||||
cp -f "${PWD}"/src/financials_yahoo.py "${PWD}"/build/
|
||||
|
||||
# this copies python modules dateutil, pytz, pyparsing to extension so it doesn't have to be installed by user
|
||||
|
||||
TMPFILE=`mktemp`
|
||||
|
||||
wget "https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl" -O $TMPFILE
|
||||
unzip $TMPFILE dateutil/\* -d "${PWD}"/build/
|
||||
rm $TMPFILE
|
||||
|
||||
wget "https://files.pythonhosted.org/packages/70/94/784178ca5dd892a98f113cdd923372024dc04b8d40abe77ca76b5fb90ca6/pytz-2021.1-py2.py3-none-any.whl" -O $TMPFILE
|
||||
unzip $TMPFILE pytz/\* -d "${PWD}"/build/
|
||||
rm $TMPFILE
|
||||
|
||||
wget "https://files.pythonhosted.org/packages/8a/bb/488841f56197b13700afd5658fc279a2025a39e22449b7cf29864669b15d/pyparsing-2.4.7-py2.py3-none-any.whl" -O $TMPFILE
|
||||
unzip $TMPFILE pyparsing.py -d "${PWD}"/build/
|
||||
rm $TMPFILE
|
||||
|
||||
# Windows LibreOffice 7.1 Python is missing this...
|
||||
wget "https://files.pythonhosted.org/packages/ee/ff/48bde5c0f013094d729fe4b0316ba2a24774b3ff1c52d924a8a4cb04078a/six-1.15.0-py2.py3-none-any.whl" -O $TMPFILE
|
||||
unzip $TMPFILE six.py -d "${PWD}"/build/
|
||||
rm $TMPFILE
|
||||
|
||||
echo "Package into oxt file..."
|
||||
pushd "${PWD}"/build/
|
||||
zip -r "${PWD}"/Financials-Extension.zip ./*
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<description xmlns="http://openoffice.org/extensions/description/2006"
|
||||
xmlns:d="http://openoffice.org/extensions/description/2006"
|
||||
xmlns:l="http://libreoffice.org/extensions/description/2011"
|
||||
xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
|
||||
<!-- only used for testing -->
|
||||
|
||||
<dependencies>
|
||||
<l:LibreOffice-minimal-version value="5.0" d:name="LibreOffice 5.0" />
|
||||
</dependencies>
|
||||
|
||||
<identifier value="com.financials.getinfo" />
|
||||
<version value="3.0.0" />
|
||||
<display-name><name lang="en">Financial Market Extension</name></display-name>
|
||||
<publisher><name xlink:href="https://github.com/cmallwitz/Financials-Extension" lang="en">The Publisher</name></publisher>
|
||||
<extension-description><src xlink:href="description-en-US.txt" lang="en" /></extension-description>
|
||||
|
||||
</description>
|
||||
+23
-7
@@ -18,6 +18,7 @@ import sys
|
||||
import time
|
||||
from functools import wraps
|
||||
from importlib import util
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
import unohelper
|
||||
from com.financials.getinfo import Financials
|
||||
@@ -47,12 +48,14 @@ if dateutil_missing or pyparsing_missing or pytz_missing:
|
||||
raise Exception("THIS EXTENSION NEEDS THE FOLLOWING PYTHON 3 LIBRARIES INSTALLED:" + msg)
|
||||
|
||||
import dateutil.parser
|
||||
import pytz
|
||||
import pyparsing
|
||||
import six
|
||||
|
||||
from datacode import Datacode
|
||||
import financials_google as google
|
||||
import financials_yahoo as yahoo
|
||||
import financials_ft as ft
|
||||
from version import version
|
||||
|
||||
implementation_name = "com.financials.getinfo.python.FinancialsImpl" # as defined in Financials.xcu
|
||||
implementation_services = ("com.sun.star.sheet.AddIn",)
|
||||
@@ -120,9 +123,10 @@ class FinancialsImpl(unohelper.Base, Financials):
|
||||
ticker = str(ticker).strip()
|
||||
source = str(source).upper()
|
||||
|
||||
if source == 'GOOGLE':
|
||||
s = self.google.getRealtime(ticker, datacode)
|
||||
elif source == 'YAHOO':
|
||||
# if source == 'GOOGLE':
|
||||
# s = self.google.getRealtime(ticker, datacode)
|
||||
# el
|
||||
if source == 'YAHOO':
|
||||
s = self.yahoo.getRealtime(ticker, datacode)
|
||||
elif source == 'FT':
|
||||
s = self.ft.getRealtime(ticker, datacode)
|
||||
@@ -219,7 +223,14 @@ class FinancialsImpl(unohelper.Base, Financials):
|
||||
@profile
|
||||
def support(self, datacode):
|
||||
|
||||
s = 'ctx={}\nid(self)={}\nversion={}\nfile={}\ncwd={}\nhome={}\nuname={}\npid={}\nsys.executable={}\nsys.version={}\nlocale={}\ndefaultlocale={}'.format(
|
||||
version = '0.0.0'
|
||||
|
||||
description_file = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'description.xml')
|
||||
for e in ET.parse(description_file).getroot():
|
||||
if e.tag.endswith('version'):
|
||||
version = e.attrib['value']
|
||||
|
||||
s = 'ctx={}\nid(self)={}\nversion={}\nfile={}\ncwd={}\nhome={}\nuname={}\npid={}\nsys.executable={}\nsys.version={}\nlocale={}\ndefaultlocale={}\ndateutil={}\npytz={}\npyparsing={}\nsix={}'.format(
|
||||
self.ctx,
|
||||
id(self),
|
||||
version,
|
||||
@@ -231,7 +242,12 @@ class FinancialsImpl(unohelper.Base, Financials):
|
||||
sys.executable,
|
||||
sys.version.replace("\n", " "),
|
||||
locale.getlocale(),
|
||||
locale.getdefaultlocale())
|
||||
locale.getdefaultlocale(),
|
||||
dateutil.__version__,
|
||||
pytz.__version__,
|
||||
pyparsing.__version__,
|
||||
six.__version__,
|
||||
)
|
||||
|
||||
if datacode:
|
||||
s = '{}\ntype(datacode)={}\nstr(datacode)={}'.format(
|
||||
@@ -246,6 +262,6 @@ def createInstance(ctx):
|
||||
return FinancialsImpl(ctx)
|
||||
|
||||
|
||||
# pythonloader looks for a static g_ImplementationHelper variable
|
||||
# python loader looks for a static g_ImplementationHelper variable
|
||||
g_ImplementationHelper = unohelper.ImplementationHelper()
|
||||
g_ImplementationHelper.addImplementation(createInstance, implementation_name, implementation_services, )
|
||||
|
||||
@@ -86,7 +86,8 @@ class FT(BaseClient):
|
||||
return f'FT.getRealtime({ticker}, {datacode}) - urlopen endpoint: {str(e)}'
|
||||
|
||||
try:
|
||||
with open(os.path.join(self.basedir, f'ft-{ticker}.html'), "w", encoding="utf-8") as text_file:
|
||||
temp = ticker.replace(':', '_') # Windows can't have ':' in file names
|
||||
with open(os.path.join(self.basedir, f'ft-{temp}.html'), "w", encoding="utf-8") as text_file:
|
||||
print(f"<!-- '{self.last_url}' -->\r\n\r\n{text}", file=text_file)
|
||||
except BaseException:
|
||||
logger.exception("BaseException ticker=%s datacode=%s %s", ticker, datacode)
|
||||
|
||||
@@ -96,7 +96,8 @@ class Google(BaseClient):
|
||||
return 'Google.getRealtime(\'{}\', {}) - urlopen: {} {}'.format(ticker, datacode, e, url)
|
||||
|
||||
try:
|
||||
with open(os.path.join(self.basedir, 'google-{}.html'.format(ticker)), "w", encoding="utf-8") as text_file:
|
||||
temp = ticker.replace(':', '_') # Windows can't have ':' in file names
|
||||
with open(os.path.join(self.basedir, 'google-{}.html'.format(temp)), "w", encoding="utf-8") as text_file:
|
||||
print(f"<!-- '{url}' -->\r\n\r\n{text}", file=text_file)
|
||||
except BaseException as e:
|
||||
logger.exception("BaseException ticker=%s datacode=%s", ticker, datacode)
|
||||
|
||||
@@ -14,19 +14,13 @@ import os
|
||||
cur_dir = os.getcwd()
|
||||
|
||||
addin_id = "com.financials.getinfo"
|
||||
addin_version = "2.6.0"
|
||||
addin_version = "3.0.0"
|
||||
addin_displayname = "Financial Market Extension"
|
||||
addin_publisher_link = "https://github.com/cmallwitz/Financials-Extension"
|
||||
addin_publisher_name = "The Publisher"
|
||||
|
||||
print("Generating extension files for version", addin_version)
|
||||
|
||||
################################################################################
|
||||
# version.py
|
||||
|
||||
version_file = open(cur_dir + '/build/version.py', 'w')
|
||||
version_file.write(f"version = '{addin_version}'")
|
||||
version_file.close()
|
||||
|
||||
################################################################################
|
||||
# description.xml
|
||||
|
||||
+2
-27
@@ -20,7 +20,8 @@ from datacode import Datacode
|
||||
financials = financials.createInstance(None)
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
# class Test(unittest.TestCase):
|
||||
class Test:
|
||||
|
||||
def test_currency(self):
|
||||
s = financials.getRealtime('EURGBP', Datacode.LAST_PRICE.value, 'GOOGLE')
|
||||
@@ -249,32 +250,6 @@ class Test(unittest.TestCase):
|
||||
s = financials.getRealtime('NYS:IBM', Datacode.LAST_PRICE.value, cell_range)
|
||||
self.assertEqual(s, 'Cell range not allowed for source', 'test_errors')
|
||||
|
||||
def test_support(self):
|
||||
cell_range = ((1, 2), ('3', '4'), (5.0, 6.0))
|
||||
|
||||
s = financials.getRealtime('SUPPORT')
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', 1)
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'int'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=1" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', 1.0)
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'float'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=1.0" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', '1')
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'str'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=1" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', cell_range)
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'tuple'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=((1, 2), ('3', '4'), (5.0, 6.0))" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
# test_google.py
|
||||
#
|
||||
# license: GNU LGPL
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 3 of the License, or (at your option) any later version.
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
logging.basicConfig(level=logging.ERROR, format="%(asctime)s %(name)s %(levelname)s %(message)s")
|
||||
|
||||
import financials
|
||||
|
||||
financials = financials.createInstance(None)
|
||||
|
||||
|
||||
class Test(unittest.TestCase):
|
||||
|
||||
def test_support(self):
|
||||
cell_range = ((1, 2), ('3', '4'), (5.0, 6.0))
|
||||
|
||||
s = financials.getRealtime('SUPPORT')
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("version=3.0.0" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', 1)
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'int'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=1" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', 1.0)
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'float'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=1.0" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', '1')
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'str'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=1" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('SUPPORT', cell_range)
|
||||
self.assertTrue(s.startswith("ctx="), 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("type(datacode)=<class 'tuple'>" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
self.assertTrue("str(datacode)=((1, 2), ('3', '4'), (5.0, 6.0))" in s, 'test_errors SUPPORT {}'.format(s))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('unittest_args', nargs='*')
|
||||
args = parser.parse_args()
|
||||
unit_argv = [sys.argv[0]] + args.unittest_args
|
||||
unittest.main(argv=unit_argv)
|
||||
+14
-20
@@ -125,37 +125,39 @@ class Test(unittest.TestCase):
|
||||
|
||||
def test_realtime_US_options(self):
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.PREV_CLOSE.value, 'YAHOO')
|
||||
# symbol from https://finance.yahoo.com/quote/IBM/options?p=IBM
|
||||
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.PREV_CLOSE.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options PREV_CLOSE {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.NAME.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.NAME.value, 'YAHOO')
|
||||
self.assertEqual(str, type(s), 'test_realtime_US_options NAME {}'.format(s))
|
||||
self.assertEqual('IBM Jun 2021 90.000 call', s, 'test_realtime_US_options NAME {}'.format(s))
|
||||
self.assertEqual('IBM Jan 2023 130.000 call', s, 'test_realtime_US_options NAME {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.EXPIRY_DATE.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.EXPIRY_DATE.value, 'YAHOO')
|
||||
self.assertEqual(str, type(s), 'test_realtime_US_options EXPIRY_DATE {}'.format(s))
|
||||
self.assertTrue(testutils.is_date(s), 'test_realtime_US_options EXPIRY_DATE {}'.format(s))
|
||||
self.assertEqual("2021-06-18", s, 'test_realtime_US_options EXPIRY_DATE {}'.format(s))
|
||||
self.assertEqual("2023-01-20", s, 'test_realtime_US_options EXPIRY_DATE {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.LAST_PRICE.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.LAST_PRICE.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options LAST_PRICE {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.OPEN.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.OPEN.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options OPEN {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.VOLUME.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.VOLUME.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options VOLUME {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.BID.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.BID.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options BID {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.ASK.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.ASK.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options ASK {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.BIDSIZE.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.BIDSIZE.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options BIDSIZE {}'.format(s))
|
||||
|
||||
s = financials.getRealtime('IBM210618C00090000', Datacode.ASKSIZE.value, 'YAHOO')
|
||||
s = financials.getRealtime('IBM230120C00130000', Datacode.ASKSIZE.value, 'YAHOO')
|
||||
self.assertEqual(float, type(s), 'test_realtime_US_options ASKSIZE {}'.format(s))
|
||||
|
||||
def test_realtime_UK_ETF(self):
|
||||
@@ -272,14 +274,6 @@ class Test(unittest.TestCase):
|
||||
|
||||
financials.yahoo.historicdata = {}
|
||||
|
||||
# Inception Date 2014-09-30
|
||||
s = financials.getHistoric('VERX.L', Datacode.CLOSE.value, '2018-04-02', 'YAHOO') # Easter Monday
|
||||
self.assertEqual(s, 'Not a trading day \'2018-04-02\'', 'test_historic_UK_ETF CLOSE {}'.format(s))
|
||||
|
||||
# Inception Date 2014-09-30
|
||||
s = financials.getHistoric('VERX.L', Datacode.CLOSE.value, '2015-01-01', 'YAHOO')
|
||||
self.assertEqual(s, 'Not a trading day \'2015-01-01\'', 'test_historic_UK_ETF CLOSE {}'.format(s))
|
||||
|
||||
s = financials.getHistoric('VERX.L', Datacode.LAST_PRICE.value, '2017-01-01', 'YAHOO')
|
||||
self.assertEqual(s, 'Not a trading day \'2017-01-01\'', 'test_historic_UK_ETF LAST_PRICE {}'.format(s))
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
# version.py
|
||||
#
|
||||
# license: GNU LGPL
|
||||
#
|
||||
# This library is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public
|
||||
# License as published by the Free Software Foundation; either
|
||||
# version 3 of the License, or (at your option) any later version.
|
||||
|
||||
# This file will not be actually used as it is regenerated with the correct build version
|
||||
# by generate_metainfo.py in the "compile" step
|
||||
|
||||
# This is a bit of a hack but I can't find out how to access the version in description.xml once deployed
|
||||
|
||||
version = '0.0.0'
|
||||
Reference in New Issue
Block a user