Boilerplate Python server for Maverick.
Demonstrates two simple ways of sending instructions:
- Manually, using the stdin to send commands to Maverick.
- Fetching messages from a Telegram entity (e.g. a group), parsing them into
BetRequest
s, and forwarding them to Maverick.
- Clone the repo
git clone https://github.com/t00ts/maverick-tg
cd maverick-tg
- Set up a Python virtual environment
python -m venv venv
source venv/bin/activate
- Install dependencies
pip install -r requirements.txt
If you just want to send commands to Maverick using your terminal, skip to disable Telegram
You'll want to set your Telegram credentials in server.py
:
tg_api_id = "YOUR API ID" # The API ID you obtained from https://my.telegram.org
tg_api_hash = "YOUR API Hash" # The API hash you obtained from https://my.telegram.org
And set the entity for the Telegram group you want to listen from.
tg_group_entity = "https://t.me/+abcde12345"
If you want to change the default server address/port, feel free to do so in the main()
when instantiating the WebSocketServer
:
websocket_server = WebSocketServer(port=54321)
All incoming messages will be sent to the process_msg
function. This is where you filter and parse messages, and construct the BetRequest
object that will be sent to Maverick.
💡 To understand how to construct a valid
BetRequest
object, run thebetreq
binary that is included in your Maverick bundle. You will be able to createBetRequest
objects interactively and gain detailed insights into how to build your own.
Comment out the telegram_feed()
task in the main()
function and you'll just have basic stdin functionality:
async def main():
# Create instances tasks (WebSocket server and data feed)
websocket_server = WebSocketServer()
# Run both tasks concurrently
await asyncio.gather(
websocket_server.start_server(),
#telegram_feed(), <- Disable Telegram
stdin_feed(),
)
Launch two side-by-side terminal sessions:
Terminal 1 | Terminal 2 |
---|---|
source venv/bin/activate |
|
./run_server.sh |
./server_output.sh |
In Maverick's config.toml
, set the addr
of your [server]
block to point to your running websocket server:
[server]
addr = "ws://localhost:5999"
max_retries = 10
Run Maverick, and you should see the connection has been established successfully:
INFO maverick::server: Connecting to server (ws://localhost:5999/)
INFO maverick::server: Connection established successfully.