core

package
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: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EventCandle = "candle"
	EventOrder  = "order"
	// own trades
	EventTrade       = "trade"
	EventPosition    = "position"
	EventCurPosition = "cur_position" // position of current script
	EventRiskLimit   = "risk_limit"
	EventDepth       = "depth"
	// all trades in the markets
	EventTradeMarket = "trade_market"

	EventBalance     = "balance"
	EventBalanceInit = "balance_init"

	EventWatch       = "watch"
	EventWatchCandle = "watch_candle"

	EventNotify = "notify"
)

Events

Variables

Functions

func Map2Candle

func Map2Candle(data interface{}) (candle *Candle)

Map2Candle convert candle to map

func RegisterExchange

func RegisterExchange(name string, fn NewExchangeFn)

Types

type BalanceInfo

type BalanceInfo struct {
	Balance float64
}

BalanceInfo balance

type CandleInfo

type CandleInfo struct {
	Exchange string
	Symbol   string
	BinSize  string
	Data     interface{}
}

CandleInfo candle data with symbol info

type CandleName

type CandleName struct {
	Name    string
	BinSize string
}

CandleName candle info

func NewCandleName

func NewCandleName(name, binSize string) *CandleName

NewCandleName create CandleName with name and binSize

func ParseCandleName

func ParseCandleName(name string) *CandleName

ParseCandleName parse string to CandleName

func (*CandleName) String

func (c *CandleName) String() string

String return string

type CandleParam

type CandleParam struct {
	Start    time.Time
	End      time.Time
	Exchange string
	BinSize  string
	Symbol   string
}

CandleParam get candle param

type EventData

type EventData struct {
	Type string      `json:"type"`
	Data interface{} `json:"data"`
}

func (*EventData) UnmarshalJSON

func (d *EventData) UnmarshalJSON(buf []byte) (err error)

UnmarshalJSON EventData can't be used as Embed

type Exchange

type Exchange interface {
	Start(map[string]interface{}) error
	Stop() error

	// Kline get klines
	GetKline(symbol, bSize string, start, end time.Time) (data chan *Candle, err chan error)

	Watch(WatchParam) error

	// for trade
	// ProcessOrder process order
	ProcessOrder(act TradeAction) (ret *Order, err error)
	CancelAllOrders() (orders []*Order, err error)

	// GetBalanceChan
	GetDataChan() chan *ExchangeData
}

func NewExchange

func NewExchange(name string, cfg *viper.Viper, cltName, symbol string) (ex Exchange, err error)

type ExchangeData

type ExchangeData struct {
	Data EventData `json:"data"`
	Name string
}

func NewExchangeData

func NewExchangeData(name, typ string, data interface{}) *ExchangeData

func (*ExchangeData) GetData

func (e *ExchangeData) GetData() interface{}

func (*ExchangeData) GetType

func (e *ExchangeData) GetType() string

type NewExchangeFn

type NewExchangeFn func(cfg *viper.Viper, cltName, symbol string) (t Exchange, err error)

type NotifyEvent

type NotifyEvent struct {
	Type    string // text,markdown
	Content string
}

NotifyEvent event to send notify

type RiskLimit

type RiskLimit struct {
	Code         string  // symbol info, empty = global
	Lever        float64 // lever
	MaxLostRatio float64 // max lose ratio
}

RiskLimit risk limit

func (RiskLimit) Key

func (r RiskLimit) Key() string

Key key of r

type RiskLimits

type RiskLimits map[string]RiskLimit

RiskLimits risk limits

func NewRiskLimits

func NewRiskLimits() (rl RiskLimits)

func (RiskLimits) GetLimitRatio

func (rl RiskLimits) GetLimitRatio(limit RiskLimit) (ret float64)

func (RiskLimits) Update

func (rl RiskLimits) Update(limit RiskLimit)

type SymbolInfo

type SymbolInfo struct {
	ID          int64  `xorm:"pk autoincr null 'id'"`
	Exchange    string `xorm:"notnull unique(esr)  'exchange'"`
	Symbol      string `xorm:"notnull unique(esr) 'symbol'"`
	Resolutions string `xorm:"notnull unique(esr) 'resolutions'"`
	Pricescale  int    `xorm:"notnull 'pricescale'"`
}

SymbolInfo symbol infos

func (*SymbolInfo) GetResolutions

func (si *SymbolInfo) GetResolutions() []string

type WatchParam

type WatchParam = EventData

WatchParam add watch event param

func NewWatchCandle

func NewWatchCandle(cp *CandleParam) *WatchParam

Jump to

Keyboard shortcuts

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