ztrade

command module
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 8, 2022 License: BSD-3-Clause Imports: 1 Imported by: 0

README

ztrade

I hope ztrade is "The last trade app you need" !

中文

Features

  1. Develop/write strategy with only go language,no other script need
  2. Event base framework,easy to extend
  3. Support bitmex,binance
  4. use gomacro as script engine
  5. can build strategy to go golang plugin,best performance

build

make

simple run

cd dist
./ztrade --help

Use

replace your key and secret

replace your key and secret in dist/configs/ztrade.yaml

download history Kline

# run first
./ztrade download --binSize 1m --start "2020-01-01 08:00:00" --end "2021-01-01 08:00:00" --exchange binance --symbol BTCUSDT
# auto download kline
./ztrade download --symbol BTCUSDT -a --exchange binance

backtest

./ztrade backtest --script debug.go --start "2020-01-01 08:00:00" --end "2021-01-01 08:00:00" --symbol BTCUSDT --exchange binance

real trade

./ztrade trade --symbol BTCUSDT --exchange binance --script debug.go

strategy

Just copy pkg/helper/helper.go to your own strategy dir,and then you can develop it as you would normally write go code

strategy.go

type DemoStrategy struct {
}

func NewDemoStrategy() *DemoStrategy {
	return new(DemoStrategy)
}

// Param define you script params here
func (s *DemoStrategy) Param() (paramInfo []Param) {
	paramInfo = []Param{
		Param{Name: "symbol", Type: "string", Info: "symbol code"},
	}
	return
}

// Init strategy
func (s *DemoStrategy) Init(engine *Engine, params ParamData) {
	return
}

// OnCandle call when 1m candle reached
func (s *DemoStrategy) OnCandle(candle Candle) {
	var param Param
	param.Name = "hello"
	fmt.Println("candle:", candle, param)
	return
}

// OnPosition call when position is updated
func (s *DemoStrategy) OnPosition(pos float64) {
	fmt.Println("position:", pos)
	return
}

// OnTrade call call every trade occurs
func (s *DemoStrategy) OnTrade(trade Trade) {
	fmt.Println("trade:", trade)
	return
}

// OnTradeHistory call when you own trade occures
func (s *DemoStrategy) OnTradeHistory(trade Trade) {
	fmt.Println("tradeHistory:", trade)
	return
}

// OnDepth call when orderbook updated
func (s *DemoStrategy) OnDepth(depth Depth) {
	fmt.Println("depth:", depth)
	return
}

Thanks

gomacro

vnpy

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
ctl
exchange/ok/api/account
Package Account provides primitives to interact with the openapi HTTP API.
Package Account provides primitives to interact with the openapi HTTP API.
exchange/ok/api/market
Package Market provides primitives to interact with the openapi HTTP API.
Package Market provides primitives to interact with the openapi HTTP API.
exchange/ok/api/trade
Package Trade provides primitives to interact with the openapi HTTP API.
Package Trade provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL