mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-15 14:56:40 +00:00
Resolve "/intra
command not working for marketdata"
This commit is contained in:
parent
845c929311
commit
14f461424e
@ -1,9 +1,10 @@
|
||||
import datetime as dt
|
||||
import logging
|
||||
import os
|
||||
import datetime as dt
|
||||
from typing import Dict
|
||||
|
||||
import pandas as pd
|
||||
import pytz
|
||||
import requests as r
|
||||
import schedule
|
||||
|
||||
@ -21,6 +22,9 @@ class MarketData:
|
||||
|
||||
charts: Dict[Stock, pd.DataFrame] = {}
|
||||
|
||||
openTime = dt.time(hour=9, minute=30, second=0)
|
||||
marketTimeZone = pytz.timezone("US/Eastern")
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Creates a Symbol Object
|
||||
|
||||
@ -29,6 +33,7 @@ class MarketData:
|
||||
MARKETDATA_TOKEN : str
|
||||
MarketData.app API Token
|
||||
"""
|
||||
|
||||
try:
|
||||
self.MARKETDATA_TOKEN = os.environ["MARKETDATA"]
|
||||
|
||||
@ -170,18 +175,21 @@ class MarketData:
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
resolution = "5" # minutes
|
||||
resolution = "15" # minutes
|
||||
now = dt.datetime.now(self.marketTimeZone)
|
||||
|
||||
if self.openTime < now.time():
|
||||
startTime = now.replace(hour=9, minute=30)
|
||||
else:
|
||||
startTime = now - dt.timedelta(days=1)
|
||||
|
||||
if data := self.get(
|
||||
f"stocks/candles/{resolution}/{symbol}",
|
||||
params={
|
||||
"from": dt.datetime.now().strftime("%Y-%m-%d"),
|
||||
"to": dt.datetime.now().isoformat(),
|
||||
},
|
||||
params={"from": startTime.timestamp(), "to": now.timestamp(), "extended": True},
|
||||
):
|
||||
data.pop("s")
|
||||
df = pd.DataFrame(data)
|
||||
df["t"] = pd.to_datetime(df["t"], unit="s")
|
||||
df["t"] = pd.to_datetime(df["t"], unit="s", utc=True)
|
||||
df.set_index("t", inplace=True)
|
||||
|
||||
df.rename(
|
||||
|
2
bot.py
2
bot.py
@ -237,7 +237,7 @@ def intra(update: Update, context: CallbackContext):
|
||||
update.message.reply_photo(
|
||||
photo=buf,
|
||||
caption=f"\nIntraday chart for {symbol.name} from {df.first_valid_index().strftime('%d %b at %H:%M')} to"
|
||||
+ f" {df.last_valid_index().strftime('%d %b at %H:%M')}"
|
||||
+ f" {df.last_valid_index().strftime('%d %b at %H:%M %Z')}"
|
||||
+ f"\n\n{s.price_reply([symbol])[0]}",
|
||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||
disable_notification=True,
|
||||
|
@ -4,4 +4,5 @@ flake8==5.0.4
|
||||
Flake8-pyproject==1.2.3
|
||||
pylama==8.4.1
|
||||
mypy==1.2.0
|
||||
types-cachetools==5.3.0.5
|
||||
types-cachetools==5.3.0.5
|
||||
types-pytz==2023.3.0.0
|
@ -80,7 +80,7 @@ class Router:
|
||||
if symbols:
|
||||
for symbol in symbols:
|
||||
self.trending_count[symbol.tag] = self.trending_count.get(symbol.tag, 0) + trending_weight
|
||||
log.warning(self.trending_count)
|
||||
log.debug(self.trending_count)
|
||||
|
||||
return symbols
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user