Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 support #12

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
20 changes: 12 additions & 8 deletions demo.py
Original file line number Diff line number Diff line change
@@ -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():
Expand All @@ -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))
Expand Down
6 changes: 3 additions & 3 deletions pybitx/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import meta
from api import BitX
__version__ = "0.1.10"

__version__ = meta.version

from pybitx.api import BitX
3 changes: 1 addition & 2 deletions pybitx/api.py
Original file line number Diff line number Diff line change
@@ -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__)

Expand Down
1 change: 0 additions & 1 deletion pybitx/meta.py

This file was deleted.

26 changes: 20 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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<version>.*)'
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',
Expand All @@ -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']}
)
9 changes: 5 additions & 4 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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 = {
Expand Down