コード例 #1
0
    def test_class_can_cache_api_data_3(self):
        """this test will simulate an interation with the class, the test will do some
        requests at different time and it'll see if the cache will hit the correct
        number of times
        """

        max_requests = 30
        my_class = coinmarketcapapi.CoinMarketCapAPI(max_request_per_minute=max_requests)

        delay_seconds = 60/max_requests
        n_of_requests = 5
        expected_cache_calls = 0
        total_cache_calls = 0

        for step in range(n_of_requests):
            my_class.send_request() # Server request
            #if my_class._n_cache_hits != 0:
            if my_class.cache.get_n_cache_hits() != 0:
                total_cache_calls += 1

            #random numbers generated securely
            delay_time = secrets.choice([1, 2, 3])

            time.sleep(delay_time)

            if (delay_time < delay_seconds) and step < 4: # less than last step, range is 0,1,2,3,4
                expected_cache_calls += 1

        self.assertEqual(total_cache_calls, expected_cache_calls)
コード例 #2
0
    def __init__(self, cmc_api_key='6d7f5365-d3c4-4210-804e-c3c36302499d'):
        self.___CMC_API_KEY = cmc_api_key
        self.___cmc = cmc.CoinMarketCapAPI(self.___CMC_API_KEY, sandbox=False)

        # THIS API CALL COSTS CREDITS
        # self.___fiat_data = self.___cmc.fiat_map().data

        self.coin_list = coin.get_coin_list(coins='all')
        self.___coin_symbols___ = list(self.coin_list.keys())
コード例 #3
0
    def test_class_can_cache_api_data_2(self):
        """This test will simulate an interation with the class making a request
        every 3 seconds (under the cache time), so the cache should be hit 0 times
        """
        my_class = coinmarketcapapi.CoinMarketCapAPI(max_request_per_minute=30)
        times_of_request = 5

        for _ in range(times_of_request):
            my_class.send_request(convert="EUR")
            time.sleep(3)

         #self.assertEqual(my_class._n_cache_hits, 0)
        self.assertEqual(my_class.cache.get_n_cache_hits(), 0)
コード例 #4
0
    def test_force_full_cache(self):
        """This test will test the "force full test" mechanism
        """

        my_class = coinmarketcapapi.CoinMarketCapAPI(30, True)
        #max requests per minute 30
        #full cache mechanism True

        my_class.send_request(endpoint='ticker')

        time.sleep(3)
        my_class.send_request(endpoint='ticker')

        self.assertTrue(bool(my_class.cache._cached_api_global_response), True)
コード例 #5
0
    def test_class_can_cache_api_data_1(self):
        """This test will simulate an interation with the class making a request
        ina for loop, so the cache should be hit n times (where n is the number of
        for iterations) - 1 because the first one is always a call to the server
        (the cache is initially empty)
        """
        my_class = coinmarketcapapi.CoinMarketCapAPI(max_request_per_minute=9)
        times_of_request = 5

        for _ in range(times_of_request):
            my_class.send_request(convert="EUR")


        #self.assertEqual(my_class._n_cache_hits, times_of_request - 1)
        self.assertEqual(my_class.cache.get_n_cache_hits(), times_of_request - 1)
コード例 #6
0
class CacheTestCase(unittest.TestCase):
    """Test class
    """

    my_class = coinmarketcapapi.CoinMarketCapAPI()

    def test_error_status_code_not_200(self):
        response = requests.get("http://www.google.com/invalidpage")

        with self.assertRaises(errors.APICallFailed):
            self.my_class._response_is_valid(response)

    def test_error_from_api_server(self):
        response = requests.get(
            "https://api.coinmarketcap.com/v1/ticker/btcoin/")
        # URL should be ../bitcoin/

        with self.assertRaises(errors.APICallFailed):
            self.my_class._response_is_valid(response)
コード例 #7
0
ファイル: stats.py プロジェクト: SarahKay99/CryptoCalc
        - Exchange map: 
        - Exchange listings: 
        - Exchange market pairs: 
        - Exchange quotes latest: 
        - Exchange quotes historical: 
        - Global metrics quotes historical:
        - Price performance latest
        - Exchange listings historical
        - Globalmetrics quotes historical
        - Blockchain statistics latest
"""

coin = input("Enter your coin: ")

API_KEY = '6d7f5365-d3c4-4210-804e-c3c36302499d'
cmc = c.CoinMarketCapAPI(API_KEY, sandbox=False)

# market = c.CoinMarketCap()
# overall_data = market.stats(convert=coin)
# coin_list = market.coin_list()
# coin_detail = market.coin_ticker_detail(1, convert="CNY", disable_cache=False)

coin_data = {
    "info": cmc.cryptocurrency_info(symbol=coin),
    "map": cmc.cryptocurrency_map(symbol=coin),
    "latest_listing": cmc.cryptocurrency_listings_latest(),
    "quotes_latest": cmc.cryptocurrency_quotes_latest(symbol=coin),
    "fiat_map": cmc.fiat_map(),
    "fcas_listings_latest": cmc.partners_flipsidecrypto_fcas_listings_latest(),
    "fcas_quotes_latest": cmc.partners_flipsidecrypto_fcas_quotes_latest(symbol=coin),
    "key_info": cmc.key_info(symbol=coin),
コード例 #8
0
import pandas as pd
import os
from binance_exchange_api.rest import api_caller
import datetime as dt
coin_data = []
exchange_info = api_caller.get_exchange_info()
from config.config import COIN_MKTCAP_CONFIG

coins = [ a['baseAsset'] for a in exchange_info['symbols'] if (a['symbol'][-3:]=='BTC') and a['status']=='TRADING']

import coinmarketcapapi
api_key =     COIN_MKTCAP_CONFIG['api_keys'][0]['api_key']


api = coinmarketcapapi.CoinMarketCapAPI(api_key)
listings_cap_max_10000= api.cryptocurrency_listings_latest(market_cap_max=10000, limit = 5000)
listings_cap_min_10000= api.cryptocurrency_listings_latest(market_cap_min=10000, limit = 5000)
hnn = set([a['symbol'] for a in listings_cap_min_10000.data if a['quote']['USD']['volume_24h']>200000000 ]).intersection(set(coins))
lnn = set([a['symbol'] for a in listings_cap_max_10000.data if a['quote']['USD']['volume_24h']>200000 ]).intersection(set(coins))
print("A")