diff --git a/README.md b/README.md index dfc202a..7593332 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,6 @@ Commands: - /stock ( (default: 1 year ago)> ( (default: today)): Computing statistical information for the given symbol. - /stockg ( (default: 1 year ago)> ( (default: today)): Computing statistical information for the given symbol, and the chart plotting. - /stockcorr : correlation between two symbols -- /search : find the symbol name from the given text - /help: display help message. Telegram: @FinportTelebot ([https://t.me/FinportTelebot](https://t.me/FinportTelebot)) diff --git a/finportbotutil/syminfo.py b/finportbotutil/syminfo.py index a2b084a..1dc84be 100644 --- a/finportbotutil/syminfo.py +++ b/finportbotutil/syminfo.py @@ -34,36 +34,32 @@ async def get_symbols_correlation(symbol1, symbol2, startdate, enddate, api_url) async def get_plots_infos(symbol, startdate, enddate, api_url): - payload = json.dumps({ - 'startdate': startdate, - 'enddate': enddate, - 'components': { - 'name': 'DynamicPortfolio', - 'current_date': enddate, - 'timeseries': [ - { - 'date': startdate, - 'portfolio': {symbol: 1} - } - ] + done = False + while not done: + payload = json.dumps({ + 'startdate': startdate, + 'enddate': enddate, + 'components': { + 'name': 'DynamicPortfolio', + 'current_date': enddate, + 'timeseries': [ + { + 'date': startdate, + 'portfolio': {symbol: 1} + } + ] + } + }) + headers = { + 'Content-Type': 'application/json' } - }) - headers = { - 'Content-Type': 'application/json' - } - - response = requests.request('GET', api_url, headers=headers, data=payload) - return json.loads(response.text) + response = requests.request('GET', api_url, headers=headers, data=payload) -async def search_symbols(querystring, api_url): - payload = json.dumps({'querystring': querystring, 'topn': 6}) - headers = { - 'Content-Type': 'application/json' - } - - response = requests.request('GET', api_url, headers=headers, data=payload) - return json.loads(response.text) + response_dict = json.loads(response.text) + if 'plot' in response_dict: + done = True + return response_dict async def get_ma_plots_info(symbol, startdate, enddate, dayswindow, api_url, title=None): diff --git a/main.py b/main.py index 6025ac6..d21b170 100644 --- a/main.py +++ b/main.py @@ -38,16 +38,9 @@ # Stock correlation API stockcorr_api_url = os.getenv('STOCKCORR') -# Search API -search_api_url = os.getenv('SEARCH') -modelloadretry = int(os.getenv('SEARCHMODELLOADRETRY', 5)) - # Add or Modify User ARN addmodifyuser_arn = os.environ.get('ADDUSERARN') -# Symbol Search Wrapper ARN -searchwrappwer_arn = os.environ.get('SEARCHWRAPPERARN') - # fit LPPL model URL fit_lppl_url = os.environ.get('FITLPPL') @@ -60,7 +53,6 @@ CMD_TIPS = ['tips'] CMD_STOCK = ['stock', 'stockg'] CMD_STOCKCORR = ['stockcorr'] -CMD_SEARCH = ['search'] CMD_MA50 = ['stockgma50'] CMD_MA200 = ['stockgma200'] CMD_SP500_MA = ['sp500ma'] @@ -380,52 +372,6 @@ def handling_stockcorrelation_message(message): return {'message': message_text, 'result': results} -@bot.message_handler(commands=CMD_SEARCH) -def handling_search(message): - logging.info(message) - print(message) - - if ispolling: - querystring = message.text[8:].strip() - logging.info('query string: {}'.format(querystring)) - print('query string: {}'.format(querystring)) - for i in range(modelloadretry): - results = asyncio.run(search_symbols(querystring, search_api_url)) - if 'message' in results and 'timed out' in results['message']: - logging.info('Trial {} fail'.format(i)) - print('Trial {} fail'.format(i)) - bot.reply_to(message, 'Model loading...') - elif 'queryresults' in results: - break - else: - logging.info('Trial {} fail with error'.format(i)) - print('Trial {} fail with error'.format(i)) - bot.reply_to(message, 'Unknown error; retrying...') - logging.info(results) - print(results) - if 'queryresults' not in results: - bot.reply_to(message, 'Unknown error.') - return {'message': 'Unknown error.'} - else: - symbol_and_descp = [ - symbolprob['symbol'] + ' : ' + symbolprob['descp'] - for symbolprob in sorted(results['queryresults'], key=itemgetter('prob'), reverse=True) - ] - bot.reply_to(message, '\n'.join(symbol_and_descp)) - return { - 'message': '\n'.join(symbol_and_descp), - 'result': results - } - else: - lambda_client = boto3.client('lambda') - lambda_client.invoke( - FunctionName=searchwrappwer_arn, - InvocationType='Event', - Payload=json.dumps(message.json) - ) - return {'message': None, 'comment': 'Search done using another Lambda'} - - def plotting_index_ma(index, plottitle): enddate = date.today().strftime('%Y-%m-%d') startdate = (date.today() - relativedelta(years=1)).strftime('%Y-%m-%d') diff --git a/messagetemplates/help.txt b/messagetemplates/help.txt index 3c3b92b..e123a68 100644 --- a/messagetemplates/help.txt +++ b/messagetemplates/help.txt @@ -4,7 +4,6 @@ /stock : Computing the statistics of a symbol (Arguments: symbol [startdate] [enddate]) (date format: YYYY-mm-dd) /stockg : Computing the statistics of a symbol, and plotting (Arguments: symbol [startdate] [enddate]) (date format: YYYY-mm-dd) /stockcorr : Computing the correlation between two symbols (Arguments: symbol1 symbol2 [startdate] [enddate]) (date format: YYYY-mm-dd) -/search : search a symbol with a given text (Argument: any_text) /stockgma50: Computing the statistics of a symbol, and plotting the 50-day moving average (Arguments: symbol [startdate] [enddate]) (date format: YYYY-mm-dd) /stockgma200: Computing the statistics of a symbol, and plotting the 200-day moving average (Arguments: symbol [startdate] [enddate]) (date format: YYYY-mm-dd) /sp500ma: Plotting the S&P 500 index and its 50- and 200-day moving average.