Trader
is a framework that automated cryptocurrency exchange with strategy.
Disclaimer: The profit and loss is yourself when use this framework!
- Current support spot/future of binance, more exchange work in progress.
- Easy write your own strategy.
- Back test engine support to test your strategy.
- Restful api server integration.
Just see examples
package strategy
type UpDownRate struct {
strategy.Base
}
package strategy
func (s *UpDownRate) OnConnect() {
// you can do something initialization here.
}
func (s *UpDownRate) On1mKline() {
// here you can buy or sell order depending on 1m kline.
}
The result will store in orders
table in database.
package tests
func TestUpDownRate(t *testing.T) {
conf.InitConfig("config.yml")
eng := (*engine.GetEngine(exchange.Mock, conf.BinanceApiKey, conf.BinanceApiSecret)).(*engine.Mock)
BaseAsset := "ETH"
QuoteAsset := "USDT"
symbol := BaseAsset + QuoteAsset
h, _ := time.ParseDuration("-48h")
eng.Exchange.(*mock.Mock).StartTime = time.Now().Add(h)
eng.Exchange.(*mock.Mock).EndTime = time.Now()
eng.Exchange.(*mock.Mock).Symbol = symbol
eng.RegisterStrategy(&UpDownRate{
KLineLimit: 10,
Rate: decimal.NewFromInt(6).Div(decimal.NewFromInt(4)),
Base: strategy.Base{
Streams: []string{strings.ToLower(symbol) + "@kline_1m"},
FundRatio: decimal.NewFromFloat(1),
StopProfit: decimal.NewFromFloat(0.02),
StopLoss: decimal.NewFromFloat(0.06),
BaseAsset: BaseAsset,
QuoteAsset: QuoteAsset,
Exchange: eng.Exchange,
}},
)
eng.Start(false)
}
After test strategy, and it's effective, that's the time to run it.
package main
func main() {
conf.InitConfig("config.yml")
eng := (*engine.GetEngine(exchange.BinanceSpot, conf.BinanceApiKey, conf.BinanceApiSecret)).(*engine.Engine)
eng.RegisterStrategy(&UpDownRate{
KLineLimit: 10,
Rate: decimal.NewFromInt(6).Div(decimal.NewFromInt(4)),
Base: strategy.Base{
FundRatio: decimal.NewFromFloat(1),
StopProfit: decimal.NewFromFloat(0.02),
StopLoss: decimal.NewFromFloat(0.06),
BaseAsset: "ETH",
QuoteAsset: "USDT",
Exchange: eng.Exchange,
Streams: []string{"ethusdt@kline_1m", "ethusdt@miniTicker"},
}},
)
eng.Start(true)
}
Trader
has a back test engine, for that you can test your strategy.
Copy config.example.yaml
to config.yaml
then update it, and current use MySQL
.
You can get other custom config by viper.GetString()
etc, see viper framework for
more details.
Also see examples.
INFO[0001] Get account balances success balances="[{BTC 0.00000092 0} {ETH 0.0000053 0} {USDT 111.51295105 0} {BUSD 0.00914978 0}]"
INFO[0001] Register strategy success strategy=UpDownRate
INFO[0002] Subscribe account success
INFO[0005] Subscribe market data success streams="[ethusdt@kline_1m ethusdt@miniTicker]"
INFO[0005] Start trader success
You can earn BTC
and ETH
when sleep now!
Get orders by strategy and symbol.
Get strategy information by strategy and symbol.
Get fund information by strategy.
Add fund for strategy.
This project is licensed under the Apache-2.0 License.