コード例 #1
0
ファイル: bitstamp.py プロジェクト: delwink/coinfetch
## 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/'))
コード例 #2
0
ファイル: ccc.py プロジェクト: aussiehash/Pycointick
##
##  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/'))
コード例 #3
0
ファイル: ccc.py プロジェクト: justyntemme/coinfetch
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/'))
コード例 #4
0
ファイル: bter.py プロジェクト: aussiehash/Pycointick
##
##  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/'))
コード例 #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'))
コード例 #6
0
ファイル: bitstamp.py プロジェクト: aussiehash/Pycointick
##  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/'))
コード例 #7
0
ファイル: cb.py プロジェクト: delwink/coinfetch
    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/'))
コード例 #8
0
ファイル: bter.py プロジェクト: aussiehash/Pycointick
##
##  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/'))
コード例 #9
0
ファイル: btce.py プロジェクト: aussiehash/Pycointick
##
##  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/'))