Last active
June 24, 2022 09:17
-
-
Save OndrejIT/44dd96b61d31cbfb57a0026666649286 to your computer and use it in GitHub Desktop.
minswap telegram bot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from datetime import datetime | |
TOKENS = 1000 | |
TELEGRAM_API = "https://api.telegram.org/botXY" # Telegra api bot token | |
TELEGRAM_CHAT_ID = 0 # Telegram chat ID | |
def get_price(): | |
url = "https://monorepo-mainnet-prod.minswap.org/graphql?CandlestickSeries" | |
# graphql request payload | |
j = {"query": "query CandlestickSeries($pair: InputPoolByPair!, $interval: Int!, $cursor: String) {candlestickSeries(pair: $pair, interval: $interval, cursor: $cursor) {time open high low close}}", "variables": {"pair": {"assetA": {"currencySymbol": "5dac8536653edc12f6f5e1045d8164b9f59998d3bdc300fc92843489", "tokenName": "4e4d4b52"}, "assetB": {"currencySymbol": "", "tokenName": ""}}, "interval": 900}} | |
resp = requests.post(url, json=j) | |
data = resp.json()["data"]["candlestickSeries"][0] | |
close = float(data["close"]) | |
t = datetime.fromtimestamp(int(data["time"]) / 1000).strftime("%d.%m.%Y %H:%M:%S") | |
return { | |
"close": round(close, 6), | |
"time": t, | |
"ada": round(close * TOKENS) | |
} | |
def send_telegram(message): | |
payload = { | |
"chat_id": TELEGRAM_CHAT_ID, | |
"text": message, | |
"parse_mode": "html", | |
} | |
r = requests.post(TELEGRAM_API, data=payload) | |
if not r.status_code == requests.codes.OK: | |
raise Exception(r.status_code) | |
if __name__ == "__main__": | |
data = get_price() | |
send_telegram( | |
message=f'----- {data["time"]} -----\n<b>NMKR: {data["close"]}</b>\n<i>ADA: ~{data["ada"]}</i>', | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Cron: