mirror of
https://gitlab.com/simple-stock-bots/simple-stock-bot.git
synced 2025-06-16 07:16:40 +00:00
Merge branch '89-intra-command-not-working-for-marketdata' into 'master'
Resolve "`/intra` command not working for marketdata" Closes #89 See merge request simple-stock-bots/simple-telegram-stock-bot!47
This commit is contained in:
commit
85ff7b7452
@ -1,9 +1,10 @@
|
|||||||
|
import datetime as dt
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import datetime as dt
|
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
import pytz
|
||||||
import requests as r
|
import requests as r
|
||||||
import schedule
|
import schedule
|
||||||
|
|
||||||
@ -21,6 +22,9 @@ class MarketData:
|
|||||||
|
|
||||||
charts: Dict[Stock, pd.DataFrame] = {}
|
charts: Dict[Stock, pd.DataFrame] = {}
|
||||||
|
|
||||||
|
openTime = dt.time(hour=9, minute=30, second=0)
|
||||||
|
marketTimeZone = pytz.timezone("US/Eastern")
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
"""Creates a Symbol Object
|
"""Creates a Symbol Object
|
||||||
|
|
||||||
@ -29,6 +33,7 @@ class MarketData:
|
|||||||
MARKETDATA_TOKEN : str
|
MARKETDATA_TOKEN : str
|
||||||
MarketData.app API Token
|
MarketData.app API Token
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.MARKETDATA_TOKEN = os.environ["MARKETDATA"]
|
self.MARKETDATA_TOKEN = os.environ["MARKETDATA"]
|
||||||
|
|
||||||
@ -170,18 +175,21 @@ class MarketData:
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
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(
|
if data := self.get(
|
||||||
f"stocks/candles/{resolution}/{symbol}",
|
f"stocks/candles/{resolution}/{symbol}",
|
||||||
params={
|
params={"from": startTime.timestamp(), "to": now.timestamp(), "extended": True},
|
||||||
"from": dt.datetime.now().strftime("%Y-%m-%d"),
|
|
||||||
"to": dt.datetime.now().isoformat(),
|
|
||||||
},
|
|
||||||
):
|
):
|
||||||
data.pop("s")
|
data.pop("s")
|
||||||
df = pd.DataFrame(data)
|
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.set_index("t", inplace=True)
|
||||||
|
|
||||||
df.rename(
|
df.rename(
|
||||||
|
2
bot.py
2
bot.py
@ -237,7 +237,7 @@ def intra(update: Update, context: CallbackContext):
|
|||||||
update.message.reply_photo(
|
update.message.reply_photo(
|
||||||
photo=buf,
|
photo=buf,
|
||||||
caption=f"\nIntraday chart for {symbol.name} from {df.first_valid_index().strftime('%d %b at %H:%M')} to"
|
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]}",
|
+ f"\n\n{s.price_reply([symbol])[0]}",
|
||||||
parse_mode=telegram.ParseMode.MARKDOWN,
|
parse_mode=telegram.ParseMode.MARKDOWN,
|
||||||
disable_notification=True,
|
disable_notification=True,
|
||||||
|
@ -5,3 +5,4 @@ Flake8-pyproject==1.2.3
|
|||||||
pylama==8.4.1
|
pylama==8.4.1
|
||||||
mypy==1.2.0
|
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:
|
if symbols:
|
||||||
for symbol in symbols:
|
for symbol in symbols:
|
||||||
self.trending_count[symbol.tag] = self.trending_count.get(symbol.tag, 0) + trending_weight
|
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
|
return symbols
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user