Beispiel #1
0
## OR OTHERWISE ARISING FROM, OUT OF, OR IN CONNECTION WITH THE WORK OR THE USE
## OF OR OTHER DEALINGS IN THE WORK.
##

from cfetch import register_ticker, NoSuchKindException, NoSuchPairException
from cfetch import Ticker
from requests import get

class BitstampTicker(Ticker):
    def __init__(self, path):
        super().__init__(path)

    def get_pair_data(self, response):
        return response.json()

    def get_rate(self, a, b, amt=1, kind='vwap'):
        r = get(self.path)
        res = self.get_pair_data(r)
        if kind not in res:
            raise NoSuchKindException('Kind {} not available'.format(kind))

        if a == 'btc' and b == 'usd':
            return float(res[kind]) * amt
        elif a == 'usd' and b == 'btc':
            return (float(res[kind]) ** -1) * amt
        else:
            raise NoSuchPairException('{}/{}'.format(a, b))

register_ticker('bs', 'The Bitstamp ticker (built-in)',
                BitstampTicker('https://www.bitstamp.net/api/ticker/'))
Beispiel #2
0
##
##  coinfetch-api-ccc - CryptoCoin Charts API plugin for coinfetch
##  Copyright (C) 2015 Delwink, LLC
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU Affero General Public License as published by
##  the Free Software Foundation, version 3 only.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU Affero General Public License for more details.
##
##  You should have received a copy of the GNU Affero General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

from cfetch import register_ticker, Ticker

class CccTicker(Ticker):
    def __init__(self, path, kind='price'):
        super().__init__(path, kind)

    def get_pair_data(self, response, pair=None):
        return response.json()

register_ticker('ccc', 'The CryptoCoin Charts ticker (built-in)',
                CccTicker('http://api.cryptocoincharts.info/tradingPair/'))
Beispiel #3
0
from cfetch import register_ticker, NoSuchKindException, NoSuchPairException
from cfetch import Ticker


class CccTicker(Ticker):
    def __init__(self, path):
        super().__init__(path)

    def get_pair_data(self, response, pair=None):
        return response.json()

    def get_rate_pow(self, a, b, amt, power, kind):
        r = get(self.path + self.get_pair(a, b))
        res = self.get_pair_data(r, (a, b))

        if kind not in res:
            raise NoSuchKindException(kind)

        if res[kind] is None:
            raise NoSuchPairException('{}/{}'.format(a, b))

        return (float(res[kind])**power) * amt

    def get_rate(self, a, b, amt=1, kind='price'):
        return super().get_rate(a, b, amt, kind)


register_ticker('ccc', 'The CryptoCoin Charts ticker (built-in)',
                CccTicker('http://api.cryptocoincharts.info/tradingPair/'))
Beispiel #4
0
##
##  coinfetch-api-bter - BTer API plugin for coinfetch
##  Copyright (C) 2015 Delwink, LLC
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU Affero General Public License as published by
##  the Free Software Foundation, version 3 only.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU Affero General Public License for more details.
##
##  You should have received a copy of the GNU Affero General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

from cfetch import register_ticker, Ticker


class BterTicker(Ticker):
    def get_pair_data(self, response, pair=None):
        return response.json()


register_ticker('bter', 'The BTer ticker (built-in)',
                BterTicker('http://data.bter.com/api/1/ticker/'))
Beispiel #5
0
    def get_rate(self, a, b, amt=1):
        a = a.upper()
        b = b.upper()
        if 'BTC' not in (a, b):
            self._fail(a, b)

        r = get(self.path)
        res = self.get_pair_data(r)

        try:
            if a == 'BTC':
                if b not in res:
                    self._fail(a, b)

                res = res[b]
                return float(res[self.kind]) * amt

            if a not in res:
                self._fail(a, b)

            res = res[a]
            return (float(res[self.kind]) ** -1) * amt
        except (KeyError, TypeError) as e:
            raise ValueError(str(e))

    def _fail(self, a, b):
        raise ValueError('{}/{}'.format(a, b))

register_ticker('ba', 'The BitcoinAverage ticker (built-in)',
                BitcoinAverageTicker('https://api.bitcoinaverage.com/ticker/all'))
Beispiel #6
0
##  You should have received a copy of the GNU Affero General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

from cfetch import register_ticker, Ticker
from requests import get


class BitstampTicker(Ticker):
    def __init__(self, path, kind='vwap'):
        super().__init__(path, kind)

    def get_pair_data(self, response):
        return response.json()

    def get_rate(self, a, b, amt=1):
        if a == 'btc' and b == 'usd':
            r = get(self.path)
            res = self.get_pair_data(r)
            return float(res[self.kind]) * amt
        elif a == 'usd' and b == 'btc':
            r = get(self.path)
            res = self.get_pair_data(r)
            return (float(res[self.kind])**-1) * amt
        else:
            raise ValueError('{}/{}'.format(a, b))


register_ticker('bs', 'The Bitstamp ticker (built-in)',
                BitstampTicker('https://www.bitstamp.net/api/ticker/'))
Beispiel #7
0
    def __init__(self, path):
        super().__init__(path)

    def get_pair(self, a, b):
        return '{}-{}'.format(a.upper(), b.upper())

    def get_pair_data(self, response, pair=None):
        return response.json()

    def get_rate_pow(self, a, b, amt, power, kind):
        if kind not in ('spot', 'buy', 'sell'):
            raise NoSuchKindException(kind)

        r = get(self.path + self.get_pair(a, b) + '/' + kind,
                headers={'CB-VERSION': '2017-09-19'})

        res = self.get_pair_data(r, (a, b))
        if 'data' not in res:
            raise NoSuchPairException('{}/{}'.format(a, b))

        if 'errors' in res:
            raise Exception(res['errors'])

        return (float(res['data']['amount']) ** power) * amt

    def get_rate(self, a, b, amt=1, kind='spot'):
        return super().get_rate(a, b, amt, kind)

register_ticker('cb', 'The Coinbase ticker (built-in)',
                CoinbaseTicker('https://api.coinbase.com/v2/prices/'))
Beispiel #8
0
##
##  coinfetch-api-bter - BTer API plugin for coinfetch
##  Copyright (C) 2015 Delwink, LLC
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU Affero General Public License as published by
##  the Free Software Foundation, version 3 only.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU Affero General Public License for more details.
##
##  You should have received a copy of the GNU Affero General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

from cfetch import register_ticker, Ticker

class BterTicker(Ticker):
    def get_pair_data(self, response, pair=None):
        return response.json()

register_ticker('bter', 'The BTer ticker (built-in)',
                BterTicker('http://data.bter.com/api/1/ticker/'))
Beispiel #9
0
##
##  coinfetch-api-btce - BTC-E API plugin for coinfetch
##  Copyright (C) 2015 Delwink, LLC
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU Affero General Public License as published by
##  the Free Software Foundation, version 3 only.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU Affero General Public License for more details.
##
##  You should have received a copy of the GNU Affero General Public License
##  along with this program.  If not, see <http://www.gnu.org/licenses/>.
##

from cfetch import register_ticker, Ticker

register_ticker('btce', 'The BTC-E ticker (built-in)',
                Ticker('https://btc-e.com/api/3/ticker/'))