def get_data_until_success(command, args): """ Due to Poloniex's limit an api call to 50000 trading records get_data_utill_success() send api calls until reaching the end time """ polo = Poloniex() js0 = polo.api(command, args) df0 = pd.DataFrame(js0) # !!! timezone conversion fix -18000 unix_time_convert = lambda x: int(time.mktime(datetime.datetime.strptime(x, "%Y-%m-%d %H:%M:%S").timetuple())-18000) df0["date"] = df0["date"].apply(unix_time_convert) if len(df0) == 50000: while (df0["date"].iloc[-1] > args["start"]): args["end"] = df0["date"].iloc[-1] + 1 print(args) js = polo.api(command, args) df = pd.DataFrame(js) if not df.empty: df["date"] = df["date"].apply(unix_time_convert) df0 = df0.append(df, ignore_index=True) if len(df) < 50000: df0.loc[-1,"date"] = args["start"] df0["rate"] = df0["rate"].apply(float) df0["total"] = df0["total"].apply(float) return df0
def get_target(coin_name, time_chosen): # download actual trading data of the test time polo = Poloniex() args = {} args["currencyPair"] = "BTC_" + coin_name command = "returnTradeHistory" args["start"] = time_chosen args["end"] = time_chosen + 1800 js = polo.api(command, args) df = pd.DataFrame(js) df["rate"] = df["rate"].apply(float) df = df[np.isfinite(df['rate'])] delta = df["rate"].iloc[0] / df["rate"].iloc[-1] - 1 # sigmoid function with an multiply factor to magnify delta ############################### # need to make the multiply factor an argument ############################### target = 1 / (1 + math.e**(-150 * delta)) return target