示例#1
0
def input_data(tt):
    trade_data = pd.DataFrame(columns=[
        'time', 'ok0330', 'ok_thisweek', 'bfx_bids_wall', 'bfx_asks_wall',
        'bfx_total_bids', 'bfx_total_asks', 'bfx_buy_volumn',
        'bfx_sell_volumn', 'bfx_last_price', 'exchange_rate', 'huobi_USDT'
    ])
    for i in range(0, tt):
        t = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
        ok0330 = float(
            mykey.future_ticker('btc_usd', 'quarter')['ticker']['last'])
        ok_thisweek = float(
            mykey.future_ticker('btc_usd', 'this_week')['ticker']['last'])
        bfx_bids_wall = bfx.bfx_books()['bids_wall']
        bfx_asks_wall = bfx.bfx_books()['asks_wall']
        bfx_total_bids = bfx.bfx_books()['total_bids']
        bfx_total_asks = bfx.bfx_books()['total_asks']
        bfx_buy_volumn = bfx.bfx_volumn()[0]
        bfx_sell_volumn = bfx.bfx_volumn()[1]
        bfx_last_price = bfx.bfx_ticker()
        exchange_rate = float(mykey.exchange_rate()['rate'])
        huobiUSDT = float(huobi_USDT.get_usdt_price())
        trade_data.loc[i] = [
            t, ok0330, ok_thisweek, bfx_bids_wall, bfx_asks_wall,
            bfx_total_bids, bfx_total_asks, bfx_buy_volumn, bfx_sell_volumn,
            bfx_last_price, exchange_rate, huobiUSDT
        ]
        print(trade_data)
        time.sleep(30)
    trade_data.to_csv('btc.csv')
示例#2
0
def test_data(tt):
    pca=joblib.load('pca.m')
    next5=joblib.load('next5.m')
    next10=joblib.load('next10.m')
    next15=joblib.load('next15.m')
    i=0
    while i<=tt:
        try:
            DateTime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            ok0330=float(mykey.future_ticker('btc_usd','quarter')['ticker']['last'])
            ok_thisweek=float(mykey.future_ticker('btc_usd','this_week')['ticker']['last'])
            bfx_bids_wall=float(bfx.bfx_books()['bids_wall'])
            bfx_asks_wall=float(bfx.bfx_books()['asks_wall'])
            bfx_total_bids=float(bfx.bfx_books()['total_bids'])
            bfx_total_asks=float(bfx.bfx_books()['total_asks'])
            bfx_buy_volumn=float(bfx.bfx_volumn()[0])
            bfx_sell_volumn=float(bfx.bfx_volumn()[1])
            bfx_last_price=float(bfx.bfx_ticker())
            exchange_rate=float(mykey.exchange_rate()['rate'])
            huobiUSDT=float(huobi_USDT.get_usdt_price())
            #huobi USDT OTC price
            news_emotion=float(wallstreet_news.wallstr_news())
            #News emotion from wallstreet cn
            if i==0:
                raw=pd.DataFrame([[DateTime,ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion]],columns=['DateTime','ok0330','ok_thisweek','bfx_bids_wall','bfx_asks_wall','bfx_total_bids','bfx_total_asks','bfx_buy_volumn','bfx_sell_volumn','bfx_last_price','exchange_rate','huobi_USDT','news_emotion'])
            if (i>0)&(i<=15):
                raw2=pd.DataFrame([[DateTime,ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion]],index=[i],columns=['DateTime','ok0330','ok_thisweek','bfx_bids_wall','bfx_asks_wall','bfx_total_bids','bfx_total_asks','bfx_buy_volumn','bfx_sell_volumn','bfx_last_price','exchange_rate','huobi_USDT','news_emotion'])
                raw=raw.append(raw2)
            if i>15:
                raw3=pd.DataFrame([[DateTime,ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion]],index=[i],columns=['DateTime','ok0330','ok_thisweek','bfx_bids_wall','bfx_asks_wall','bfx_total_bids','bfx_total_asks','bfx_buy_volumn','bfx_sell_volumn','bfx_last_price','exchange_rate','huobi_USDT','news_emotion'])
                raw=raw.append(raw3)
                raw=raw.drop([i-16])
                feature=d_pro(raw) 
				#Data Preprocessing
                PCA_ed_feature=pca.transform(feature)
				#PCA Features
                next_5=next5.predict(PCA_ed_feature)[15]
                next_10=next10.predict(PCA_ed_feature)[15]
                next_15=next15.predict(PCA_ed_feature)[15]
                if(next_5)+(next_10)+(next_15)>2:
                    print('buy buy buy')
                    mykey.future_trade('btc_usd','quarter',amount=10,tradeType=1,matchPrice=1,leverRate=20)
                    longtime.append(i)
                    #record the time we long bitcoin
                print([next_5,next_10,next_15])
            i=i+1
            for time in longtime:
                if i>time+15:
                    mykey.future_trade('btc_usd','quarter',amount=10,tradeType=3,matchPrice=1,leverRate=20)
                    longtime.remove(time)
                    #sell the future long ticket
            print(raw)
            time.sleep(60)
        except:
            print('connect error')          
    return raw
示例#3
0
def test_data(tt):
    pca=joblib.load('pca.m')
    next5=joblib.load('next5.m')
    next10=joblib.load('next10.m')
    next15=joblib.load('next15.m')
    i=0
    while i<=tt:
        try:
            DateTime=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
            ok0330=float(mykey.future_ticker('btc_usd','quarter')['ticker']['last'])
            ok_thisweek=float(mykey.future_ticker('btc_usd','this_week')['ticker']['last'])
            bfx_bids_wall=float(bfx.bfx_books()['bids_wall'])
            bfx_asks_wall=float(bfx.bfx_books()['asks_wall'])
            bfx_total_bids=float(bfx.bfx_books()['total_bids'])
            bfx_total_asks=float(bfx.bfx_books()['total_asks'])
            bfx_buy_volumn=float(bfx.bfx_volumn()[0])
            bfx_sell_volumn=float(bfx.bfx_volumn()[1])
            bfx_last_price=float(bfx.bfx_ticker())
            exchange_rate=float(mykey.exchange_rate()['rate'])
            huobiUSDT=float(huobi_USDT.get_usdt_price())
            #huobi USDT OTC price
            news_emotion=float(wallstreet_news.wallstr_news())
            #News emotion from wallstreet cn
            if i==0:
                raw=pd.DataFrame([[DateTime,ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion]],columns=['DateTime','ok0330','ok_thisweek','bfx_bids_wall','bfx_asks_wall','bfx_total_bids','bfx_total_asks','bfx_buy_volumn','bfx_sell_volumn','bfx_last_price','exchange_rate','huobi_USDT','news_emotion'])
            if (i>0)&(i<=15):
                raw2=pd.DataFrame([[DateTime,ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion]],index=[i],columns=['DateTime','ok0330','ok_thisweek','bfx_bids_wall','bfx_asks_wall','bfx_total_bids','bfx_total_asks','bfx_buy_volumn','bfx_sell_volumn','bfx_last_price','exchange_rate','huobi_USDT','news_emotion'])
                raw=raw.append(raw2)
            if i>15:
                raw3=pd.DataFrame([[DateTime,ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion]],index=[i],columns=['DateTime','ok0330','ok_thisweek','bfx_bids_wall','bfx_asks_wall','bfx_total_bids','bfx_total_asks','bfx_buy_volumn','bfx_sell_volumn','bfx_last_price','exchange_rate','huobi_USDT','news_emotion'])
                raw=raw.append(raw3)
                raw=raw.drop([i-16])
                feature=d_pro(raw) 
				#Data Preprocessing
                PCA_ed_feature=pca.transform(feature)
				#PCA Features
                next_5=next5.predict(PCA_ed_feature)[15]
                next_10=next10.predict(PCA_ed_feature)[15]
                next_15=next15.predict(PCA_ed_feature)[15]
				if next_5+next_10+next_15>2:
				#input auto-trading code to long
				if next_5+next_10+next_15=0:
				#input auto-trading code to short
				#predict the future bitcoin price(5min/10min/15min)
                print([next_5,next_10,next_15])
            i=i+1
            print(raw)
			time.sleep(60)
        except:
            print('connect error')          
    return raw
示例#4
0
def input_data(tt):
    #input the number of rows you want to input
    j = 0
    for i in range(0, tt):
        #count number of rows
        try:
            ok0330 = float(
                mykey.future_ticker('btc_usd', 'quarter')['ticker']['last'])
            ok_thisweek = float(
                mykey.future_ticker('btc_usd', 'this_week')['ticker']['last'])
            bfx_bids_wall = bfx.bfx_books()['bids_wall']
            bfx_asks_wall = bfx.bfx_books()['asks_wall']
            bfx_total_bids = bfx.bfx_books()['total_bids']
            bfx_total_asks = bfx.bfx_books()['total_asks']
            bfx_buy_volumn = bfx.bfx_volumn()[0]
            bfx_sell_volumn = bfx.bfx_volumn()[1]
            bfx_last_price = bfx.bfx_ticker()
            exchange_rate = float(mykey.exchange_rate()['rate'])
            huobiUSDT = float(huobi_USDT.get_usdt_price())
            #get USDT price from huobi.pro
            news_emotion = float(wallstreet_news.wallstr_news())
            print('test')
            print(news_emotion)
            #get news emotion from wallstreet news blockchain channel
            cursor = con.cursor()
            print(cursor)
            print('test')
            # db_name = 'PythonTestDB'
            # create_db_sql = 'CREATE DATABASE ' + db_name
            # cursor.execute(create_db_sql)
            # if i==0:
            #     create_table_sql = 'DROP TABLE BitcoinTradeHistory'
            #     cursor.execute(create_table_sql)
            #     string = 'CREATE TABLE BitcoinTradeHistory(date DATE, last_price FLOAT ,ok_thisweek FLOAT ,bfx_bids_wall FLOAT ,bfx_asks_wall FLOAT   ,bfx_total_bids FLOAT   ,bfx_total_asks FLOAT   ,bfx_buy_volumn FLOAT    ,bfx_sell_volumn FLOAT  ,bfx_last_price FLOAT   ,exchange_rate FLOAT    ,huobiUSDT FLOAT    ,news_emotion FLOAT)'
            #     cursor.execute(string)
            cursor.execute(
                "insert into BitcoinTradeHistory values(getdate(),{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11})"
                .format(ok0330, ok_thisweek, bfx_bids_wall, bfx_asks_wall,
                        bfx_total_bids, bfx_total_asks, bfx_buy_volumn,
                        bfx_sell_volumn, bfx_last_price, exchange_rate,
                        huobiUSDT, news_emotion))
            print('test')
            #insert into SQL Server Database
            con.commit()
            j = j + 1
            print('collected {0} rows'.format(j))
            time.sleep(60)
        except:
            print('connect error')
            traceback.print_exc(file=sys.stdout)
    print('done')
示例#5
0
#connect to SQL Server Database
def input_data(tt):
    #input the number of rows you want to input
	j=0
    for i in range(0,tt):
        #count number of rows
        try:
            ok0330=float(mykey.future_ticker('btc_usd','quarter')['ticker']['last'])
            ok_thisweek=float(mykey.future_ticker('btc_usd','this_week')['ticker']['last'])
            bfx_bids_wall=bfx.bfx_books()['bids_wall']
            bfx_asks_wall=bfx.bfx_books()['asks_wall']
            bfx_total_bids=bfx.bfx_books()['total_bids']
            bfx_total_asks=bfx.bfx_books()['total_asks']
            bfx_buy_volumn=bfx.bfx_volumn()[0]
            bfx_sell_volumn=bfx.bfx_volumn()[1]
            bfx_last_price=bfx.bfx_ticker()
            exchange_rate=float(mykey.exchange_rate()['rate'])
            huobiUSDT=float(huobi_USDT.get_usdt_price())
            #get USDT price from huobi.pro
            news_emotion=float(wallstreet_news.wallstr_news())
            #get news emotion from wallstreet news blockchain channel
            cursor=con.cursor()
            cursor.execute("insert into dbo.BitcoinTradeHistory values(getdate(),{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11})".format(ok0330,ok_thisweek,bfx_bids_wall,bfx_asks_wall,bfx_total_bids,bfx_total_asks,bfx_buy_volumn,bfx_sell_volumn,bfx_last_price,exchange_rate,huobiUSDT,news_emotion))
            #insert into SQL Server Database
            con.commit()
            j=j+1
            print('collected {0} rows'.format(j))
            time.sleep(60) 
        except:
            print('connect error')             
    print('done')