Skip to content
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
18 changes: 18 additions & 0 deletions exchanges/cex.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from exchanges.base import Exchange


class Cex(Exchange):

TICKER_URL = 'https://cex.io/api/ticker/BTC/USD'

@classmethod
def _current_price_extractor(cls, data):
return data.get('last')

@classmethod
def _current_bid_extractor(cls, data):
return data.get('bid')

@classmethod
def _current_ask_extractor(cls, data):
return data.get('ask')
28 changes: 28 additions & 0 deletions exchanges/coinbase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from decimal import Decimal

from exchanges.base import Exchange
from exchanges.helpers import get_response


class Coinbase(Exchange):

TICKER_URL = 'https://api.coinbase.com/v2/prices/BTC-{}/{}'

@classmethod
def _get_current_price(cls, currency='USD', price_type='spot'):
url = cls.TICKER_URL.format(currency, price_type)
data = get_response(url)
price = data.get('data').get('amount')
return Decimal(price)

@classmethod
def get_current_price(cls, currency='USD'):
return cls._get_current_price(currency=currency, price_type='spot')

@classmethod
def get_current_bid(cls, currency='USD'):
return cls._get_current_price(currency=currency, price_type='buy')

@classmethod
def get_current_ask(cls, currency='USD'):
return cls._get_current_price(currency=currency, price_type='sell')
50 changes: 50 additions & 0 deletions exchanges/gemini.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from datetime import datetime, timedelta
from decimal import Decimal
from exchanges.base import Exchange
from helpers import get_response


class Gemini(Exchange):

TICKER_URL = 'https://api.gemini.com/v1/pubticker/btcusd'

@classmethod
def _current_price_extractor(cls, data):
return data.get('last')

@classmethod
def _current_bid_extractor(cls, data):
return data.get('bid')

@classmethod
def _current_ask_extractor(cls, data):
return data.get('ask')

@classmethod
def get_historical_data_as_dict(cls, start='2013-09-01'):
start_date = datetime.strptime(start, '%Y-%m-%d')
delta = datetime.today() - start_date
days = [start_date + timedelta(x) for x in range(delta.days + 1)]
data = map(cls._get_historical_data, days)
prices = {datetime.strftime(k, '%Y-%m-%d'): Decimal(str(v['price']))
for (k,v) in zip(days, data)}
return prices

@classmethod
def get_historical_data_as_list(cls, start='2013-09-01'):
pass
start_date = datetime.strptime(start, '%Y-%m-%d')
delta = datetime.today() - start_date
days = [start_date + timedelta(x) for x in range(delta.days + 1)]
data = map(lambda day: cls._get_historical_data(day), days)
ret = [
{'date': datetime.strftime(k, '%Y-%m-%d'),
'price': Decimal(str(v['price']))}
for (k,v) in zip(days, data)
]
return ret

@classmethod
def _get_historical_data(cls, day):
url = 'https://api.gemini.com/v1/trades/btcusd?since=%s&limit_trades=1'
return get_response(url % day.strftime('%s'))[0]
12 changes: 5 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
# Copyright (C) 2015 Bitquant Research Laboratories (Asia) Limited
# Released under the Simplified BSD License

from setuptools import (
setup,
find_packages,
)
from setuptools import setup


setup(
name='bitcoin-price-api',
version = '0.0.4',
version='0.0.5',
author='Matthew Madurski',
author_email='madurskimr@gmail.com',
url='https://github.com/dursk/bitcoin-price-api',
description="API's for bitcoin exchanges",
long_description='''Price API's for bitcoin exchanges''',
license='MIT',
packages=['exchanges'],
install_requires = ['requests', 'python-dateutil'],
use_2to3 = True
install_requires=['python-dateutil==2.4.2', 'requests==2.9.1'],
use_2to3=True
)