This project is still in progress and is not a full version.
This project was inspired by backtrader
python backtrader is a great project but it has disadvantage of python GIL so i want solve by golang
go get github.com/gobenpark/cerebro
🙏 Plz wait for beta version
package main
import (
"context"
"sort"
"time"
"github.com/gobenpark/proto/stock"
"github.com/gobenpark/cerebro/container"
"github.com/gobenpark/cerebro/order"
"github.com/rs/zerolog/log"
uuid "github.com/satori/go.uuid"
)
type store struct {
name string
uid string
cli Client
}
func NewStore(name string) *store {
cli, err := stock.NewSocketClient(context.Background(), "localhost:50051")
if err != nil {
panic(err)
}
return &store{name, uuid.NewV4().String(), cli}
}
func (s *store) LoadHistory(ctx context.Context, code string, du time.Duration) ([]container.Candle, error) {
panic("implement me ")
}
func (s *store) LoadTick(ctx context.Context, code string) (<-chan container.Tick, error) {
panic("implement me ")
}
func (s *store) Order(code string, ot order.OType, size int64, price float64) error {
panic("implement me ")
}
func (s *store) Cancel(id string) error {
panic("implement me ")
}
func (s *store) Uid() string {
return s.uid
}
Next(broker,container)
is incomming tick or candle data
in this part you can every using indicator and buy, sell using broker
import (
"fmt"
"github.com/gobenpark/cerebro/broker"
"github.com/gobenpark/cerebro/container"
"github.com/gobenpark/cerebro/indicators"
"github.com/gobenpark/cerebro/order"
)
type Bighands struct {
Broker broker.Broker
indi indicators.Indicator
}
func (s *Bighands) Next(broker *broker.Broker, container container.Container) {
rsi := indicators.NewRsi(14)
rsi.Calculate(container)
fmt.Println(rsi.Get()[0])
fmt.Println(broker.GetCash())
obv := indicators.NewObv()
obv.Calculate(container)
fmt.Println(obv.Get()[0])
fmt.Println(container.Code())
sma := indicators.NewSma(20)
sma.Calculate(container)
fmt.Println(sma.Get()[0])
fmt.Println(container.Code())
}
func (s *Bighands) NotifyOrder(o *order.Order) {
switch o.Status() {
case order.Submitted:
fmt.Printf("%s:%s\n", o.Code, "Submitted")
fmt.Println(o.ExecutedAt)
case order.Expired:
fmt.Println("expired")
fmt.Println(o.ExecutedAt)
case order.Rejected:
fmt.Println("rejected")
fmt.Println(o.ExecutedAt)
case order.Canceled:
fmt.Println("canceled")
fmt.Println(o.ExecutedAt)
case order.Completed:
fmt.Printf("%s:%s\n", o.Code, "Completed")
fmt.Println(o.ExecutedAt)
fmt.Println(o.Price)
fmt.Println(o.Code)
fmt.Println(o.Size)
case order.Partial:
fmt.Println("partial")
fmt.Println(o.ExecutedAt)
}
}
func (s *Bighands) NotifyTrade() {
panic("implement me")
}
func (s *Bighands) NotifyCashValue() {
panic("implement me")
}
func (s *Bighands) NotifyFund() {
panic("implement me")
}
package main
import (
"time"
"github.com/gobenpark/cerebro/broker"
"github.com/gobenpark/cerebro/cerebro"
"github.com/gobenpark/cerebro/strategy"
)
func main() {
bk := broker.NewBroker(100000, 0.0005)
upbit := NewStore("binance")
smart := &strategy.Bighands{
Broker: bk,
}
cb := cerebro.NewCerebro(
cerebro.WithBroker(bk),
cerebro.WithStore(upbit, "KRW-MFT", "KRW-LBC"),
cerebro.WithStrategy(smart),
cerebro.WithResample("KRW-MFT", time.Minute*3, true),
cerebro.WithResample("KRW-LBC", time.Minute*3, true),
cerebro.WithLive(true),
cerebro.WithPreload(true),
)
err := cb.Start()
if err != nil {
panic(err)
}
}
Live Trader have several part of trading components
-
Cerebro : the Cerebro managements all trading components and make dependency graph
-
Store components is user base implements for external real server ex) Binance , upbit , etc
-
Strategy is user base own strategy
- Indicator
- bollinger band
- RSI
- Simple Moving Average
- On Balance Bolume
- new feature Observer is observing price and volume for find big hands
- new feature Signal
- support news, etc information base trading
- multi store one cerebro
- feature broker slippage
- Chart
- MAJOR version when you make incompatible API changes,
- MINOR version when you add functionality in a backwards compatible manner, and
- PATCH version when you make backwards compatible bug fixes. Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.
if you have any idea and want to talk this project send me mail ([email protected]) or issue