Exemplo n.º 1
0
def getCurrencyDaily(symbol, currency):
    fileName = 'E:\\scrapy\\phoenixHealth\\code\\scapy\\newCryptoCompare\\currency-daily\\' + symbol + currency + '.csv'
    if os.path.isfile(fileName):
        print(coinName + " has been downloaded.")
        return
    test = price.get_historical_data(symbol,
                                     currency,
                                     'day',
                                     info='full',
                                     aggregate=1,
                                     limit=2000)
    with open(fileName, 'w', newline="", encoding='utf-8') as datacsv:
        csvwriter = csv.writer(datacsv, dialect=("excel"))
        firstLine = [
            "date", "cryptocurrrency", "open", "high", "low", "close",
            "volume-from", "volume-to"
        ]
        csvwriter.writerow(firstLine)
        for i in test:
            if i['high'] == 0 and i['low'] == 0 and i['open'] == 0 and i[
                    'close'] == 0 and i['volumeto'] == 0:
                continue
            data = []
            date = i['time'].split(' ')[0].replace('-', '/')
            data.append(date)
            data.append(symbol + currency)
            data.append(i['open'])
            data.append(i['high'])
            data.append(i['low'])
            data.append(i['close'])
            data.append(i['volumefrom'])
            data.append(i['volumeto'])
            csvwriter.writerow(data)
    print("Generate " + symbol + currency + ".csv successfully.")
Exemplo n.º 2
0
def test_get_historical_data_timestamp(to_ts):

    datas = price.get_historical_data('BTC', 'USD', 'minute', to_ts=to_ts)

    assert len(datas) == 1441
    data = datas[0]
    assert data['time'] == '2019-05-15 18:01:00'
def gen_crypto_data(item_id):
    result = MySQL(item_id).searchTweetsByHour()
    fsym = item_id.upper()

    price_data = price.get_current_price(
        fsym, 'USD', e='all', try_conversion=True, full=True, format='raw')[fsym]['USD']
    result['price'] = price_data['PRICE']
    result['coin_supply'] = price_data['SUPPLY']
    result['market_cap'] = price_data['MKTCAP']
    result['velocity'] = result['price'] * \
        result['coin_supply'] / result['market_cap']

    result['high'] = 0
    result['low'] = float("inf")
    result['volume_sold'] = 0
    for data in price.get_historical_data(
            fsym, 'USD', 'minute', aggregate=10, limit=6):
        result['high'] = data['high'] if data['high'] > result['high'] else result['high']
        result['low'] = data['low'] if data['low'] < result['low'] else result['low']
        result['volume_sold'] += data['volumeto']

    file_path = './out/' + fsym + '_crypto.xlsx'
    if not os.path.isfile(file_path):
        wb = Workbook()
        ws = wb.active
        ws.append(['price',
                   'high',
                   'low',
                   'volume_sold',
                   'coin_supply',
                   'market_cap',
                   'velocity',
                   'amount_hour',
                   'amount_avg',
                   'amount_spike',
                   'sentiment_hour',
                   'sentiment_avg',
                   'sentiment_spike'])
        wb.save(file_path)

    else:
        wb = load_workbook(file_path)
        ws = wb.active
    ws.append([time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()),
               result['price'],
               result['high'],
               result['low'],
               result['volume_sold'],
               result['coin_supply'],
               result['market_cap'],
               result['velocity'],
               result['amount_hour'],
               result['amount_avg'],
               result['amount_spike'],
               result['sentiment_hour'],
               result['sentiment_avg'],
               result['sentiment_spike']])
    wb.save(file_path)
    return result
Exemplo n.º 4
0
def test_get_high_historical_data():

    datas = price.get_historical_data('BTC', 'USD', 'minute', info='high')

    data = datas[0]
    assert data.keys() == set(['time', 'high'])
    data['time'] == '2018-09-29 00:30:00'
    data['high'] == 6537.44
Exemplo n.º 5
0
def get_price():
    money = price.get_historical_data('BTC',
                                      'USD',
                                      'hour',
                                      aggregate=1,
                                      limit=(1000))
    print(len(money))
    print(money)
    return 0
Exemplo n.º 6
0
def get_past_hour_price(currency):
    data = price.get_historical_data(currency, 'USD', 'hour', aggregate=1, limit=(500*24))
    price_vec = []
    time_vec = []
    data_dictionary = {"time": time_vec, "price": price_vec}

    for idx in data:
        price_vec.append(idx["close"])
        time_vec.append(idx["time"])
        #print("Time: ", idx["time"], "Close: ", idx["close"])

    return data_dictionary
Exemplo n.º 7
0
 def get_data(self, minutes):
     xrp = price.get_historical_data('XRP',
                                     'KRW',
                                     'minute',
                                     e='Bithumb',
                                     aggregate=minutes,
                                     limit=2000)
     eth = price.get_historical_data('ETH',
                                     'KRW',
                                     'minute',
                                     e='Bithumb',
                                     aggregate=minutes,
                                     limit=2000)
     btc = price.get_historical_data('BTC',
                                     'KRW',
                                     'minute',
                                     e='Bithumb',
                                     aggregate=minutes,
                                     limit=2000)
     XRP = pd.DataFrame(xrp)
     ETH = pd.DataFrame(eth)
     BTC = pd.DataFrame(btc)
     return XRP, ETH, BTC
Exemplo n.º 8
0
def get_graph_data(coin, currency, period):
    times = []
    prices = []
    historical = price.get_historical_data(coin,
                                           currency,
                                           timeList[period]["period"],
                                           info='close',
                                           aggregate=1,
                                           limit=timeList[period]["count"])
    for data in historical:
        dt = datetime.datetime.strptime(data["time"], "%Y-%m-%d %H:%M:%S")
        times.append(dt)
        prices.append(data["close"])
    return times, prices
Exemplo n.º 9
0
def test_get_historical_data():

    datas = price.get_historical_data('BTC', 'USD', 'minute')

    assert len(datas) == 1441

    data = datas[0]
    data['time'] == '2018-09-29 00:30:00'
    data['close'] == 6655.97
    data['high'] == 6655.99
    data['low'] == 6655.58
    data['open'] == 6655.99
    data['volumefrom'] == 5.21
    data['volumeto'] == 34791.94
Exemplo n.º 10
0
def get_daily_data(ticker, quantity, plot=False, display=False):
    hist = price.get_historical_data(ticker,
                                     'USD',
                                     'day',
                                     aggregate=1,
                                     limit=quantity)
    data = pd.DataFrame.from_dict(hist)
    if display:
        print(data.head())
        print(data.tail())
    if plot:
        plt.plot(data.time, data.close, label="Close")
        plt.plot(data.time, data.high, label="High")
        plt.plot(data.time, data.open, label="Open")
        plt.legend()
        plt.grid(True)
        plt.show()
    return data
Exemplo n.º 11
0
def fig300btc():
	from cryptocompy import coin, price

	fig = plt.figure(figsize=(15, 7.5))
	r = price.get_historical_data('BTC', 'USD', 'day', info='close', aggregate=1, limit=300)
	axis = fig.add_subplot(1, 1, 1)

	prices = []
	for value in r:
		price = value['close']
		price = int(price)
		prices.append(price)
	
	dates = []
	for value in r:
		date = value['time']
		date = date[5:]
		date = date[:5]
		date = date[:2] + date[2:]
		dates.append(date)

	minprice = min(prices) - 25
	axis.plot(dates, prices, 'm')
	xticks = axis.get_xticks()
	axis.set_xticks(xticks[::30])
	axis.tick_params(axis='x', labelsize=13, labelrotation=45)
	axis.tick_params(axis='y', labelsize=13)
	axis.fill_between(dates, prices, minprice, facecolor='blue', alpha=0.5)
	plt.margins(0)
	plt.style.use('seaborn-darkgrid')
	canvas = FigureCanvas(fig)
	output = io.BytesIO()
	canvas.print_png(output)
	response = make_response(output.getvalue())
	response.mimetype = 'image300btc/png'
	img = io.BytesIO()
	fig.savefig(img, bbox_inches="tight")
	img.seek(0)
	return send_file(img, mimetype='image300btc/png')
    def download(self,
                 instrument,
                 period,
                 number_of_periods,
                 fromDate,
                 toDate=None):
        logger.debug("Downloading %s" % instrument)

        crypto_period = self.period_dict[period]
        dict_downloaded = price.get_historical_data(
            instrument.symbol,
            instrument.currency,
            crypto_period,
            aggregate=number_of_periods)
        if len(dict_downloaded) == 0:
            logger.error(
                'Cant download cryptocompare %s_%s for %s return None' %
                (instrument.symbol, instrument.currency, period))
            return None
        outputComplete = self.formatHistorical(dict_downloaded)

        # Already added
        # outputComplete = self.setTimeCorrect(outputComplete, period=period, instrument=instrument)
        return outputComplete