def get_money(): items = 'money' table = 'act_info' condition = ' order by datetime desc limit 1 ' money = get_all_data(items, table, condition) money = money[0][0] return (money)
def get_money(): items = 'money' table = 'act_info' condition = ' ' money = get_all_data(items, table, condition) money = money[0][0] return(money)
def get_vol(symbol_list): items = 'symbol, vol_usage' table = 'act_pos' condition = 'where symbol in (' + str(symbol_list).replace( '[', '').replace(']', '') + ') and vol_usage > 0' vol_data = dict(get_all_data(items, table, condition)) return (vol_data)
def get_last(table, ts_data): symbol_list = list(ts_data.symbol) items = 'symbol, max(datetime)' table = table condition = 'where symbol in (' + str(symbol_list).replace( '[', '').replace(']', '') + ') group by symbol order by symbol asc' last_data = dict(get_all_data(items, table, condition)) return (last_data)
def get_1m_data(symbol, time): items = 'symbol, datetime, open, high, low, close' table = 'ts_price_1m' condition = 'where symbol = \'' + symbol + '\' and datetime >= \'' + time + '\' order by datetime asc' df_1m = pd.DataFrame( get_all_data(items, table, condition), columns=['symbol', 'datetime', 'open', 'high', 'low', 'close']) df_1m.sort_values('datetime', inplace=True) return (df_1m)
def get_1h_data(symbol): items = ' * from (SELECT symbol, datetime, open, high, low, close' table = 'ts_price_1h' condition = 'where symbol = \'' + symbol + '\' order by datetime desc limit 120) order by datetime asc' df_1h = pd.DataFrame( get_all_data(items, table, condition), columns=['symbol', 'datetime', 'open', 'high', 'low', 'close']) df_1h.sort_values('datetime', inplace=True) return (df_1h)
def get_td_signal(symbol_list): symbol_list = symbol_list items = 'a.symbol, a.datetime, a.signal, a.buy_price' table = 'td_kd a inner join (SELECT symbol, max(datetime) as dtime FROM td_kd group by symbol) b on a.symbol =b.symbol and a.datetime =b.dtime' condition = 'where a.symbol in (' + str(symbol_list).replace( '[', '').replace(']', '') + ') order by a.symbol asc' signal_data = get_all_data(items, table, condition) signal_data = pd.DataFrame( signal_data, columns=['symbol', 'datetime', 'signal', 'buy_price']) signal_data = calc_current_td_signal(signal_data) return (signal_data)
def get_td_signal_h(symbol_list): signal_data = pd.DataFrame() for symbol in symbol_list: items = 'symbol, datetime, signal, buy_price' table = 'td_kd' condition = 'where symbol = \'' + symbol + '\' order by datetime desc limit 2' kd_data = get_all_data(items, table, condition) if len(kd_data) == 0: continue kd_data = pd.DataFrame( kd_data, columns=['symbol', 'datetime', 'signal', 'buy_price']) signal_data = signal_data.append(kd_data) signal_data = signal_data.sort_values(by=['symbol', 'datetime']) return (signal_data)