How to use pycoingecko - 10 common examples

To help you get started, weโ€™ve selected a few pycoingecko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github man-c / pycoingecko / tests / test_api.py View on Github external
def test_get_exchanges_id_name_list(self):
        # Arrange
        json_response = [{'id': 'abcc', 'name': 'ABCC'}, {'id': 'acx', 'name': 'ACX'}, {'id': 'airswap', 'name': 'AirSwap'}]

        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/exchanges/list',
                          json = json_response, status = 200)

        # Act
        response = CoinGeckoAPI().get_exchanges_id_name_list()

        ## Assert
        assert response == json_response
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_failed_get_global(self):
        # Arrange
        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/global',
                          status = 404)
        exception = HTTPError("HTTP Error")

        # Act Assert
        with pytest.raises(HTTPError) as HE:
            CoinGeckoAPI().get_global()
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_failed_get_coins_markets(self):
        # Arrange
        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd',
                          status = 404)
        exception = HTTPError("HTTP Error")

        # Act Assert
        with pytest.raises(HTTPError) as HE:
            CoinGeckoAPI().get_coins_markets('usd')
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_failed_get_exchanges_by_id(self):
        # Arrange
        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/exchanges/bitforex',
                          status = 404)
        exception = HTTPError("HTTP Error")

        # Act Assert
        with pytest.raises(HTTPError) as HE:
            CoinGeckoAPI().get_exchanges_by_id('bitforex')
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_get_supported_vs_currencies(self):
        # Arrange
        coins_json_sample = ['btc', 'eth', 'ltc', 'bch', 'bnb', 'eos', 'xrp', 'xlm', 'usd', 'aed', 'ars', 'aud', 'bdt', 'bhd', 'bmd', 'brl', 'cad', 'chf', 'clp', 'cny', 'czk', 'dkk', 'eur', 'gbp', 'hkd', 'huf', 'idr', 'ils', 'inr', 'jpy', 'krw', 'kwd', 'lkr', 'mmk', 'mxn', 'myr', 'nok', 'nzd', 'php', 'pkr', 'pln', 'rub', 'sar', 'sek', 'sgd', 'thb', 'try', 'twd', 'uah', 'vef', 'vnd', 'zar', 'xdr', 'xag', 'xau']

        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/simple/supported_vs_currencies',
                          json = coins_json_sample, status = 200)

        # Act
        response = CoinGeckoAPI().get_supported_vs_currencies()

        ## Assert
        assert response == coins_json_sample
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_ping(self):
        # Arrange
        ping_json = { 'gecko_says':'(V3) To the Moon!' }
        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/ping',
                          json = ping_json, status = 200)

        # Act
        response = CoinGeckoAPI().ping()

        ## Assert
        assert response == ping_json
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_failed_get_price(self):
        # Arrange
        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd',
                          status = 404)
        exception = HTTPError("HTTP Error")

        # Act Assert
        with pytest.raises(HTTPError) as HE:
            CoinGeckoAPI().get_price('bitcoin', 'usd')
github man-c / pycoingecko / tests / test_api.py View on Github external
def test_failed_get_exchanges_list(self):
        # Arrange
        responses.add(responses.GET, 'https://api.coingecko.com/api/v3/exchanges',
                          status = 404)
        exception = HTTPError("HTTP Error")

        # Act Assert
        with pytest.raises(HTTPError) as HE:
            CoinGeckoAPI().get_exchanges_list()
github josai / crypto-arbitrage / exchange_compare.py View on Github external
def get_coin_pair_data(exclude=[], include=[]):
    cg = CoinGeckoAPI()
    coins = cg.get_coins_list()
    random.shuffle(coins)
    coin_data = []
    for coin in coins:
        try:
            market_data = cg.get_coin_by_id(coin['id'])['tickers']
            pairs_data = []
            for i in market_data:
                market = i['market']['name']
                price = float(i['converted_last']['usd'])
                volume = float(i['converted_volume']['usd'])
                info = {'market': market,
                        'price': price,
                        'target': i['target'],
                        'volume': volume
                        }
github BTS-CM / Bitshares-HUG-REST-API / hug_script.py View on Github external
# Getting the value of USD in BTS
		#market = Market("USD:BTS") # Set reference market to USD:BTS
		#price = market.ticker()["quoteSettlement_price"] # Get Settlement price of USD
		#price.invert() # Switching from quantity of BTS per USD to USD price of one BTS.

		hertz_reference_timestamp = "2015-10-13T14:12:24+00:00" # Bitshares 2.0 genesis block timestamp
		hertz_current_timestamp = pendulum.now().timestamp() # Current timestamp for reference within the hertz script
		hertz_amplitude = 0.14 # 14% fluctuating the price feed $+-0.14 (1% per day)
		hertz_period_days = 28 # Aka wavelength, time for one full SIN wave cycle.
		hertz_phase_days = 0.908056 # Time offset from genesis till the first wednesday, to set wednesday as the primary Hz day.
		hertz_reference_asset_value = 1.00 # $1.00 USD, not much point changing as the ratio will be the same.

		hertz_value = get_hertz_feed(hertz_reference_timestamp, hertz_current_timestamp, hertz_period_days, hertz_phase_days, hertz_reference_asset_value, hertz_amplitude)
		hertz = Price(hertz_value, "USD/HERTZ") # Limit the hertz_usd decimal places & convert from float.

		cg = CoinGeckoAPI() # Initialise coingecko
		bts_usd_coingecko = cg.get_price(ids='bitshares', vs_currencies='usd') # Price of BTS in USD from coingecko
		bts_usd_coingecko_value = Price(bts_usd_coingecko["bitshares"]["usd"], "USD/BTS") # Price format
		hertz_bts = bts_usd_coingecko_value.invert() * hertz.as_quote("HERTZ") # Feed price

		unofficial_data = {
			'hertz_price_in_usd': hertz['price'],
			'hertz_price_in_bts': hertz_bts['price'],
			'core_exchange_rate': hertz_bts['price']*0.80,
			'usd_price_in_bts': 1/(bts_usd_coingecko["bitshares"]["usd"]),
			'bts_price_in_usd': bts_usd_coingecko["bitshares"]["usd"]
		}
		########

		try:
		  target_asset = Asset("HERTZ", full=True)
		except:

pycoingecko

Python wrapper around the CoinGecko API

MIT
Latest version published 9 days ago

Package Health Score

76 / 100
Full package analysis