exchange

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2026 License: BSD-3-Clause Imports: 8 Imported by: 9

README

exchange

An easy to use exchange package.

It is mainly used for ztrade.

Documentation

Index

Constants

View Source
const (
	WatchTypeCandle      = "candle"
	WatchTypeDepth       = "depth"
	WatchTypeTradeMarket = "trade_market"
	WatchTypeTrade       = "trade"
	WatchTypePosition    = "position"
	WatchTypeBalance     = "balance"
)

Variables

View Source
var (
	ErrRetry = errors.New("need retry")
)

Functions

func KlineChan

func KlineChan(e Exchange, symbol, bSize string, start, end time.Time) (dataCh chan *Candle, errCh chan error)

func RegisterExchange

func RegisterExchange(name string, fn NewExchangeFn)

Types

type Config

type Config interface {
	Get(string) interface{}
	GetBool(string) bool
	GetInt(string) int
	GetString(string) string
	UnmarshalKey(string, interface{}) error
}

func WrapViper

func WrapViper(cfg *viper.Viper) Config

type Exchange

type Exchange interface {
	Info() ExchangeInfo
	Symbols() ([]Symbol, error)

	Start() error
	Stop() error

	// Watch exchange event, call multiple times for different event
	Watch(WatchParam, WatchFn) error

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

	// for trade
	ProcessOrder(act TradeAction) (ret *Order, err error)
	CancelAllOrders() (orders []*Order, err error)
	CancelOrder(old *Order) (orders *Order, err error)
}

func NewExchange

func NewExchange(name string, cfg Config, cltName string) (ex Exchange, err error)

func NewExchangeViper

func NewExchangeViper(name, cltName string) (ex Exchange, err error)

type ExchangeConfig

type ExchangeConfig struct {
	Type   string
	Key    string
	Secret string
	IsTest bool
}

type ExchangeInfo

type ExchangeInfo struct {
	Name       string
	Value      string
	Desc       string
	KLineLimit FetchLimit
	OrderLimit FetchLimit
}

ExchangeInfo exchange info

type FetchLimit

type FetchLimit struct {
	Duration string
	Limit    int
}

type NewExchangeFn

type NewExchangeFn func(cfg Config, cltName string) (t Exchange, err error)

type ViperCfg

type ViperCfg struct {
	*viper.Viper
}

func (*ViperCfg) UnmarshalKey

func (c *ViperCfg) UnmarshalKey(key string, rawVal interface{}) error

type WatchFn

type WatchFn func(interface{})

type WatchParam

type WatchParam struct {
	Type  string
	Param map[string]string
}

func WatchCandle

func WatchCandle(symbol, binSize string) WatchParam

Directories

Path Synopsis
ctp
okx
api/account
Package account provides primitives to interact with the openapi HTTP API.
Package account provides primitives to interact with the openapi HTTP API.
api/market
Package market provides primitives to interact with the openapi HTTP API.
Package market provides primitives to interact with the openapi HTTP API.
api/public
Package public provides primitives to interact with the openapi HTTP API.
Package public provides primitives to interact with the openapi HTTP API.
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