Пример #1
0
def sync_dol_bar(pair, db_name, record_name, threhold, interval='1m'):
    #get time of last row from db
    # 'features.sqlite',"x_features"
    pre_sql = psql.Preprocess_sql(db_name, record_name)
    time = str(pre_sql.get_last_n(1).date_time[0])
    # get klines from last time to current time
    klines = get_data.get_klines_df(time, symbol=pair, interval=interval)
    if get_data.is_limit(klines, threhold):
        #convert klines to dol_bar
        dol_bar = get_data.form_dol_bar(klines, threhold)

        # get last 25 rows
        # combine them to nwe dol bar
        #calculate features
        #get only df2
        #store to db
        last_twenty = pre_sql.get_last_n(25)
        p = proprecess.Proprecessing()
        p.combine_df(last_twenty, dol_bar)
        p.add_features()
        new_bars = p.get_df2()
        pre_sql.store_df(new_bars)
        print("finished")
    else:
        print("up to date")
Пример #2
0
    def live_trading(self):
        time = str(self.pre_sql.get_last_n(1).date_time[0])
        # get klines from last time to current time
        klines = get_data.get_klines_df(time,
                                        symbol=self.pair,
                                        interval=self.interval)
        if get_data.is_limit(klines, self.threshold):
            #convert klines to dol_bar
            dol_bar = get_data.form_dol_bar(klines, self.threshold)

            # get last 25 rows
            # combine them to nwe dol bar
            #calculate features
            #get only df2
            #store to db
            last_twenty = self.pre_sql.get_last_n(25)
            p = proprecess.Proprecessing()
            p.combine_df(last_twenty, dol_bar)
            p.add_features()
            new_bars = p.get_df2()
            self.pre_sql.store_df(new_bars)
            df = new_bars.iloc[-1]

            if new_bars['side']:
                features = df[self.columns].tolist()
                pred = int(self.predict.predict([features])[0])
                num_allowed = self.configs.get_trading_num()
                if num_allowed['long'] > 0 and pred == self.long_strategy[
                        "pred"] and side == self.long_strategy["side"]:
                    print("trade long")
                    self.configs.update_trading_num("long", -1)
                elif num_allowed['short'] > 0 and pred == self.short_strategy[
                        "pred"] and side == self.short_strategy["side"]:
                    print("trade short")
                    self.configs.update_trading_num("short", -1)
Пример #3
0
    def live_trading(self):
        print("start live trading")
        time = str(self.pre_sql.get_last_n(1).date_time[0])
        # get klines from last time to current time
        klines = get_data.get_klines_df(time,
                                        symbol=self.pair,
                                        interval=self.interval)
        print("get klines")
        if get_data.is_limit(klines, self.threshold):
            log = {}
            log["is_limit()"] = "klines dollar value > threshold"
            print("klines dollar value > threshold")
            #convert klines to dol_bar
            dol_bar = get_data.form_dol_bar(klines, self.threshold)

            # get last 25 rows
            # combine them to nwe dol bar
            #calculate features
            #get only df2
            #store to db
            last_twenty = self.pre_sql.get_last_n(50)
            p = proprecess.Proprecessing()
            p.combine_df(last_twenty, dol_bar)
            p.add_features()
            new_bars = p.get_df2()
            self.pre_sql.store_df(new_bars)
            df = new_bars.iloc[-1]
            print("last one")
            print(df)
            df = df.where(pd.notnull(df), None)
            log['side'] = df['side']
            if df['side']:
                features = df[self.columns].tolist()
                pred = int(self.predict.predict([features])[0])
                num_allowed = self.configs.get_trading_num()
                long_allowed = self.configs.query_config(self.pair, "long")
                short_allowed = self.configs.query_config(self.pair, "short")
                """
                long number available for the pair 
                short number available for the pair 
                """
                long_num = self.configs.get_trade_avl(self.pair, "long")
                short_num = self.configs.get_trade_avl(self.pair, "short")

                log['pred'] = pred
                log['num_allowed'] = num_allowed

                if long_allowed and num_allowed[
                        'long'] > 0 and long_num > 0 and pred == self.long_strategy[
                            "pred"] and df['side'] == self.long_strategy[
                                "side"]:
                    log['trade_long'] = "execuated"
                    self.log_func.insert_log(log)
                    return "long"
                elif short_allowed and num_allowed[
                        'short'] > 0 and short_num > 0 and pred == self.short_strategy[
                            "pred"] and df['side'] == self.short_strategy[
                                "side"]:

                    log['trade_short'] = "execuated"
                    self.log_func.insert_log(log)
                    return "short"
                else:
                    return "N"
                    self.log_func.insert_log(log)
            else:
                self.log_func.insert_log(log)
                return "N"
Пример #4
0
import get_data as gd 
import pandas as pd 

import time
start_time = time.time()

df = pd.read_csv('x_features.csv',index_col=0)
df.index = pd.to_datetime(df.index)
d = str(df.iloc[-1:].index[0])
df = gd.get_klines_df(d,interval="12h")
# df = gd.convert_raw_data(d,interval="12h")
dol = gd.form_dol_bar(df,1851265300)
print(dol)
# print(gd.is_limit(k,3099318401.0))

print("--- %s seconds ---" % (time.time() - start_time))