backtest

package
v0.1.32 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2020 License: MIT Imports: 11 Imported by: 0

README

backtest

根据 https://github.com/ThreeDotsLabs/watermill/blob/482e08e8bb2a28b1c80dd4c00792fa8d23391f5e/pubsub/gochannel/pubsub.go#L194 中的源代码

func (g *GoChannel) Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error) {
	// ....
	go func(s *subscriber, g *GoChannel) {
		select {
		case <-ctx.Done():
			// unblock
		case <-g.closing:
			// unblock
		}
		s.Close()
	    // ....
	}(s, g)
	// ....
	return s.outputChannel, nil
}

GoChannel.Close() 后,所有的 subscriber 也会被 close。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BalanceService

func BalanceService(ctx context.Context, ps Pubsub, prices map[string]float64, asset string)

BalanceService 会在每天的凌晨零点零分零秒记录 balance 的总价值 prices 里面需要放好各种资产的价格,不要忘记 capital 的价格是 1

func NewBackTest

func NewBackTest(ctx context.Context, ps Pubsub, balance exch.Balance)

NewBackTest returns a new trade center - bt bt subscribe "tick", "order" and "cancelAllOrders" topics from pubsub and bt publish "balance" topic

TODO: 在成交的时候,还需要发布 "traded" 具体的成交信息。

func NextIDFunc

func NextIDFunc() func() int64

NextIDFunc 返回的函数,可以生成连续的 ID

func TickBarService

func TickBarService(ctx context.Context, ps Pubsub, interval time.Duration)

TickBarService 会负责接受从 "tick" 话题中接受 tick 数据, 生成 Bar 后,会发送数据到对应的话题中。 例如,生成日 bar 线后,发送到 "24h0m0sBar" 话题中 例如,生成 30 日 bar 线后,发送到 "720h0m0sBar" 话题中

Types

type BackTest

type BackTest struct {
}

BackTest 是一个模拟的交易中心

type Publisher

type Publisher interface {
	Publish(topic string, messages ...*message.Message) error
	Close() error
}

Publisher is publish interface of watermill

type Pubsub

type Pubsub interface {
	Publisher
	Subscriber
}

Pubsub is a combination of interface of watermill

type Subscriber

type Subscriber interface {
	Subscribe(ctx context.Context, topic string) (<-chan *message.Message, error)
}

Subscriber is publish interface of watermill

Jump to

Keyboard shortcuts

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