Data Storage & Datasource Configuration

MagicTradeBot's Management App supports multiple SQL-based databases to store and manage essential trading-related data. This flexibility allows users to operate in environments ranging from lightweight embedded databases to full-scale production-grade relational databases.

📌 What Data Is Stored

MagicTradeBot persists the following structured data to the connected datasource:

  • Exchange Accounts: Exchange credentials, API keys, and configuration per exchange.
  • Trading Symbols: Coins/pairs associated with specific exchanges or accounts.
  • Trading Templates: Custom template definitions including strategy, risk controls, and symbol bindings.
  • Trade Data: Real-time and historical trade logs and execution data.
  • KlineData: Custom internal kline (candlestick) data, built and optimized locally without reliance on third-party providers.
  • Other: Logs, system settings, schedules, and other runtime-critical metadata.

💾 Supported Datasource Options

MagicTradeBot currently supports the following SQL database engines:

  • SQLite – Lightweight and built-in (default option)
  • SQL Server – Full-featured enterprise RDBMS (Microsoft SQL)
  • MySQL – Popular open-source RDBMS
  • PostgreSQL – Advanced open-source object-relational DB system

⚙️ Configuration Setup

All database connections are configured in the appsettings.json file inside the Management App:

{
  "ConnectionStrings": {
    "SQLLight": "Data Source=Data/MTManagementDB.db",
    "SQLSERVER": "Server=localhost;Database=MagicTrade;User Id=sa;Password=yourpass;",
    "Postge": "Server=localhost;Database=MagicTrade;User Id=pguser;Password=yourpass;",
    "MySQL": "Server=localhost;Database=MagicTrade;User=mtuser;Password=yourpass;"
  },

  "Secrets": {
    // WARNING: Never commit real secrets to source control!
    "Database": {
      "Host": "",        // Environment: Secrets__Database__Host
      "Name": "",        // Environment: Secrets__Database__Name
      "User": "",        // Environment: Secrets__Database__User
      "Password": ""     // Environment: Secrets__Database__Password
    }
  }
}

🔐 Security Best Practices

  • Never hardcode credentials in appsettings.json for production use.
  • Utilize environment variables to inject secrets securely. For example:
    • Secrets__Database__User
    • Secrets__Database__Password
  • Use a Secrets Manager or Docker secrets in containerized environments.
  • Encrypt database at rest when possible.

🧪 Default SQLite Usage (Recommended for Local / Development)

MagicTradeBot comes with SQLite pre-integrated and pre-configured. No manual setup is required to start testing locally.

"SQLLight": "Data Source=Data/MTManagementDB.db"

The default file-based database is automatically created under the /Data folder.

🔧 Switching to External Databases

  1. Create the desired database in your SQL Server / MySQL / PostgreSQL engine.
  2. Update the corresponding connection string in appsettings.json.
  3. Ensure required ports are open and accessible.
  4. Restart the Management App.

🧩 Summary

  • MagicTradeBot stores all trade data, configurations, and logs in a structured database.
  • Supports lightweight to enterprise-grade SQL engines.
  • Encourages secure and scalable deployments via environment-configured secrets.
  • Easy to switch between databases by modifying configuration only.

For advanced deployments, backup scheduling and database replication are also supported externally depending on your database engine.

📎 Related Topics