Bitcoin Arbitrage Trading Bot

Automated system that buys Bitcoin on centralized exchanges at spot price and sells peer-to-peer at a premium. Fully autonomous from order execution to on-chain escrow release.

🏦
Exchange
Market Buy
🔑
Hot Wallet
UTXO Management
🔒
Escrow
2-of-2 Multisig
🤝
P2P Trade
Encrypted Match
Settlement
PSBT Release
⚙️
Trading Engine
Central orchestrator — 30s polling loop
  • Offer lifecycle management (create, fund, match, release)
  • Auto-accept trade requests with PGP-encrypted payment data
  • Contract monitoring with PSBT signing
  • Auto premium reduction via live PATCH (no cancel/refund)
  • Auto-refund: sign & broadcast cancelled escrow PSBTs every 10min
  • Auto buy-escrow: every 10min, CHF/EUR/USD, 5.5% fixed premium, no Revolut
  • Daily summary, low balance alerts, profit tracking
  • Multi-source spot price with fallback
  • Thread-safe concurrent access (engine + Telegram threads)
🏦
Exchange Connector
CHF/EUR/USD spot market buy + withdrawal
  • Market buy with viqc (volume in quote currency)
  • Dual fill detection: QueryOrders + balance change fallback
  • BTC withdrawal to whitelisted hot wallet address
  • Trade history and ledger queries
  • HMAC-SHA512 signed API authentication
🤝
P2P Platform
Peer-to-peer marketplace integration
  • Secp256k1 authentication with auto-refresh (~50min)
  • Sell offers with per-method SHA256 payment hashes
  • Trade request detection via v069 (v1 often empty)
  • AES symmetric key exchange + PGP encryption
  • Live premium PATCH on active offers
  • Market scanner: competitor + buyer demand analysis
💸
Wise Forwarder
Auto-forward incoming EUR/CHF to exchange
  • Balance polling every 30s via Wise API
  • Auto-create transfer drafts (EUR → Kraken, CHF → bank)
  • Telegram notification with Wise app deep link
  • One-tap confirmation in Wise app (PSD2 compliant)
📡
Hot Wallet & TX Builder
Raw Bitcoin TX construction & UTXO management
  • BIP32/39/84 HD keys: m/84'/0'/0'/0/i
  • Native SegWit P2WPKH → P2WSH
  • UTXO selection with dynamic fee estimation
  • BIP143 witness signing (ECDSA)
  • Dust handling and change outputs
  • Mempool broadcast via public API
✍️
Escrow & PSBT Signing
Multisig escrow release & key derivation
  • Per-offer escrow keys: m/84'/0'/0'/{id}'
  • Parse and sign PSBTv0 (2-of-2 multisig)
  • BIP143 sighash (ALL + SINGLE|ANYONECANPAY)
  • Auto-detect key from witness script inspection
  • TX finalization and GroupHug batch support
  • Legacy vs current derivation path fallback
📊
Premium Management
Dynamic pricing + auto-reduction
  • Market-based premium calculation (undercut strategy)
  • Auto-reduction: -0.5% every 24h without match
  • Live PATCH on funded offers (no on-chain refund needed)
  • Floor enforcement (4%) and ceiling cap (10%)
  • Telegram notification on each reduction
🗄️
Trade Database
SQLite with WAL mode
  • Trade logging with full fee breakdown
  • Buy data preservation across escrow lifecycle
  • Event tracking (lifecycle audit trail)
  • Daily/monthly profit analytics
  • Platform breakdown reports
💬
Telegram Bot
Remote control & monitoring
  • /buy_escrow — Full cycle: CHF/EUR/USD buy or BTC withdraw → Offer → Escrow
  • /market — Competitive analysis + premium recommendation
  • /status /balance /offers /contracts — Monitoring
  • /cancel /pause /resume — Control with inline keyboards
  • Background UTXO polling for escrow funding
  • Persistent pending fundings (survives restart)
  • Telegram notifications for every auto buy-escrow (offer ID, premium, sats, BTC cost)
📈
Web Dashboard
Flask — HTTPS + Basic Auth
  • Real-time status overview
  • Trade history with filtering
  • Balance and P&L charts
  • Market premium landscape

Payment Methods

Twint
CHF
sha256(phone)
SEPA
EUR
sha256(IBAN)
SEPA Instant
EUR
sha256(IBAN)
Revolut
CHF · EUR
sha256(JSON)
Wise
CHF · EUR · USD
sha256(JSON)

Trade Lifecycle

1
Telegram
/buy_escrow 200
CHF/EUR/USD/BTC
2
Exchange Buy
Market order
(skip if BTC)
3
Withdraw
→ Hot Wallet
4
Create Offer
P2P + hashes
5
Derive Key
m/84'/.../id'
6
Fund Escrow
SegWit TX
7
Wait / Reduce
PATCH -0.5%/24h
8
Match
AES + PGP
9
Payment
Fiat received
10
Sign PSBT
2-of-2 release
11
Settle
On-chain

Security Model

🔏
Exchange API
HMAC-SHA512 signed requests, nonce replay protection
🪪
Platform Auth
Secp256k1 ECDSA signature, auto-refresh every 50min
🔑
Escrow Keys
Per-offer HD-derived keys (BIP32 hardened children)
🔐
Payment Data
AES-256 symmetric key encrypted with buyer's PGP key
🛡️
Escrow Safety
2-of-2 multisig, double-funding prevention
📡
Telegram
Chat ID verification, flood control handling
Language
Python 3.12
Cryptography
secp256k1 · PGP · AES
Bitcoin
Raw TX · BIP32/84/143 · PSBT
Database
SQLite (WAL)
Exchange
REST API (HMAC-SHA512)
P2P
P2P REST API
Notifications
Telegram Bot API
Deployment
systemd · VPS · venv