Skip to content

fatihsen-dev/go_auto_trade

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README

Project: Go-based Trading Bot

This project is a Go (Golang) application designed to interact with the Binance Spot API for automated trading. It leverages the following key libraries and concepts:

  1. Go: Main programming language used.
  2. Binance API: Spot trading endpoints for placing orders, checking balances, and retrieving price information.
  3. godotenv: Used for loading environment variables from a .env file.
  4. HMAC-SHA256: Required for signing requests to Binance.

Note: This README and the associated code were generated with the assistance of AI.


How It Works

  1. Environment Variables

    • The bot reads BINANCE_API_KEY and BINANCE_API_SECRET from a .env file.
    • If either key is missing or empty, the bot exits with an error.
  2. Initialization

    • The init() function loads the .env file and checks if the required environment variables exist.
    • If .env is missing or the variables are not defined, the bot logs a fatal error and terminates.
  3. Ping Check

    • At startup, the bot sends a ping request to Binance (/api/v3/ping).
    • If the ping fails, the bot immediately exits. Otherwise, it proceeds to start.
  4. Trading Strategy

    • Retrieves 24h volume data for symbols, checks balances, and gathers kline data.
    • Uses simple RSI & MACD indicators to determine buy/sell conditions, plus stop-loss and take-profit.
  5. Logging

    • Various log messages indicate buy/sell events, stop-loss triggers, take-profit triggers, etc.

File Structure

  • main.go # Contains the main trading bot logic
  • .env # Environment variables (not committed to version control)
  • go.mod # (Optional) Go module file for dependencies

Setup & Installation

  1. Install Go

  2. Create a .env File

    • In the project root, create .env:
      BINANCE_API_KEY=YOUR_API_KEY
      BINANCE_API_SECRET=YOUR_API_SECRET
      
    • Replace with actual values.
  3. Build & Run
    go build -o binance_bot main.go ./binance_bot Or directly: go run main.go


Usage & Configuration

  • Portfolio
    In main.go, edit: portfolio := map[string]float64{ "BTCUSDT": 80, "ETHUSDT": 40, } Adjust as needed.

  • Intervals & Thresholds
    autoTradePortfolio( portfolio, buyInterval, // e.g. 3600 seconds stopLossPct, // e.g. 0.05 = 5% takeProfitPct, // e.g. 0.1 = 10% rsiPeriod, buyRSIThreshold, sellRSIThreshold, ... )


Disclaimers

  1. No Guarantee of Profit
  • This code is for educational purposes only and not financial advice.
  1. Security
  • Keep your .env private; never enable withdrawal on your API keys.
  1. AI Generated Code
  • Portions of this project were generated by AI. Always review before production use.

License

Use or modify this code freely for personal or learning projects.

Happy Trading!

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages