def main():
	global currencyList
	n = 0
	curDay = strftime("%d-%m-%Y", gmtime())

	l = len(currencyList)
	#l = 1
	while n < l:
		# initialise scraper
		scraper = CmcScraper(currencyList[n], '01-01-2000', curDay)

		# # get data as list of list
		headers, data = scraper.get_data()

		# # export the data to csv
		scraper.export_csv('history/'+currencyList[n]+".csv")

		# # get dataframe for the data
		df = scraper.get_dataframe()

		x = []
		y = []
		with open('history/'+currencyList[n]+'.csv', 'r') as f:
		    sreader = csv.reader(f)

		    i = 0 
		    for row in sreader:
		        if i > 0 :
		        	x.append(i)
		        	y.append((float(row[2]) + float(row[3]))/2)

		        i = i + 1

		prediction = predict(y,currencyList[n])

		print currencyList[n] + ' => ' + str(prediction) 

		y.reverse()
		data = {}
		data["pointStart"] = 1230764400000
		data["pointInterval"] = 3600000
		data["dataLength"] = len(y)
		data["data"] = y
		data["prediction"] = prediction

		json_data = json.dumps(data)

		#print json_data
		file = open('public/'+currencyList[n]+'.json', 'w') 
		file.write(json_data)
		file.close() 

		n = n+1
import streamlit as st
from cryptocmd import CmcScraper
import plotly.express as px

st.write('# 비트코인 BTC 데이터')

scrppper = CmcScraper('BTC', '01-01-2021', '07-01-2021') # %d-%m-%Y

df = scrppper.get_dataframe()

fig_close = px.line(df, x='Date', y=['Open', 'High', 'Low', 'Close'], title='가격')
fig_volume = px.line(df, x='Date', y=['Volume'], title='거래량')

st.plotly_chart(fig_close)
st.plotly_chart(fig_volume)
import streamlit as st
from cryptocmd import CmcScraper
import plotly.express as px
from datetime import datetime

st.write('#Cryptocurrency Web App')
st.sidebar.header('Menu')

name = st.sidebar.selectbox('Name', ['BTC', 'ETH', 'USDT'])

start_date = st.sidebar.date_input('start date', datetime(2021, 1, 1))
end_date = st.sidebar.date_input('end date', datetime(2021, 1, 25))

scrapper = CmcScraper(name, start_date.strftime('%d-%m-%Y'),
                      end_date.strftime('%d-%m-%Y'))

df = scrapper.get_dataframe()

fig_close = px.line(df,
                    x='Date',
                    y=['Open', 'High', 'Low', 'Close'],
                    title='Price')
fig_volume = px.line(df, x='Date', y=['Volume'], title='Volume')

st.plotly_chart(fig_close)
st.plotly_chart(fig_volume)
Пример #4
0
	def get_historical_quotes(self) -> pd.DataFrame:
		scraper = CmcScraper(self.ticker)
		df = scraper.get_dataframe()
		return pd.DataFrame({'_id' : 'null', 'Ticker' : self.ticker, 'TimeStampID' : 
			df['Date'], 'Price_USD' : df['Close'], 'Price_BTC' : 'null', 
			'MarketCap_USD' : df['Market Cap'], 'Volume24hr_USD' : df['Volume']})
Пример #5
0
def get_historical_data(crypto, first_day, last_day):
    scraper = CmcScraper(crypto, first_day, last_day)
    historical_data_df = scraper.get_dataframe().set_index("Date")
    return historical_data_df
Пример #6
0
def load_data(selected_ticker):
    init_scraper = CmcScraper(selected_ticker)
    df = init_scraper.get_dataframe()
    min_date = pd.to_datetime(min(df['Date']))
    max_date = pd.to_datetime(max(df['Date']))
    return min_date, max_date
Пример #7
0
elif date_range == "Specific date range":

    ### Initialise scraper with time interval
    start_date = st.sidebar.date_input('Select start date:',
                                       min_value=min_date,
                                       max_value=max_date,
                                       value=min_date)
    end_date = st.sidebar.date_input('Select end date:',
                                     min_value=min_date,
                                     max_value=max_date,
                                     value=max_date)
    scraper = CmcScraper(selected_ticker, str(start_date.strftime("%d-%m-%Y")),
                         str(end_date.strftime("%d-%m-%Y")))

### Pandas dataFrame for the same data
data = scraper.get_dataframe()

st.subheader('Raw data')
st.write(data.head())


### Plot functions
def plot_raw_data():
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=data['Date'], y=data['Close'], name="Close"))
    fig.layout.update(title_text='Time Series data with Rangeslider',
                      xaxis_rangeslider_visible=True)
    st.plotly_chart(fig)


def plot_raw_data_log():
Пример #8
0
def updateCoins(coinCodes):
    """Update the H5 Repository with Coin Data

    Keyword arguments:
    coinList - Set of CoinCodes
    """

    global apph5datafile

    coinList = []

    if coinCodes == '*':
        print("You asked to update all tracked coins")
        coinList = config.get('Active', 'Coins').split(' ')
    else:
        coinList = coinCodes
        print("You asked to list the last week for coins %s" % (coinList))

    print("You asked to update coins %s" % (coinList))

    for coin in coinList:

        havecointable = True

        if not os.path.exists(apph5datafile):
            print("Creating Datafile %s" % apph5datafile)
            havecointable = False


#        if not ('/'+coin.upper()) in storedcoins:
#            print("Coin %s not in dataset" % coin.upper())
#            havecointable = False

        if havecointable:

            try:
                hdf = read_hdf(apph5datafile, coin)

                hdf['date_ranked'] = hdf['Date'].rank(ascending=1)
                print "Last element from %s is dated %s" % (
                    coin, str(hdf.at[0, 'Date'])[:10])
                lastdate = datetime.strptime(
                    str(hdf.at[0, 'Date'])[:10], "%Y-%m-%d")
                nextday = timedelta(1)
                nextday = lastdate + nextday
                delta = (datetime.today() - timedelta(1)) - nextday
                print("Difference from yesterday to last update ", delta)

            except KeyError:
                print("No data found for this Coin")
                nextday = (datetime.today() - timedelta(2 * 365))

            lastdate = datetime.today() - timedelta(1)

            print "Updating data from %s to %s" % (str(nextday), str(lastdate))

            startdate = '{:%d-%m-%Y}'.format(nextday)
            enddate = '{:%d-%m-%Y}'.format(lastdate)

            scraper = CmcScraper(coin, startdate, enddate)

        else:

            scraper = CmcScraper(coin.upper())

        # get data as list of list
        try:
            headers, data = scraper.get_data()

            # get dataframe for the data
            df = scraper.get_dataframe()

            print df

            # df.to_hdf('pluton.h5',coin,append=True,format='t')
            df.to_hdf(apph5datafile, coin.upper())

        except ValueError:
            print("No data found")

    return
f= pd.read_csv(data)
print(f)

!pip install cryptocmd

from cryptocmd import CmcScraper

# initialise scraper
scraper1 = CmcScraper('XRP', '08-08-2015', '12-04-2018')
scraper2 = CmcScraper('ETH', '08-08-2015', '12-04-2018')
scraper3 = CmcScraper('DASH', '08-08-2015', '12-04-2018')
scraper4 = CmcScraper('LTC', '08-08-2015', '12-04-2018')
scraper5 = CmcScraper('XLM', '08-08-2015', '12-04-2018')

# get dataframe for the data
df1 = scraper1.get_dataframe()
df2 = scraper2.get_dataframe()
df3 = scraper3.get_dataframe()
df4 = scraper4.get_dataframe()
df5 = scraper5.get_dataframe()
Y = f['BCHAIN-MKPRU'][0:978]
X =  pd.concat([df1['Close'], df2['Close'], df3['Close'] ,df4['Close'], df5['Close'],f[0:979]], axis=1)
X= X[1:]

from scipy import stats
X = stats.zscore(X)
Y = stats.zscore(Y)
X.shape

t=range(1,979)
plt.plot(t, np.flipud(Y), color='darkorange', label='data')
Пример #10
0
def download_data_scrapper(from_symbol):
    scraper = CmcScraper(from_symbol)
    data = scraper.get_dataframe()
    return data
Пример #11
0
def CryptoForecast(SelectCrypto):

   # get the data
#     cryptodata = pdr.get_data_yahoo(
#         [SelectCrypto + "-" + "USD"], start=firstdate, end=todate
#     ).reset_index()
#     cryptodata.columns = cryptodata.columns.get_level_values(0)

    scraper = CmcScraper(SelectCrypto, firstdate, todate)
    cryptodata = scraper.get_dataframe()

    cryp_pro = cryptodata[["Date", "Close"]]
    cryp_pro = cryp_pro.rename(columns={"Date": "ds", "Close": "y"})

    # Fit the Model
    model = Prophet()
    model.fit(cryp_pro)

    # make the prediction
    future = model.make_future_dataframe(periods=60)
    forecast = model.predict(future)

    # prepare data for plotting 
    forecast = forecast[["ds", "yhat", "yhat_lower", "yhat_upper"]]
    forecast = forecast.rename(columns={"ds": "Date"})
    plot_data = cryptodata.merge(forecast, on="Date", how="outer").sort_values(by="Date", ascending=False)
    plot_data["Volume"] = plot_data["Volume"].replace(np.nan, 0)
    plot_data = plot_data.iloc[0:150,:]

    # make the plot
    fig_forecast = px.scatter(
        plot_data,
        x="Date",
        y="Close",
        size="Volume",
        title=SelectCrypto,
        labels={"Date": "Date", "Close": "Price in USD"},
        template="plotly_dark",
        #height = 500, 
    ).update_traces(mode="lines+markers", marker=dict(color="green", opacity=0.4))

    fig_forecast["data"][0]["showlegend"]=True
    fig_forecast["data"][0]["name"]="Actual Price"

    fig_forecast.add_trace(
        go.Scatter(
            x=plot_data["Date"],
            y=plot_data["yhat"],
            mode="lines",
            name="Predicted Price",
        )
    )
    fig_forecast.add_trace(
        go.Scatter(
            x=plot_data["Date"],
            y=plot_data["yhat_upper"],
            mode="lines",
            line=dict(dash="dot", color="dodgerblue"),
            name="Upper Band",
        )
    )
    fig_forecast.add_trace(
        go.Scatter(
            x=plot_data["Date"],
            y=plot_data["yhat_lower"],
            mode="lines",
            line=dict(dash="dot"),
            name="Lower Band",
        )
    )

    fig_forecast.update_layout(legend=dict(orientation="h", x=1.02, y=1.02, xanchor="right", yanchor="bottom"))

    return fig_forecast