diff --git a/README.md b/README.md index 42567ea..f1483d6 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,21 @@ # pybitx -BitX API for python +BitX API for python ([See API documentation](https://www.luno.com/en/api)). # Installation +```bash +pip install pybitx +``` + +#### For Developers +Clone this repo and create a virtual environment +```bash +git clone https://github.com/CjS77/pybitx +cd pybitx +virtualenv -p /usr/bin/python2.7 env +source env/bin/activate +pip install -e .[dev] +python2.7 tests/test_api.py # For good measure +``` # Usage diff --git a/demo.py b/demo.py index 8c9daca..f0d7a3b 100644 --- a/demo.py +++ b/demo.py @@ -1,16 +1,20 @@ -from pybitx.api import BitX +from __future__ import print_function + import os import pprint +from pybitx.api import BitX + + pp = pprint.PrettyPrinter(indent=4, width=80) def format_call(name, results): - print '-'*80 - print '%50s' % (name,) - print '-'*80 + print('-'*80) + print('%50s' % (name,)) + print('-'*80) pp.pprint(results) - print '-'*80 + print('-'*80) def runDemo(): @@ -21,9 +25,9 @@ def runDemo(): user = os.environ['BITX_KEY'] password = os.environ['BITX_SECRET'] else: - print "Note: I couldn't find a BITX_KEY environment variable. This means that none of the API queries\nthat " \ - "require authentication will work. I'll carry on anyway, but make sure your credentials are available " \ - "in the BITX_KEY and BITX_SECRET environment variables and run this demo again" + print("Note: I couldn't find a BITX_KEY environment variable. This means that none of the API queries\nthat " + "require authentication will work. I'll carry on anyway, but make sure your credentials are available " + "in the BITX_KEY and BITX_SECRET environment variables and run this demo again") api = BitX(user, password) kind = 'auth' if auth else 'none' format_call(' Ticker ', api.get_ticker(kind)) diff --git a/pybitx/__init__.py b/pybitx/__init__.py index e0a914a..8945943 100644 --- a/pybitx/__init__.py +++ b/pybitx/__init__.py @@ -1,4 +1,4 @@ -import meta -from api import BitX +__version__ = "0.1.10" -__version__ = meta.version + +from pybitx.api import BitX \ No newline at end of file diff --git a/pybitx/api.py b/pybitx/api.py index 7aacd21..b0e516d 100644 --- a/pybitx/api.py +++ b/pybitx/api.py @@ -1,11 +1,10 @@ import requests import logging from concurrent.futures import ThreadPoolExecutor -from meta import version +from pybitx import __version__ import pandas as pd import json -__version__ = version log = logging.getLogger(__name__) diff --git a/pybitx/meta.py b/pybitx/meta.py deleted file mode 100644 index 1ee2704..0000000 --- a/pybitx/meta.py +++ /dev/null @@ -1 +0,0 @@ -version = "0.1.10" diff --git a/setup.py b/setup.py index cef5496..1b71ca1 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,25 @@ +import os +import re + from setuptools import setup, find_packages -import pybitx + + +# Extract the version from the main package __init__ file +PATTERN = '__version__\s+=\s+(?P.*)' +BASE_DIR = os.path.dirname(__file__) + +with open(os.path.join(BASE_DIR, 'pybitx/__init__.py'), 'r') as f: + match = re.search(PATTERN, f.read()) + +if match is None: + raise ValueError("failed to extract package version") + +version = match.groupdict()['version'] + setup( name='pybitx', - version=pybitx.__version__, + version=version, packages=find_packages(exclude=['tests']), description='A BitX API for Python', author='Cayle Sharrock', @@ -17,11 +33,9 @@ ], license='MIT', url='https://github.com/CjS77/pybitx', - download_url='https://github.com/CjS77/pybitx/tarball/%s' % (pybitx.__version__, ), + download_url='https://github.com/CjS77/pybitx/tarball/%s' % (version, ), keywords='BitX Bitcoin exchange API', classifiers=[], test_suite='tests', - tests_require=[ - 'requests-mock>=0.7.0' - ] + extras_require={'dev': ['requests-mock>=0.7.0']} ) diff --git a/tests/test_api.py b/tests/test_api.py index 668cf46..55a8f9c 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,8 +1,9 @@ +import base64 import unittest import requests_mock -import api + +from pybitx import api from pybitx.api import BitX, BitXAPIError -import base64 class TestBitX(unittest.TestCase): @@ -66,8 +67,8 @@ class TestAPICalls(unittest.TestCase): @staticmethod def make_auth_header(auth): s = ':'.join(auth) - k = base64.b64encode(s) - return 'Basic %s' % (k,) + k = base64.b64encode(s.encode('utf-8')) + return 'Basic %s' % (k.decode('utf-8'),) def setUp(self): options = {