Automated cryptocurrency trading bot for the bitFlyer exchange.
This logo was created by gopherize.me.
gogocoin is an automated trading bot for the bitFlyer cryptocurrency exchange, written in Go. It executes trades using an EMA-based scalping strategy with configurable trade frequency.
- Pluggable strategy architecture: Implement the
pkg/strategy.Strategyinterface to plug in your own trading strategy - Bundled minimal reference strategy: EMA crossover scalping (see
pkg/strategy/scalping/README.md; an extended EMA + RSI + cooldown implementation lives inexample/strategy/scalping/) - Engine-level risk management (daily loss caps, per-trade loss caps, min trade interval, max daily trades — configured under
trading.risk_management) - Web UI for starting and stopping trading
- Real-time market data ingestion and analysis via WebSocket
- Real-time monitoring dashboard (
http://localhost:8080) - Data persistence with SQLite
- Automatic trade data cleanup (configurable via
retention_days) - Structured logging with level and category filtering
- 24/7 operation support (idempotent, restart-safe)
- Language: Go 1.23+ (development: Go 1.25.0)
- Dependencies: Minimal (go-bitflyer-api-client + yaml.v3 + sqlite3 only)
- Architecture: Layered modular architecture
- Public API (
pkg/):pkg/engine.Run()+pkg/strategy.Strategyinterface allow strategy injection from external repositories. Stable, semantically versioned API - Database: SQLite (lightweight, embedded, no external DB required)
- Retention: configurable via
retention_days(example default: 90 days; the code falls back to 1 day when unset) - Historical data: accessible via bitFlyer
- Retention: configurable via
- Concurrency: Asynchronous workers via Goroutines + Channels
- Transport: WebSocket (real-time) + REST API (Web UI)
- Logging: Structured logging based on the standard
log/slogpackage- High-frequency log filtering (DEBUG level and
datacategory) - DB index optimization (
timestamp DESC)
- High-frequency log filtering (DEBUG level and
- Performance optimizations:
- Balance cache (60s TTL, ~90% reduction in API calls)
- ~98% reduction in 429 errors
- Deadlock-safe design
- Deployment: Single binary with embedded web assets
- Quality assurance:
- Static analysis with golangci-lint
- Unit tests across multiple packages
- Layered modular architecture
- Type safety via Go's type system
- Proper error handling
Important: Please read carefully.
This software is provided for informational and development purposes only and does not constitute financial advice or investment recommendations. Cryptocurrency trading carries significant risk and you may lose your entire investment.
Actual trading results vary greatly depending on market conditions, configuration, and timing. Past backtesting or simulation results do not guarantee future performance.
The author accepts no responsibility for any losses or damages arising from the use of this software. Use it at your own discretion and risk.
This library is not affiliated with bitFlyer in any way. Please review each API provider's terms of service before use.
This library is provided "as is" with no warranties regarding accuracy, completeness, or future compatibility.
gogocoin can be used in two ways.
Install gogocoin via go get and integrate it into your own repository. You can implement and plug in your own trading strategy.
go get github.com/bmf-san/gogocoin@latestA working sample is available in the example/ directory. See Using the example directory for details.
The example/ directory includes a Dockerfile and docker-compose.yml that build a fully working binary with the bundled EMA+RSI scalping strategy registered.
- Docker and Docker Compose
- bitFlyer API key (obtain from the API settings page)
# 1. Clone the repository
git clone https://github.com/bmf-san/gogocoin.git
cd gogocoin/example
# 2. Create the config file
cp configs/config.example.yaml configs/config.yaml
# Edit configs/config.yaml and set your API keys
# 3. Start (build context is the repo root, so run from example/)
make up
# 4. Open the Web UI
open http://localhost:8080make logs # View logs
make down # Stop
make restart # Restart
make rebuild # Rebuildexample/ is a fully working sample showing how to use gogocoin as a library. It serves as a starting point for building your own repository.
example/
├── cmd/
│ └── main.go # Entry point (registers strategy via blank import)
├── strategy/scalping/
│ ├── params.go # Strategy parameter definitions
│ ├── strategy.go # Strategy implementation (EMA + RSI + cooldown)
│ └── register.go # Auto-registration via init()
├── configs/
│ └── config.example.yaml # Config file template
├── go.mod # Independent Go module
├── Makefile # build / run / Docker shortcuts
├── Dockerfile # Docker image (build context: repo root)
└── docker-compose.yml # Docker Compose config
With Docker (simplest):
cd example
cp configs/config.example.yaml configs/config.yaml
# Edit configs/config.yaml and set your API keys
make upWithout Docker:
cd example
# 1. Create the config file
cp configs/config.example.yaml configs/config.yaml
# Edit configs/config.yaml and set your API keys
# 2. Run
export BITFLYER_API_KEY=your_key
export BITFLYER_API_SECRET=your_secret
make run
# or: go run ./cmd/Copy example/ as-is to use as your own repository, or follow the pattern below.
1. Create go.mod
go mod init github.com/yourname/your-bot
go get github.com/bmf-san/gogocoin@latest2. Implement your strategy and register it via init()
// strategy/scalping/register.go
package scalping
import "github.com/bmf-san/gogocoin/pkg/strategy"
func init() {
strategy.Register("scalping", func() strategy.Strategy {
return NewDefault()
})
}3. Blank import in main.go
import (
"github.com/bmf-san/gogocoin/pkg/engine"
_ "github.com/yourname/your-bot/strategy/scalping" // triggers init()
)
func main() {
engine.Run(ctx, engine.WithConfigPath("./configs/config.yaml"))
}Reference implementation: bmf-san/my-gogocoin
| Document | Description |
|---|---|
| docs/CONFIG.md | Configuration reference |
| docs/STRATEGY.md | Trading strategy reference (pluggable architecture overview and bundled strategies) |
| docs/DESIGN_DOC.md | Architecture design document (how to implement a custom strategy § 5) |
| docs/DATA_MANAGEMENT.md | Data management reference |
| docs/openapi.yaml | API specification (OpenAPI 3.1) |
Monitor trading activity in real time in your browser: http://localhost:8080
You can also start and stop trading from the Web UI.
- Persist
./data/via a Docker volume (already configured) - Restart roughly once a week for stability
- Use log level
infoin production (debugfor development only)
- View logs:
make logsordocker compose logs -f - Check DB:
ls -lh ./data/gogocoin.db - Restart container:
make restart
# Install dependencies
make deps
# Install dev tools (golangci-lint, oapi-codegen, etc.)
make install-tools
# Run tests
make test
# Check coverage
make test-coverage
# Format code
make fmt
# Run linter
make lint
# Run via Docker (from example/ directory)
# cd example && make upWhen you modify docs/openapi.yaml, regenerate the code with oapi-codegen and commit it.
# Regenerate api.gen.go
make generate
internal/api/api.gen.gois an auto-generated file. Do not edit it directly — always update it viamake generate. The CIcodegenjob verifies that the spec and generated code are in sync.
- example/ — Working sample for using gogocoin as a library (in this repository)
- bmf-san/my-gogocoin — Example production repository using gogocoin
- gogocoin-vps-template — Template for deploying to a VPS (ConoHa, etc.) with systemd + GitHub Actions
See CONTRIBUTING.md.
