def render_json(self, data, requestid=False, jsonstr=False, indent=False): self.set_header('Content-Type', 'application/json') if jsonstr: data = json.loads(data) if requestid: data['requestid'] = 'requestid:%s midware_finish:%s' % ( self.requestid, second2_str24h(time.time())[11:]) try: data = json.dumps(data) except Exception as e: easylog.exception("%s data:%s", e, data) data = {'error': 'JSON格式错误(%s)' % e} if requestid: data['requestid'] = 'requestid:%s midware_finish:%s' % ( self.requestid, second2_str24h(time.time())[11:]) data = json.dumps(data, cls=IpaJsonEncoder) try: start_time = time.time() self.write(data) easylog.info('write data length:%.02fKB TIME USAGE:%.4fs', len(data) / 1024.0, time.time() - start_time) except Exception as e: easylog.critical('%s', e)
def start_fetch_blockid(id_dict, conf_dict, latest_block_info): id_dict_size = 3600 last_clean_ts = 0 while True: try: url = "%s/v1/chain/get_info" % (conf_dict['eoshost']) res = requests.get(url, timeout=3.0) if res.status_code / 100 != 2: easylog.error("Failed to get_info:%s", res.text) continue result = json.loads(res.text) now_ts = time.time() latest_block_info['ts'], latest_block_info['info'] = now_ts, result if result['head_block_num'] in id_dict and result['head_block_id'] == id_dict[result['head_block_num']]['id']: continue easylog.info('%d : %s', result['head_block_num'], result['head_block_id']) id_dict[result['head_block_num']] = {'id':result['head_block_id'],'ts':time.time()} nums = list(id_dict.keys()) if now_ts-last_clean_ts > id_dict_size/2 and len(nums)>id_dict_size: last_clean_ts = now_ts for key in nums: if now_ts - id_dict[key]['ts'] > id_dict_size/2: del id_dict[key] except Exception as e: easylog.exception("%s", e) finally: time.sleep(conf_dict['get_info_sec'])
def main(): # remote debug # host: machine running Komodo or the DBGP Proxy (uses localhost if unspecified) # port: port to connect on (uses 9000 if unspecified) #brkOnExcept(host="192.168.1.141", port=9000) # Or you can use the command line to start the remote debuge # pydbgp -d 192.168.1.141:9000 ./main.py --port=8999 \ # --debug=True --logging=debug \ # --logging=debug|info|warning|error|none options.parse_command_line() easylog.setup("%s/nohup_%d.out" % (options.log_path, options.port), options.logging, log_file_enable=True, file_size_mb=20, file_count=2) handler_map = [] # TODO: Here add your handlers before the DEFAULT handler_map from components.eosapi.hanlder import handler_map as eosapi_handler_map handler_map += eosapi_handler_map from components.default.handler import handler_map as default_handler_map handler_map += default_handler_map for h in handler_map: easylog.info(str(h)) start_httpserver(handler_map, options)
def setup_env(): unfilled_orders_ = query_unfilled_orders(TARGET_PID, HOST_ACT) easylog.info("Going to cancel unfilled_orders_ count:%d", len(unfilled_orders_['rows'])) for row in unfilled_orders_["rows"]: ret=cancel_order(row["order_id"],{'trade_no':row["trade_no"]},HOST_ACT) if len(unfilled_orders_["rows"])>0: sltime = 6.0 easylog.info("will sleep %f seconds to wait cancel order ", sltime) time.sleep(sltime)
def now_to_hours_4_number(): snow=datetime.datetime.now().strftime('%Y-%m-%d') snow1=datetime.datetime.now().strftime('%Y-%m-%d %H') v=date2num(datetime.datetime.strptime(snow,'%Y-%m-%d')) tnow=date2num(datetime.datetime.strptime(snow1,'%Y-%m-%d %H'))-v x=math.floor(tnow*6)/6 easylog.info("flag_before: %s,%s,",snow1,x) return x+v
def send_dingding_msg(msg, access_token, timeout=5): headers = {'Content-Type': "application/json"} url = "https://oapi.dingtalk.com/robot/send" querystring = {"access_token": access_token} content = {"msgtype": "text", "text": {"content": msg}} try: response = requests.post(url, data=json.dumps(content), headers=headers, params=querystring, timeout=timeout) easylog.info('dingding send message:%s %s', msg, response.text) except Exception as e: easylog.exception('dingding msg:%s', msg)
def reload_robot_config(signum, frame): # { # "accept_price":0.8033, # "hour_max_buy":3000.10, # "day_max_buy":3000.10 * 10, # "week_max_buy": 3000.10 * 10 * 3, # "market_check_interval_sec" : 6.3, # "buy1_sell1_interval_sec" : 0.01, # "whole_depth_money" : 10000, # "oneday_min_volume" : 3500000 # } global g_config, V_, g_config_file easylog.info("starting to reload config with signal:%d", signum) with open(g_config_file) as fp: tmp = json.loads(fp.read()) g_config.update(tmp) V_ = g_config['accept_price']
def generate_k_line_basic(u,l,old=-1): global days global hours_4 global hours global mins_30 global mins_15 global mins_5 global mins_1 flag,days_l,days_u=get_u_l(u,l,days[0],days[1],days[2],6,old) if not flag: return days_u flag,hours_4_l,hours_4_u=get_u_l(days_u,days_l,hours_4[0],hours_4[1],hours_4[2],5,old) if not flag: return hours_4_u flag,hours_l,hours_u=get_u_l(hours_4_u,hours_4_l,hours[0],hours[1],hours[2],4,old) if not flag: return hours_u flag,mins_30_l,mins_30_u=get_u_l(hours_u,hours_l,mins_30[0],mins_30[1],mins_30[2],3,old) if not flag: return mins_30_u flag,mins_15_l,mins_15_u=get_u_l(mins_30_u,mins_30_l,mins_15[0],mins_15[1],mins_15[2],2,old) if not flag: return mins_15_u flag,mins_5_l,mins_5_u=get_u_l(mins_15_u,mins_15_l,mins_5[0],mins_5[1],mins_5[2],1,old) if not flag: return mins_5_u flag,mins_1_l,mins_1_u=get_u_l(mins_5_u,mins_5_l,mins_1[0],mins_1[1],mins_1[2],1,old) if not flag: return mins_1_u x=mins_1_l+random.random()*(mins_1_u-mins_1_l) set_basic_data(x) if u==x: easylog.info("flag_generate_x: old=%s \n days:%s \n hours_4:%s \n hours:%s \n mins_30:%s \n mins_15:%s \n mins_5:%s \n mins1_:%s \n",old,days,hours_4,hours,mins_30,mins_15,mins_5,mins_1) return x
def calculate_D1_D2(old_money,profits,count,U_value,V,a=0.01,alpha=0.8): """ old_money 原始的1W美金 profits 总利润 count 总销售量 U_value 真实买家卖单上边界 V 价值控制线 alpha 价值波动系数 """ d=[] bp=[] # 判断profits rb=calculate_rebuy_rate(old_money,profits) pp=profits-alpha*V*count if pp<0: pp=0 allocate_rate=get_initial_allocate_rate(1.18,[(6,0),(2.2,1)]) price_rate=[] price_rate_u=[] qq=1 e=0 allocate_count_D2=[] for i in range(27): e+=qq*allocate_rate[i] price_rate.append(qq) qq=qq/(1+a) qq=qq*(1+random_n()*a) pt=pp*rb+old_money easylog.info("allocate_rate:%s,price_rate:%s,profits:%s,count:%s,rb:%s,old_money:%s,V:%s,alpha:%s,U_value:%s,e:%s", allocate_rate,price_rate,profits,count,rb,old_money,V,alpha,U_value,e) l=calculate_u(allocate_rate,price_rate,profits,count,rb,old_money,V,alpha,U_value,e,a) D2,residue=allocate_D2(allocate_rate,price_rate,l,pt,e) qu=1 for i in range(27): price_rate_u.append(qu) qu=qu*(1+a) qu=qu*(1-random_n()*a) allocate_count_D2.append(D2[i][0]) D1=allocate_D1(allocate_rate,price_rate,allocate_count_D2,price_rate_u,profits,count,rb,old_money,V,alpha,l,a) return D1,D2
def calculate_depth(depth): """ sell_edge,self_edge,sum_d,under_v,D_l """ easylog.info("depth:%s", depth) global self_unfilled_orders_sell_helper,V D_l=sys.maxsize under_v=[] sum_d=0 sell_edge=sys.maxsize #其他人卖的下边界 self_edge=sys.maxsize for item in self_unfilled_orders_sell_helper: self_edge=min(item[0],self_edge) for d in depth: dprice=float(d["price"]) if not check_include_by_price(dprice): sell_edge=min(sell_edge,dprice) D_l=min(dprice,D_l) if dprice<self_edge: amount=(float(d["amount"])) under_v.append((amount,dprice)) sum_d+=amount*dprice easylog.info("sell_edge:%s self_edge:%s sum_d:%s under_v:%s D_l:%s", sell_edge,self_edge,sum_d,under_v,D_l) return sell_edge,self_edge,sum_d,under_v,D_l
def wrapper(*args, **kwargs): easylog.debug('Begin %s', method.__name__) start_point= time.time() method_rc = method(*args, **kwargs) easylog.info('End %s() FUNC TIME USAGE:%.3fs', method.__name__, time.time()-start_point) return method_rc
def wrapper(self, *args, **kwargs): easylog.debug('Begin %s.%s', self.__class__.__name__, method.__name__) start_point= time.time() method_rc = method(self, *args, **kwargs) easylog.info('End call %s.%s() FUNC TIME USAGE:%.3fs', self.__class__.__name__, method.__name__, time.time()-start_point) return method_rc
def main_process(conf_file): global V_,self_unfilled_orders_sell,self_filled_orders_sell,self_unfilled_orders_buy,self_filled_orders_buy global unfilled_orders,self_unfilled_orders,orders_helper,self_unfilled_orders_sell_helper,self_unfilled_orders_buy_helper global g_config, g_config_file global days global mins_1 g_config_file = conf_file reload_robot_config(1, None) if not init_hooclient(g_config['dbfile'], g_config['client_id'], g_config['client_key'], g_config['dding_atoken'], g_config['bos_pairid']): easylog.error('Failed to init_hooclient()') return D1=[] D2=[] old_x=0 back_start_time=0 analyse_circle_startime=0 self_buy_delimited=0 back_pow=0 profits=0 count=0 spend=0 spend_c=0 jd=load_data() if jd: profits=jd["profits"] count=jd["count"] spend=jd["spend"] spend_c=jd["spend_c"] time_circle=date2num(datetime.datetime.now()) up_count=0 up_spend_c=0 #U_value=0.04 #V_=0.005633 U_value= 1.02 * V_ tm=date2num(datetime.datetime.now()) week_end=tm+7 day_end=tm+1 hour_end=tm+1/24 week_spend=0 day_spend=0 hour_spend=0 old_self_sell_max=10000 old_self_buy_min=sys.maxsize t_spend=0 t_profits=0 t_spend_c=0 t_profits_C=0 hit_hour_max_check_wait_interval=2.0 D1_l=0 D_l=0 self_buy_under_V=0 distance=0 model=0 update_D=True setup_env() while True : try: ##查询orders unfilled_orders_ = query_unfilled_orders(TARGET_PID, HOST_ACT) filled_orders_=query_filled_orders(TARGET_PID, HOST_ACT) tm=date2num(datetime.datetime.now()) buy_sell_1_cash_amount = [0,0] # calculate the buy&sell first order dealed by others instead of robot buy_sell_1_amount = [0,0] # 0: buy, 1: sell ## 分析 orders #1.计算profits 和count 同时找出 下探点 profits_=0 count_=0 spend_=0 spend_c_=0 self_sell_price_min=0 self_buy_min=sys.maxsize rows=unfilled_orders_["rows"] for row in rows: if row["side"]=='sell': if row["order_id"] in sell_1: buy_sell_1_cash_amount[1] = float(row["filled_cash_amount"]) buy_sell_1_amount[1]=float(row["filled_amount"]) continue if row["order_id"] in self_unfilled_orders_sell.keys(): old_record=self_unfilled_orders_sell[row["order_id"]] filled_amount=float(row["filled_amount"]) filled_cash_amount=float(row["filled_cash_amount"]) D1_l=min(D1_l,float(row["price"])) if filled_cash_amount>old_record["filled_cash_amount"]: profits_+=filled_cash_amount-old_record["filled_cash_amount"] count_+=filled_amount-old_record["filled_amount"] easylog.debug("flag1:unfilled sell %s filled_cash_amount:%s old_filled_cash_amount:%s,profits_:%s,count_:%f", row["order_id"], filled_cash_amount,old_record["filled_cash_amount"],profits_,count_) self_unfilled_orders_sell[row["order_id"]]["filled_cash_amount"]=filled_cash_amount self_unfilled_orders_sell[row["order_id"]]["filled_amount"]=filled_amount self_sell_price_min=max(self_sell_price_min,float(row["price"])) else: #ret = cancel_order(row["order_id"],{'trade_no':row["trade_no"]},HOST_ACT) easylog.info("unfilled SELL Order not exist,order:%s", row) else: if row["order_id"] in buy_1: buy_sell_1_cash_amount[0]= float(row["filled_cash_amount"]) buy_sell_1_amount[0]=float(row["filled_amount"]) if row["order_id"] in back_buy_orders: cancel_order_for_back_buy(row["order_id"]) continue if row["order_id"] in self_unfilled_orders_buy.keys(): old_record=self_unfilled_orders_buy[row["order_id"]] filled_amount=float(row["filled_amount"]) filled_cash_amount=float(row["filled_cash_amount"]) if filled_cash_amount>old_record["filled_cash_amount"]: spend_+=filled_cash_amount-old_record["filled_cash_amount"] spend_c_+=filled_amount-old_record["filled_amount"] easylog.debug("flag1:unfilled no-sell %s filled_cash_amount:%s old_filled_cash_amount:%s,spend_:%s,spend_c_:%f", row["order_id"], filled_cash_amount,old_record["filled_cash_amount"],spend_,spend_c_) self_unfilled_orders_buy[row["order_id"]]["filled_cash_amount"]=filled_cash_amount self_unfilled_orders_buy[row["order_id"]]["filled_amount"]=filled_amount self_buy_min=min(self_buy_min,float(row["price"])) else: #ret = cancel_order(row["order_id"],{'trade_no':row["trade_no"]},HOST_ACT) easylog.info("unfilled BUY Order not exist,order:%s", row) rows=filled_orders_["rows"] for row in rows: if row["status"]=='canceled': if row['order_id'] in self_unfilled_orders_buy.keys(): del self_unfilled_orders_buy[row['order_id']] delete_list(row['order_id'],self_unfilled_orders_buy_helper,1) elif row['order_id'] in self_unfilled_orders_sell.keys(): del self_unfilled_orders_sell[row["order_id"]] delete_list(row["order_id"],self_unfilled_orders_sell_helper,1) continue if row["side"]=='sell': if row["order_id"] in sell_1: buy_sell_1_cash_amount[1]= float(row["filled_cash_amount"]) buy_sell_1_amount[1]=float(row["filled_amount"]) sell_1.remove(row["order_id"]) continue if row["order_id"] in self_unfilled_orders_sell.keys(): old_record=self_unfilled_orders_sell[row["order_id"]] filled_amount=float(row["filled_amount"]) filled_cash_amount=float(row["filled_cash_amount"]) if filled_cash_amount>old_record["filled_cash_amount"]: profits_+=filled_cash_amount-old_record["filled_cash_amount"] count_+=filled_amount-old_record["filled_amount"] easylog.debug("flag1:filled sell %s filled_cash_amount:%s old_filled_cash_amount:%s,profits_:%s,count_:%f", row["order_id"], filled_cash_amount,old_record["filled_cash_amount"],profits_,count_) self_sell_price_min=max(self_sell_price_min,float(row["price"])) del self_unfilled_orders_sell[row["order_id"]] delete_list(row["order_id"],self_unfilled_orders_sell_helper,1) else: if row["order_id"] in buy_1: buy_1.remove(row["order_id"]) buy_sell_1_cash_amount[0]= float(row["filled_cash_amount"]) buy_sell_1_amount[0]=float(row["filled_amount"]) if row["order_id"] in back_buy_orders: del back_buy_orders[row["order_id"]] if row["order_id"] in self_unfilled_orders_buy.keys(): old_record=self_unfilled_orders_buy[row["order_id"]] filled_amount=float(row["filled_amount"]) filled_cash_amount=float(row["filled_cash_amount"]) if filled_cash_amount>old_record["filled_cash_amount"]: spend_+=filled_cash_amount-old_record["filled_cash_amount"] spend_c_+=filled_amount-old_record["filled_amount"] easylog.debug("flag1:filled no-sell %s filled_cash_amount:%s old_filled_cash_amount:%s,spend_:%s,spend_c_:%f", row["order_id"], filled_cash_amount,old_record["filled_cash_amount"],spend_,spend_c_) self_buy_min=min(self_buy_min,float(row["price"])) del self_unfilled_orders_buy[row["order_id"]] delete_list(row["order_id"],self_unfilled_orders_buy_helper,1) depths = query_pair_book(TARGET_PID) buy_depth=depths["data"]["bids"] sell_depth=depths["data"]["asks"] sell_edge,self_edge,sum_d,under_v,D_l=calculate_depth(sell_depth) profits+=profits_ count+=count_ spend+=spend_ spend_c+=spend_c_ if buy_sell_1_cash_amount[0]>buy_sell_1_cash_amount[1]: spend+=buy_sell_1_cash_amount[0]-buy_sell_1_cash_amount[1] spend_c+=buy_sell_1_amount[0]-buy_sell_1_amount[1] else: profits+=buy_sell_1_cash_amount[1]-buy_sell_1_cash_amount[0] count+=buy_sell_1_amount[1]-buy_sell_1_amount[0] if buy_sell_1_cash_amount[0] != buy_sell_1_cash_amount[1]: easylog.info("buy_sell_1_cash_amount:%s buy_sell_1_amount:%s", buy_sell_1_cash_amount, buy_sell_1_amount) profits_and_spen = profits-spend count_and_spen_c = count-spend_c store_data(profits,count,spend,spend_c) if len(buy_depth)>0 and len(sell_depth)>0 and float(buy_depth[0]['price']) > float(sell_depth[0]['price']): easylog.error("WRONG depth occur:%s", depths) sys.exit(1) if len(sell_depth)>0 and len(D2)>0 and len(D2[0])>0 and float(sell_depth[0]['price']) < D2[0][1]: easylog.warning("WARNING depth occur: depths %s D1:%s D2:%s", depths, D1, D2) x=0 if model==0: easylog.info("model==0 self_sell_price_min:%s D_l:%s", self_sell_price_min,D_l) U_value=max(self_sell_price_min,D_l) # self_buy_min 自我买单边 # D1_l=0 自我挂卖单边 # D_l=0 所有挂单边 # self_buy_under_V=0 # distance 距离差 #被吃单判断 触发还可以更改一下 if spend_c_>0: old_self_buy_min=self_buy_min #等待 t_spend_c+=spend_c_ t_spend+=spend_ t_profits+=profits_ t_profits_C+=count_ time.sleep(hit_hour_max_check_wait_interval) continue if t_spend_c>0: if sell_edge<V_ and t_profits_C>0: U_value=min(sell_edge,old_self_buy_min) tv=max(profits_and_spen,0) tc=max(count_and_spen_c,0) if profits_and_spen<0 or count_and_spen_c<0 : tv=0 tc=0 D1,D2=calculate_D1_D2(g_config['whole_depth_money'],tv,tc,U_value,V_) easylog.info("D1:%s D2:%s whole_depth_money:%s profits:%s count:%s spend:%s spend_c:%s old_self_buy_min:%s sell_edge:%s V_:%s", D1,D2,g_config['whole_depth_money'],profits,count,spend,spend_c,old_self_buy_min,sell_edge,V_) time_circle=date2num(datetime.datetime.now()) create_sell_orders(D1) create_buy_orders(D2) depths = query_pair_book(TARGET_PID) buy_depth=depths["data"]["bids"] sell_depth=depths["data"]["asks"] sell_edge,self_edge,sum_d,under_v,D_l=calculate_depth(sell_depth) # 判断 D1_l与D_l之间的关系 if D1[0][1] <D_l: #随机游走模式 model=2 else: #缓慢上买模式 model=1 t_spend_c=0 t_spend=0 t_profits=0 t_profits_C=0 tp=date2num(datetime.datetime.now()) if tp-time_circle > 1/96: easylog.info("tp:%s time_circle:%s", tp, time_circle) update_D=True time_circle=tp if model==0 and profits_>0: U_value=self_sell_price_min easylog.info("model==0 and profits_>0 set update_D=True,self_sell_price_min:%s",self_sell_price_min) update_D=True if update_D: #U_value? tv=max(profits_and_spen,0) tc=max(count_and_spen_c,0) if profits_and_spen<0 or count_and_spen_c<0 : tv=0 tc=0 D1,D2=calculate_D1_D2(g_config['whole_depth_money'],tv,tc,U_value,V_) easylog.info("D1:%s D2:%s whole_depth_money':%s profits:%s count:%s spend:%s spend_c:%s U_value:%s V_:%s", D1,D2,g_config['whole_depth_money'],profits,count,spend,spend_c,U_value,V_) create_sell_orders(D1) create_buy_orders(D2) time_circle=date2num(datetime.datetime.now()) depths = query_pair_book(TARGET_PID) buy_depth=depths["data"]["bids"] # all buy orders sell_depth=depths["data"]["asks"] # all sell orders sell_edge,self_edge,sum_d,under_v,D_l=calculate_depth(sell_depth) update_D = False if model==1: easylog.debug("==1=> model1") if sum_d>0 and D1[0][1] >=D_l: tm=date2num(datetime.datetime.now()) while tm>week_end: week_end+=7 week_spend=0 while tm>day_end: day_end+=1 day_spend=0 while tm>hour_end: hour_end+=1/24 hour_spend=0 canspend=calculate_back_count(sum_d,g_config['week_max_buy'],g_config['day_max_buy'],g_config['hour_max_buy'],week_spend,day_spend,hour_spend) easylog.info("week_end:%s,day_end:%s,hour_end:%s,tm:%s,canspend:%s,hour_spend:%s sum_d:%s hour_spend:%s week_spend:%s,day_spend:%s", week_end,day_end,hour_end,tm,canspend,hour_spend,sum_d,hour_spend,week_spend,day_spend) x=generate_buy(week_end,day_end,hour_end,tm,canspend,hour_spend,(g_config['buy1_sell1_interval_sec']+g_config['market_check_interval_sec'])/24/3600) x_ = x if x > 0: under_v.sort(key=take_second) if under_v[0][0]*under_v[0][1]<x: countx=under_v[0][0] x=under_v[0][1] else: countx=x/under_v[0][1] x=under_v[0][1] easylog.info("t3:sum_d:%s canspend:%s x_:%s x:%s countx:%s under_v[0]:%s", sum_d,canspend, x_, x, countx, under_v[0]) create_buy_order((countx, x),True) xc=x*countx week_spend+=xc day_spend+=xc hour_spend+=xc U_value=x if g_config['buy1_sell1_interval_sec']>0: time.sleep(g_config['buy1_sell1_interval_sec']) else: model=2 if model==2: easylog.debug("==2=> model2") #随机设置U_value #判断结束条件 if D1[0][1]>V_ and D_l>V_: model=0 continue if sum_d>0: model=1 continue #1.查看是否有人买我的卖单,并得出吃单位置 #需要迅速上移U_value if self_sell_price_min>0: U_value=self_sell_price_min tv=max(profits_and_spen,0) tc=max(count_and_spen_c,0) if profits_and_spen<0 or count_and_spen_c<0 : tv=0 tc=0 D1,D2=calculate_D1_D2(g_config['whole_depth_money'],tv,tc,U_value,V_) easylog.info("model2: D1:%s D2:%s whole_depth_money:%s profits:%s count:%s old_self_buy_min:%s sell_edge:%s V_:%s", D1,D2,g_config['whole_depth_money'],profits,count,old_self_buy_min,sell_edge,V_) time_circle=date2num(datetime.datetime.now()) create_sell_orders(D1) create_buy_orders(D2) continue db_max=0 for item in buy_depth: dprice=float(item["price"]) db_max=max(db_max,dprice) if db_max>D1[0][1]: easylog.error("db_max>D1[0][1]: %s > %s",db_max,D1[0][1]) l=min(old_self_buy_min,db_max) U_value=l+(D1[0][1]-l)*random_beta(7,3) x=0 countx=0 if x==0: easylog.debug("model = %d", model) tm=date2num(datetime.datetime.now()) x=generate_k_line(min(U_value,D1[0][1]),D2[0][1],tm,old_x) old_x=x countx=(g_config['buy1_sell1_interval_sec']+g_config['market_check_interval_sec'])*g_config['oneday_min_volume']/(min(U_value,D1[0][1])*0.98)/600 if days[2]>0 and mins_1[2]>0: tmv=mins_1[2]/days[2] else: tmv=1/144*(0.6+random.random()) if tmv>1/70: tmv=1/70.0*(0.5+0.5*random.random()) countx*=tmv countx=countx*(0.2+random.random()*0.8) easylog.info("countx:%s x:%s U_value:%s tmv:%s", countx, x, U_value, tmv) x = round(x, PRICE_RNUM) buy_max,buy_count=calculate_buy_edge(buy_depth) normal=False if buy_max<x: normal=True else: tr=random.random() if tr<0.08: if buy_count < MIN_TOKEN_AMOUNT: buy_count = MIN_TOKEN_AMOUNT create_sell_order((buy_count, buy_max)) elif tr<0.2: buy_count_tp = buy_count*(0.1+random.random()*0.9) if buy_count_tp < MIN_TOKEN_AMOUNT: buy_count_tp = buy_count create_sell_order((buy_count_tp, buy_max)) else: normal=True ds=D_l-buy_max if ds>0: x=buy_max+ds*random_beta(0.08,11) x = round(x, PRICE_RNUM) easylog.debug("normal:%s tr:%f ds:%s buy_max:%s x:%s", normal, tr, D_l-buy_max, buy_max, x) if normal: if countx < MIN_TOKEN_AMOUNT: countx = MIN_TOKEN_AMOUNT * (1+random.random()) rrt=random.random() if rrt<0.5: create_buy_order((countx, x)) if g_config['buy1_sell1_interval_sec']>0: time.sleep(g_config['buy1_sell1_interval_sec']) create_sell_order((countx, x)) else: create_sell_order((countx, x)) if g_config['buy1_sell1_interval_sec']>0: time.sleep(g_config['buy1_sell1_interval_sec']) create_buy_order((countx, x)) time.sleep(g_config['market_check_interval_sec']) except Exception as ee: try: easylog.exception("Exception:%s", ee) send_dingding_msg("HooRobot restarted Exception:"+str(ee), g_config['dding_atoken']) store_data(profits,count,spend,spend_c) D1=[] D2=[] old_x=0 back_start_time=0 analyse_circle_startime=0 self_buy_delimited=0 back_pow=0 profits=0 count=0 spend=0 spend_c=0 jd=load_data() if jd: profits=jd["profits"] count=jd["count"] spend=jd["spend"] spend_c=jd["spend_c"] time_circle=date2num(datetime.datetime.now()) up_count=0 up_spend_c=0 #U_value=0.04 #V_=0.005633 U_value= 1.02 * V_ tm=date2num(datetime.datetime.now()) week_end=tm+7 day_end=tm+1 hour_end=tm+1/24 week_spend=0 day_spend=0 hour_spend=0 old_self_sell_max=10000 old_self_buy_min=sys.maxsize t_spend_c=0 t_spend=0 t_profits=0 t_profits_C=0 hit_hour_max_check_wait_interval=2.0 D1_l=0 D_l=0 self_buy_under_V=0 distance=0 model=0 update_D=True setup_env() except Exception as eee: easylog.exception("Exception:%s", eee)
t_profits_C=0 hit_hour_max_check_wait_interval=2.0 D1_l=0 D_l=0 self_buy_under_V=0 distance=0 model=0 update_D=True setup_env() except Exception as eee: easylog.exception("Exception:%s", eee) if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("-c", "--conf", help="the config file path", ) parser.add_argument("-d", "--debug", help='debug mode enable', default=False, action="store_true") args = parser.parse_args() if not args.conf: parser.print_usage() sys.exit(1) if args.debug: easylog.setup("./hoolog.out", level='debug', log_file_enable=False) else: easylog.setup("./hoolog.out", level='info', log_file_enable=True) easylog.info("Start to Rock") signal.signal(signal.SIGUSR1, reload_robot_config) main_process(args.conf)