def outputRes(self,df_final,timestamp,buyCount): trade = self.__config.get_t1()['trade'] if buyCount <= 0: return None buyMoney = (float(df_final['price']) + trade['addPrice']) * trade['volume'] if buyMoney > self.__balance: return None price = str('%.2f' % (float(df_final['price']) + trade['addPrice'])) info = '[%s] 在 %s 以 %s 买入 [%s]%s %s 股' % (Utils.getCurrentTime(),str(df_final['date']) + ' ' + str(df_final['time']), price, df_final['code'], df_final['name'], str(trade['volume'])) MyLog.info(info) now = dt.datetime.now() deltaSeconds = (now - timestamp).seconds if deltaSeconds > trade['timestampLimit']: MyLog.info('[%s] 行情超时 %s秒 放弃买入' % (df_final['code'],deltaSeconds)) return None if trade['enable']: res = str(self.__trade.buy(df_final['code'],trade['volume'],float(price))) if 'entrust_no' in res: self.__buyedCount = self.__buyedCount + 1 self.__balance = self.__balance - buyMoney return df_final['code'] return None if trade['enableMock']: res = self.__mockTrade.mockTrade(df_final['code'],float(price),trade['volume']) if res == 0: self.__buyedCount = self.__buyedCount + 1 self.__balance = self.__balance - buyMoney return df_final['code'] return None return df_final['code']
def isBigMoneyMatch(self, stock, conf): p = stock.get_net() / stock.getBigMoneyIn() flag = p > self.__config.get_t1()['big_money']['threshold'] if flag == True: last_line = stock.get_Lastline() info = '[%s] *** [%s] match big_money at %s %s,net=%s,in=%s,p=%s ***' % ( Utils.getCurrentTime(), stock.get_code(), last_line['date'], last_line['time'], str( stock.get_net()), str(stock.getBigMoneyIn()), str(p * 100)) MyLog.info(info) return flag
def cancelBuyIfNeed(self, stock, dh, timestamp, lock, balance): trade = self.__config.get_t1()['trade'] last_second_line = stock.get_LastSecondline() now_line = stock.get_Lastline() last_second_buy1_v = self.convertToFloat(last_second_line['b1_v']) last_second_buy1_amount = float( last_second_line['b1_p']) * last_second_buy1_v * 100 now_buy1_v = self.convertToFloat(now_line['b1_v']) now_buy1_amount = float(now_line['b1_p']) * now_buy1_v * 100 stop_price = round(float(now_line['pre_close']) * 1.1, 2) max_b1_amount = stock.get_cache('max_b1_amount') deal_amount = self.convertToFloat( now_line['amount']) - self.convertToFloat( last_second_line['amount']) cancel_b1_amount = self.__config.get_t1()['hit10']['cancel_b1_amount'] strTime = time.strftime('%H:%M:%S', time.localtime(time.time())) if strTime > '13:30:00': cancel_b1_amount = self.__config.get_t1( )['hit10']['cancel_b1_amount_1'] if strTime > '14:30:00': cancel_b1_amount = self.__config.get_t1( )['hit10']['cancel_b1_amount_2'] if max_b1_amount is None: max_b1_amount = -1 sum_last_10_deal_amount = 0 last_10_deal_amount = stock.get_cache('deal_amount') if last_10_deal_amount is not None: sum_last_10_deal_amount = sum(last_10_deal_amount) if float(now_line['price']) == stop_price: if float(now_line['b1_p']) == stop_price and self.convertToFloat( now_line['a1_v'] ) == 0 and ( now_buy1_amount < cancel_b1_amount or now_buy1_v < last_second_buy1_v * self.__config.get_t1()['hit10']['cancel_ratio'] or now_buy1_amount < max_b1_amount * self.__config.get_t1()['hit10']['cancel_ratio_max_amount'] or deal_amount >= now_buy1_amount * self.__config.get_t1()['hit10']['cancel_deal_amount_ratio'] or sum_last_10_deal_amount > now_buy1_amount * self.__config.get_t1()['hit10']['max_deal_amount']): info = '[%s] 在 [%s] 撤单 [%s],b1_v=%s' % ( Utils.getCurrentTime(), str(now_line['date']) + ' ' + str(now_line['time']), stock.get_code(), now_buy1_v) MyLog.info(info) if trade['enable'] or trade['enableMock']: self.cancelBuy(trade, stock, dh, lock, balance)
def isSpeedMatch(self, stock, conf): v30 = stock.get_speed('v30') v120 = stock.get_speed('v120') v300 = stock.get_speed('v300') p = self.getCurrentPercent(stock) v_list = [v30, v120, v300] flag = False if v_list[0] * 30 >= ( 10 - p) * self.__config.get_t1()['speed']['v30_ratio']: flag = True elif v_list[0] >= self.__config.get_t1()['speed']['v30'] and ( v_list[1] >= self.__config.get_t1()['speed']['v120'] or v_list[2] >= self.__config.get_t1()['speed']['v300']): flag = True if flag == True: last_line = stock.get_Lastline() info = '[%s] *** [%s] match speed at %s %s,v30=%s,v120=%s,v300=%s ***' % ( Utils.getCurrentTime(), stock.get_code(), last_line['date'], last_line['time'], str(v30), str(v120), str(v300)) MyLog.info(info) return flag
def isReach10Again(self, stock): now_line = stock.get_Lastline() stop_price = round(float(now_line['pre_close']) * 1.1, 2) if float(now_line['b1_p']) == stop_price and self.convertToFloat( now_line['a1_v']) == 0: stock.set_cache('min_break', None) stock.set_cache('status', None) return False else: if self.convertToFloat(now_line['a5_v']) != 0: return False if stock.get_cache('min_break') is None or stock.get_cache( 'min_break') > self.__config.get_t1( )['hit10']['min_break']: return False if stock.get_cache('break_time') is None or ( dt.datetime.now() - stock.get_cache('break_time') ).seconds > self.__config.get_t1()['hit10']['break_time']: return False if stock.get_cache('hit_top_time') is None or ( stock.get_cache('break_time') - stock.get_cache('hit_top_time') ).seconds < self.__config.get_t1()['hit10']['hit_break_inter']: return False total_sell = 0 for i in range(1, 6): total_sell += self.convertToFloat( now_line['a' + str(i) + '_v']) * self.convertToFloat( now_line['a' + str(i) + '_p']) * 100 if total_sell > stock.get_cache( 'max_b1_amount') * self.__config.get_t1( )['hit10']['max_b1_amount_ratio']: return False info = '[%s]在[%s][%s] match 10,b1_v=%s' % ( Utils.getCurrentTime(), str(now_line['date']) + ' ' + str(now_line['time']), stock.get_code(), now_line['b1_v']) MyLog.info(info) return True