def scrapeMarketCap(slug, numDays, includeVolume=False): """Scrape market cap for the specified currency slug.""" jsonDump = coinmarketcap.requestMarketCap(slug, numDays) _saveToFile( jsonDump, 'marketcap_{0}_{1}d'.format(slug, numDays), 'json') result = coinmarketcap.parseMarketCap( jsonDump, pg.selectCurrencyId(slug), includeVolume=includeVolume) if includeVolume: data, volData = result pg.insertMarketCapVolume(volData) else: data = result pg.insertMarketCap(data, numDays)
def scrapeMarketCap(slug, name, type): """Scrape market cap for the specified coin or token slug.""" jsonDump = coinmarketcap.requestMarketCap(slug) result = coinmarketcap.parseMarketCap(jsonDump, slug) database.batch_entry(result, name, type) return result[-1]['market_cap_by_available_supply'] < args.min_market_cap
def scrapeMarketCap(slug, name, type): """Scrape market cap for the specified currency slug.""" jsonDump = coinmarketcap.requestMarketCap(slug) result = coinmarketcap.parseMarketCap(jsonDump, slug) database.batch_entry(result, name, type)
def testInsertMarketCap(self): """Test insertMarketCap and insertMarketCapVolume functions.""" f = open( "{0}/example/marketcap_navajo_7d.json".format( os.path.dirname(os.path.abspath(__file__))), 'r') jsonDump = f.read() f.close() data, volData = coinmarketcap.parseMarketCap(jsonDump, 9, includeVolume=True) insertMarketCap(data, 7) # Basic count cur = dictCursor() cur.execute("""SELECT COUNT(*) cnt FROM {0}""".format( tables['market_cap_7'])) row = cur.fetchone() self.assertEqual(row['cnt'], 287) # Integrity of first and last rows cur.execute("""SELECT currency, time, market_cap_by_available_supply, market_cap_by_total_supply, price_usd, price_btc, est_available_supply, est_total_supply FROM {0} ORDER BY currency, time ASC LIMIT 1""".format(tables['market_cap_7'])) datumFirst = cur.fetchone() expectedFirst = { 'currency': 9, 'time': datetime.utcfromtimestamp(1406855058), 'market_cap_by_available_supply': Decimal('196545.14489832715'), 'market_cap_by_total_supply': Decimal('196545.14489832715'), 'price_usd': Decimal('0.00344855'), 'price_btc': Decimal('.00000588286'), 'est_available_supply': Decimal('56993561.0324128'), 'est_total_supply': Decimal('56993561.0324128') } self.assertEqual(datumFirst, expectedFirst) cur.execute("""SELECT currency, time, market_cap_by_available_supply, market_cap_by_total_supply, price_usd, price_btc, est_available_supply, est_total_supply FROM {0} ORDER BY currency, time DESC LIMIT 1""".format(tables['market_cap_7'])) datumLast = cur.fetchone() expectedLast = { 'currency': 9, 'time': datetime.utcfromtimestamp(1407458053), 'market_cap_by_available_supply': Decimal('124991.3258020573'), 'market_cap_by_total_supply': Decimal('124991.3258020573'), 'price_usd': Decimal('0.00219195'), 'price_btc': Decimal('.00000372172'), 'est_available_supply': Decimal('57022890.942794'), 'est_total_supply': Decimal('57022890.942794') } self.assertEqual(datumLast, expectedLast) # Volume Data insertMarketCapVolume(volData) cur.execute("""SELECT COUNT(*) cnt FROM {0}""".format( tables['trade_volume_usd'])) row = cur.fetchone() self.assertEqual(row['cnt'], 7) cur.execute("""SELECT currency, time, volume FROM {0} ORDER BY currency, time ASC LIMIT 1""".format(tables['trade_volume_usd'])) datumVolFirst = cur.fetchone() expectedVolFirst = { 'currency': 9, 'time': datetime.utcfromtimestamp(1406855058), 'volume': Decimal('2447.37') } self.assertEqual(datumVolFirst, expectedVolFirst) cur.execute("""SELECT currency, time, volume FROM {0} ORDER BY currency, time DESC LIMIT 1""".format(tables['trade_volume_usd'])) datumVolLast = cur.fetchone() expectedVolLast = { 'currency': 9, 'time': datetime.utcfromtimestamp(1407375855), 'volume': Decimal('477.609') } self.assertEqual(datumVolLast, expectedVolLast)