0bps

Strategy vault / Other

Telegram Mail Interface V200 Python

Before you can send messages to yourself, you need to send a /start message to your robot in Telegram, otherwise the robot will not be able to send you messages. Email [email protected] Telegram FawkesPan Accept policy…

PythonOther
Author
FawkesPan
Complexity
Starter · 51 lines
Parameters
3

Telegram APIInterface (FMZ.com)

This Library Can Only Send Messages via Telegram for Now, More Features Will Be Added Later.

Initialize

# key is Bot key
## To obtain Bot key, please refer to https://www.ccino.org/create-a-telegram-bot.html
# chat_id For receiving usersTelegram ID
## Telegram ID It can be obtained through the @dwx_aibot robot. After connecting to this robot, send /getid to obtain it. ChatID
Telegram = ext.Telegram(key=string, chat_id=integer)    # Create a new interface object

Send mail

# chat_id Optional, by default will use the settings at initializationChatID
# message Is the information content
Telegram.Send(message=string, chat_id=integer)

Notes

Before you can send messages to yourself, you need to send a /start message to your robot in Telegram, otherwise the robot will not be able to send you messages.

Contact me

Email [email protected] Telegram FawkesPan

Accept policy customization

About this library

Telegram APIDocumentation

Use WTFPL – Do What the Fuck You Want to Public License

Parameters

NameDefaultWhat it controls
DEBUG0DEBUGMode: 0 | 1
KEYTelegram robot Key
CHATIDfalseTelegram session ID

Source Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# encoding: utf-8
# 
# Telegram Interface for FMZ.com
#
# Copyright 2018 FawkesPan
# Contact : [email protected] / Telegram@FawkesPan
#
# Do What the Fuck You Want To Public License
#

try:
    import requests
except:
    print('Requests not installed. Try: pip install requests')
    Log('Requests not installed. Try: pip install requests')
    
    raise Exception('Requests not installed. Try: pip install requests')

class Telegram:
    def __init__(self):
        self.key = KEY
        self.chat_id = CHATID
        self.url = 'https://api.telegram.org/bot%s' % self.key
        
    def Send(self, message='', chat_id=None):
        if chat_id is None:
            chat_id = self.chat_id
        PARAM = {}
        PARAM['chat_id'] = chat_id
        PARAM['text'] = message
        PARAM['parse_mode'] = 'markdown'
        URL = self.url + '/sendMessage'
        try:
            res = requests.post(URL, data = PARAM)
            return True
        except IOError as e:
            print(e)
            return False
        

ext.Telegram = Telegram

# Module Function Test
def main():
    if DEBUG == 1:
        msger = ext.Telegram(KEY, CHATID)
        msger.Send("Hello World!")
    
    return True

Published by FawkesPan on the FMZ strategy square · last modified 2019-05-16. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.

Build this with AgenKit

A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Telegram-Mail-Interface-V200-Python.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. Get tests, backtest, risk controls and a paper-trading switch

Understand it first

Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.

Related specs

esc

Try , , or .

↑↓ move↵ open