def post(self, request): welcome_str_after_register = '欢迎注册' register_form = RegisterForm(request.POST) if register_form.is_valid(): user_name = request.POST.get('email', '') if UserProfile.objects.filter(email=user_name): msg = '用户名已存在' return render(request, 'register.html', locals()) pass_word = request.POST.get('password', '') user_profile = UserProfile() user_profile.username = user_name user_profile.email = user_name user_profile.is_active = False # 使用django内置的哈希模块加密密码 user_profile.password = make_password(pass_word) user_profile.save() send_message(user=user_profile, msg='欢迎您的注册!') # 发送激活连接给邮箱 msg = send_register_email(user_name, 'register') return render(request, 'login.html', locals()) else: return render(request, 'register.html', locals())
def run_task(body): data = json.loads(body, encoding='utf-8') snapshot_id = data['id'] source_location = data['sourceLocation'] organization_id = data['organizationId'] project_id = data['projectId'] build_id = data['buildId'] title = data['title'] width = data['width'] browser = data['browser'] selector = data.get('selector', None) hide_selectors = data.get('hideSelectors', None) compare_snapshot = data.get('compareSnapshot', None) flake_sha_list = data.get('flakeShas', []) save_snapshot = compare_snapshot == None snapshop_image, image_location = render_snapshot( source_location, organization_id, project_id, build_id, title, width, browser, selector, hide_selectors, save_snapshot ) message = { 'id': data['id'], } if data.get('compareSnapshot'): diff_location, difference, image_location, diff_sha, flake_matched = diff_snapshot( snapshop_image, organization_id, project_id, build_id, browser, title, width, compare_snapshot, flake_sha_list, True ) if not flake_matched: message['diffLocation'] = diff_location message['differenceAmount'] = str(difference) message['diffSha'] = diff_sha message['difference'] = not flake_matched and difference > 0.1 message['flakeMatched'] = flake_matched message['imageLocation'] = image_location send_message(message)
def run(ticker): signal_is_sent = check_signal_is_sent(ticker) if (not signal_is_sent): tf_1hour = get_candles(ticker) rsi_1hour = RSIIndicator(close=tf_1hour.close).rsi() bolinger_1hour = BollingerBands(close=tf_1hour.close) condition_short = rsi_1min[-1] >= 80 and rsi_5min[-1] >= 80 condition_long = rsi_1min[-1] <= 20 and rsi_5min[-1] <= 20 # Trade size depends on STOP_LOSS_THRESH. MT5 limitations. STOP_LOSS_THRESH = ( open_close_hour_dif_mean[ticker] ) trade_size = calculate_trade_size( STOP_LOSS_THRESH, tf_1min.close[-1] ) / ticker_info[ticker]['min_lot'] trade_size = round(trade_size) cur_time = str(datetime.now().time()) if condition_short: sl = round( tf_1min.close[-1] + STOP_LOSS_THRESH * tf_1min.close[-1], ticker_info[ticker]['price_digits'] ) tp = round( tf_1min.close[-1] - STOP_LOSS_THRESH * tf_1min.close[-1], ticker_info[ticker]['price_digits'] ) print('\n', cur_time, ticker, ': SHORT', str(trade_size), tf_1min.close[-1], sl, tp, '\n') messsage = ' '.join( [cur_time, ticker, 'SHORT', str(trade_size), str(sl), str(tp)] ) send_message(messsage) set_signal_is_sent_flag(ticker) elif condition_long: sl = round( tf_1min.close[-1] - STOP_LOSS_THRESH * tf_1min.close[-1], ticker_info[ticker]['price_digits'] ) tp = round( tf_1min.close[-1] + STOP_LOSS_THRESH * tf_1min.close[-1], ticker_info[ticker]['price_digits'] ) print('\n', cur_time, ticker, ': LONG', str(trade_size), tf_1min.close[-1], sl, tp, '\n') messsage = ' '.join( [cur_time, ticker, 'LONG', str(trade_size), str(sl), str(tp)] ) send_message(messsage) set_signal_is_sent_flag(ticker)
def run(ticker): #print(ticker) if not mt5.initialize(): print("initialize() failed, error code =", mt5.last_error()) quit() info = mt5.symbol_info(ticker) if ticker not in USA_STOCKS: df_1min = get_candles( ticker, 'mt5.TIMEFRAME_M1', 5000).loc[:, ['open', 'high', 'low', 'close', 'volume']] else: # Получаем с яху, потому что с МТ5 с 15 минутным лагом df_1min = get_american_candles( ticker, '3d', '1m').loc[:, ['open', 'high', 'low', 'close', 'volume']] df_5min = df_1min.resample('5Min').agg(AGG_DICT) df_hour = df_1min.resample('60Min').agg(AGG_DICT) df_day = df_1min.resample('1D').agg(AGG_DICT) rsi = RSI() df_1min = rsi.get_value_df(df_1min) df_5min = rsi.get_value_df(df_5min) signal = check_trade_conditions(ticker, df_day, df_hour, df_5min, df_1min) if signal is not None: signal_is_sent = check_signal_is_sent(ticker) position = get_positions(ticker) if (not signal_is_sent) and (position is None): acceptable_PERC_loss = (open_close_5min_dif_mean[ticker] + open_close_5min_dif_std[ticker]) last_close = df_5min.close[-1] trade_size = calculate_trade_size(ticker, acceptable_PERC_loss, last_close) contract_size = info.trade_contract_size min_volume = info.volume_min trade_size = round(trade_size / contract_size / min_volume) trade_size = trade_size * min_volume direction = 'sell' if signal == 'sell' else 'buy' send_message(ticker + ' ' + direction + ' ' + str(trade_size)) print(send_transaction(ticker, trade_size, direction)) cur_time = datetime.now().time() print(cur_time, ticker, direction, trade_size) set_signal_is_sent_flag(ticker)
def run_task(snapshot_id, organization_id, project_id, build_id, source_location, title, width, browser, selector, hide_selectors, compare_snapshot): title = ' '.join(title) snapshop_image, image_location = render_snapshot(source_location, organization_id, project_id, build_id, title, width, browser, selector, hide_selectors) message = {'id': snapshot_id, 'imageLocation': image_location} if compare_snapshot: diff_location, difference, image_location, diff_sha, flake_matched = diff_snapshot( snapshop_image, organization_id, project_id, build_id, browser, width, [], compare_snapshot) message['diffLocation'] = diff_location message['difference'] = 0 if difference == 0 else difference send_message(message)
sqs = boto3.resource('sqs') queue = sqs.Queue(SQS_BUILD_QUEUE_URL) print('getting messages') def get_messages(): return queue.receive_messages(MaxNumberOfMessages=10, WaitTimeSeconds=10) messages = get_messages() print('received messages: {}'.format(len(messages))) while len(messages) > 0: messages = sorted( messages, key=lambda m: json.loads(m.body, encoding='utf-8')['browser']) for message in messages: message_data = process_message(message.body) if message_data is not None: send_message(message_data) message.delete() messages = get_messages() print('received more messages: {}'.format(len(messages))) try: finished() except: pass
def consume_message(ch, method, _, body): with block_signals(): message = process_message(body) if message is not None: send_message(message) ch.basic_ack(delivery_tag=method.delivery_tag)