Updated 86 days ago

Trade on Arch with TG bot

Trade on Arch with TG bot

  • Crypto / Web3
  • Archway
  • Defi
  • Telegram-trading-bot
  • Trading

Welcome to the Arch Telegram Trading Rust Bot project!

Screenshot 2024-06-25 175221.png

This project implements a powerful Telegram trading bot written in Rust, designed to interact with the Archway blockchain.

The bot is capable of trading CW20 tokens based on predefined strategies and monitoring various transactions on Archway through commands received via Telegram.

The bot leverages the teloxide library for Telegram interactions and uses Go scripts for transaction monitoring and subscription.

Features

  • Trading: Swap CW20 tokens based on predefined trading strategies.
  • Transaction Monitoring: Listen to and report specific transactions on Archway.
  • Subscription Management: Subscribe to various transaction types and filter them as needed.

cosmos-monitor-scripts

The cosmos-monitor-scripts feature listens to transactions with specific filters on multiple chains, including Archway, and reports them via the Telegram Bot and also optionally in channels.

Setup Instructions

Download and Install

  1. Download the latest release from the releases page.
  2. Unzip the downloaded file and run the bot:
wget <the link from the releases page>
tar xvfz <filename you have just downloaded>
./cosmos-transactions-bot <params>
  1. To run the bot in the background, copy it to the system apps folder:
sudo cp ./cosmos-transactions-bot /usr/bin
  1. Create a systemd service:
sudo nano /etc/systemd/system/cosmos-transactions-bot.service

Use the following template for the service file (replace <username> with the appropriate user):

[Unit]
Description=Cosmos Transactions Bot
After=network-online.target

[Service]
User=<username>
TimeoutStartSec=0
CPUWeight=95
IOWeight=95
ExecStart=cosmos-transactions-bot --config /path/to/config.toml
Restart=always
RestartSec=2
LimitNOFILE=800000
KillSignal=SIGTERM

[Install]
WantedBy=multi-user.target
  1. Enable and start the service:
sudo systemctl enable cosmos-transactions-bot
sudo systemctl start cosmos-transactions-bot
sudo systemctl status cosmos-transactions-bot # Validate it's running
  1. To view logs:
sudo journalctl -u cosmos-transactions-bot -f --output cat

How It Works

The bot connects to multiple nodes via WebSockets and subscribes to queries set in the configuration file. When a transaction matching the filters is detected, it undergoes deduplication to avoid duplicate reports. Enriched transaction data is then sent to a reporter (currently, only Telegram) for notifications.

Configuration

The configuration is managed through a .toml file passed to the app via the --config flag. See config.example.toml for reference.

Main Components

  • Reporter: Destination point for notifications (e.g., Telegram bot).
  • Chain: Information about the blockchain, including denoms, queries, and nodes.
  • Subscription: Defines which chains and events to report to which reporter.
  • Chain Subscription: Filters and processes errors/unparsed messages for each chain.

Queries and Filters

Queries subscribe to specific events on a chain, while filters refine these events. Filters should follow the pattern xxx = yyy or xxx != yyy.

Example queries:

queries = [
    "withdraw_rewards.validator = 'archwayvaloper1...'",
    "delegate.validator = 'archwayvaloper1...'",
    "transfer.sender = 'archway1...'",
    "transfer.recipient = 'archway1...'"
]

To subscribe to all transactions:

queries = ['tx.height > 1']
filters = [
    "withdraw_rewards.validator = 'archwayvaloper1...'",
    "delegate.validator = 'archwayvaloper1...'"
]

Denoms Fetching

The bot fetches denoms and their prices in the following order:

  1. Local chain denoms.
  2. If it's an IBC denom, it traverses the IBC path and fetches intermediate chains from local config or cosmos.directory.
  3. For non-IBC denoms, it fetches from cosmos.directory if not found locally.

Notifications Channels

Create a bot on Telegram using @BotFather and configure it to send messages to users or channels. For user IDs, use @getmyid_bot to obtain the ID. Add the bot as an admin in channels.

Example bot commands:

help - Display help message
status - Display nodes status
alias - Add a wallet alias
aliases - List wallet aliases

Supported Networks

The bot works on any Cosmos-based blockchain exposing a Tendermint RPC endpoint.

Contributing

Bug reports and feature requests are welcome! Feel free to open issues or PRs.