Custom Trading Bot Platform (Blockly, Binance)

My Role: Lead Developer, Full-stack Dev
Date: 04/2025-05/2025
Technologies:
Python FastAPI React Vite TypeScript PostgreSQL asyncpg Blockly Zustand TanStack Query Mantine UI ccxt WebSockets JWT Netlify Railway

Developed a custom trading bot platform with a Blockly-based visual strategy editor. The platform features a robust backend using FastAPI (Python) for handling business logic, data processing, and real-time exchange interaction with Binance via REST APIs and WebSocket streams. The frontend, built with React and Vite, allows users to create, manage, and monitor trading strategies.

Binance Blockly Platform Interface

Key Contributions & Impact

  • Full-Stack Architecture Design: Designed and implemented a comprehensive architecture with a React frontend, FastAPI backend, and PostgreSQL database, ensuring scalability and real-time performance.
  • Backend Development (FastAPI): Built the core backend services including API layers, authentication (JWT, OAuth), strategy management, and an asynchronous execution engine for running trading strategies.
  • Real-Time Execution Engine: Developed an event-driven execution engine, processing real-time market data from Binance via WebSockets to trigger strategy logic.
  • Exchange Integration (Binance): Integrated with Binance USDⓈ-M Futures API for order placement, position management (including Hedge Mode), and account information retrieval.
  • WebSocket Management: Implemented a robust WebSocket manager for persistent connections to Binance, handling subscriptions and dispatching real-time events to strategy tasks.
  • Frontend User Interface (React & Blockly): Developed the frontend UI using React, Vite, TypeScript, and Mantine UI, featuring a Blockly interface for visual strategy creation, along with state management using Zustand and server state management with TanStack Query.
  • Secure API Key Management: Implemented secure, encrypted storage for user API keys.
  • Position Management: Designed and implemented logic for reliable tracking and management of user positions, supporting Binance Hedge Mode and relying on Binance as the source of truth for aggregated position details.

Challenges & Solutions

  • Ensuring Real-Time Responsiveness: Processing and reacting to high-frequency market data and user actions in near real-time. Solution: Leveraged FastAPI asynchronous capabilities with libraries for concurrent strategy execution, and an event-driven architecture based on WebSocket streams, and non-blocking database operations.
  • Maintaining System Resilience: Handling potential disruptions like API errors, WebSocket disconnections, or database issues without compromising active strategies or data integrity. Solution: Implemented intelligent retries with exponential backoff for API calls, automatic reconnection logic for WebSockets, and isolated strategy tasks to prevent single failures from crashing the engine. Ensured robust error logging and status reporting.
  • Managing Complex State: Synchronizing strategy state, user positions, and account information between the platform and the exchange. Solution: Relied on Binance as the source of truth for critical data like position details, with periodic reconciliation. Employed client-side state management (Zustand) and server-state caching (TanStack Query) on the frontend.

Lessons Learned

  • Deepened understanding of designing and implementing complex, real-time, event-driven systems for financial applications.
  • Gained extensive experience with asynchronous programming in Python (FastAPI, asyncio) and its importance for I/O-bound applications.
  • Learned the intricacies of integrating with cryptocurrency exchange APIs (Binance) for both RESTful commands and continuous WebSocket data streams.
  • Reinforced the importance of robust error handling, fault tolerance, and comprehensive logging in distributed systems.
About MeProjectsContact