Skip to content

Commit

Permalink
Merge pull request #7 from stephenhky/develop
Browse files Browse the repository at this point in the history
search function eliminated
  • Loading branch information
stephenhky authored Jun 2, 2024
2 parents a4377a3 + 2132004 commit 37a37e8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 83 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ Commands:
- /stock <symbol> (<startdate> (default: 1 year ago)> (<enddate> (default: today)): Computing statistical information for the given symbol.
- /stockg <symbol> (<startdate> (default: 1 year ago)> (<enddate> (default: today)): Computing statistical information for the given symbol, and the chart plotting.
- /stockcorr <symbol1> <symbol2>: correlation between two symbols
- /search <text>: find the symbol name from the given text
- /help: display help message.

Telegram: @FinportTelebot ([https://t.me/FinportTelebot](https://t.me/FinportTelebot))
50 changes: 23 additions & 27 deletions finportbotutil/syminfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
54 changes: 0 additions & 54 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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']
Expand Down Expand Up @@ -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')
Expand Down
1 change: 0 additions & 1 deletion messagetemplates/help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 37a37e8

Please sign in to comment.