Skip to content

ivanbollu/binance_test_trade

Repository files navigation

利用了豆包生成了代码和claude code调试了代码, 演示了用binance testnet api: 1.领取了test usdt 2.显示余额 3.搭建了server 4.可以在web页面买入btc/usdt和卖出

包含四个个文件: trade_en.py和trade2_en.py是两个前期测试的 trade_server_en 和 trade_interface_en 这两个是包含web服务器的。

开启server后开5001端口,在http://localhost:5001/ 就可以访问和操作。


以下代码是我让claude code生成的过程

  BTC/USDT Trading Interface Development Process
  
  ----------------------------------------
  
  Date: 2026-03-15
  
  User's Request:
  - Create a web interface for manual trading BTC/USDT
  - Allow manual buy/sell operations
  
  Process:
  
  1. Initial File Creation
  ----------------------------------------
  Created trade_interface.html (Chinese version)
  - Basic HTML structure
  - CSS styling for buy/sell boxes
  - JavaScript for trading operations
  - Integration with Binance API
  
  2. Backend Server Development
  ----------------------------------------
  Created trade_server.py (Chinese version)
  - Flask-based server
  - API endpoints for:
    - /api/account-info (get account balances and price)
    - /api/buy (place buy order)
    - /api/buy-with-usdt (buy with specified USDT amount)
    - /api/sell (place sell order)
  
  3. Testing Issues
  ----------------------------------------
  Issue 1: Unicode Encoding Error
  - File contained Chinese characters causing UnicodeEncodeError
  - Solution: Fixed UTF-8 encoding
  
  Issue 2: Invalid Symbol Error
  - XAUUSDT not available on testnet
  - Solution: Changed to BTCUSDT
  - Updated all references from XAU to BTC
  
  Issue 3: API Precision Error
  - Error: Parameter 'quantity' has too much precision
  - Root cause: BTCUSDT step size is 0.00001000
  - Solution:
    - Added format_quantity() function to round to step size
    - Updated all trading endpoints to use formatted quantities
    - Updated UI placeholders to show min step size
  
  4. English Version Creation
  ----------------------------------------
  Created English versions:
  - trade_interface_en.html: English trading interface
  - trade_server_en.py: English backend server
  - Changed port from 5000 to 5001 due to conflict
  
  5. Final Working Solution
  ----------------------------------------
  - Server running on http://localhost:5001
  - Successful trade execution confirmed
  - User interface shows:
    - Account balance (USDT and BTC)
    - Current BTC/USDT price
    - Buy with BTC amount or USDT amount
    - Sell BTC functionality
  
  Key Files:
  - bn_test_trade.txt (this file)
  - trade_interface.html (Chinese version)
  - trade_server.py (Chinese version)
  - trade_interface_en.html (English version - final)
  - trade_server_en.py (English version - final)
  - trade2_en.py (Original test script)
  
  API Configuration:
  - API Key: ***
  - Secret Key: ***
  - Testnet: True
  - Symbol: BTCUSDT
  - Step Size: 0.00001000
  
  User's Final Confirmation:
  "非常棒,买入成功了" (Translation: "Excellent, buy was successful!")

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors