exchange

package
v0.0.0-...-089aa6e Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterExchange

func RegisterExchange(exchange Type, iExchange IExchange)

Types

type Balance

type Balance struct {
	Asset  string
	Free   decimal.Decimal
	Locked decimal.Decimal
}

type BaseApi

type BaseApi struct {
	IApi
	ApiKey      string
	ApiSecret   string
	RestyClient *resty.Client
}

func (*BaseApi) BuildCommonQuery

func (api *BaseApi) BuildCommonQuery(params map[string]interface{}, withSign bool) string

构建必要参数

type BaseExchange

type BaseExchange struct {
	IExchange
	//余额信息
	Balances []Balance
}

func (*BaseExchange) GetBalance

func (exchange *BaseExchange) GetBalance(asset string) Balance

func (*BaseExchange) GetBalances

func (exchange *BaseExchange) GetBalances() []Balance

type IApi

type IApi interface {
	CancelOrder(params map[string]interface{}) (map[string]interface{}, error)
	AddOrder(params map[string]interface{}) (map[string]interface{}, error)
	KLines(params map[string]interface{}) ([][]interface{}, error)
	CreateSpotListenKey() (string, bool)
}

type IExchange

type IExchange interface {
	//订阅市场数据
	SubscribeMarketData(streams []string, callback func(map[string]interface{})) error
	//订阅订单更新
	SubscribeAccount(callback func(map[string]interface{})) error
	//近期K线
	NewKLineService() IKLineService
	//下单
	AddOrder(order db.Order) (map[string]interface{}, error)
	//取消订单
	CancelOrder(symbol string, orderId string) (map[string]interface{}, error)
	//刷新账户信息
	RefreshAccount()
	//获取账户余额
	GetBalance(asset string) Balance
	//获取账户所有余额
	GetBalances() []Balance
	//创建exchange
	NewExchange(apiKey string, apiSecret string) IExchange
	//ParseKLine
	ParseKLine(data map[string]interface{}) KLine
	//ParseTicker
	ParseTicker(data map[string]interface{}) Ticker
}

func NewExchange

func NewExchange(exchange Type, apiKey string, apiSecret string) (IExchange, error)

type IKLineService

type IKLineService interface {
	SetSymbol(symbol string) IKLineService
	SetInterval(interval string) IKLineService
	SetStartTime(startTime int64) IKLineService
	SetEndTime(endTime int64) IKLineService
	SetLimit(limit int) IKLineService
	Collect() map[string]interface{}
	Do() ([]KLine, error)
}

KLine服务

type KLine

type KLine struct {
	Open      decimal.Decimal
	Close     decimal.Decimal
	High      decimal.Decimal
	Low       decimal.Decimal
	Amount    decimal.Decimal
	Volume    decimal.Decimal
	Finish    bool
	CloseTime time.Time
}

type KLineService

type KLineService struct {
	Api       IApi
	Symbol    string
	Interval  string
	StartTime *int64
	EndTime   *int64
	Limit     *int
}

func (*KLineService) Collect

func (s *KLineService) Collect() map[string]interface{}

func (*KLineService) Do

func (s *KLineService) Do() ([]KLine, error)

func (*KLineService) SetEndTime

func (s *KLineService) SetEndTime(endTime int64) IKLineService

func (*KLineService) SetInterval

func (s *KLineService) SetInterval(interval string) IKLineService

func (*KLineService) SetLimit

func (s *KLineService) SetLimit(limit int) IKLineService

func (*KLineService) SetStartTime

func (s *KLineService) SetStartTime(startTime int64) IKLineService

func (*KLineService) SetSymbol

func (s *KLineService) SetSymbol(symbol string) IKLineService

type Ticker

type Ticker struct {
	EventType             string          `json:"e"` // 事件类型
	Time                  float64         `json:"E"` // 事件时间
	Symbol                string          `json:"s"` // 交易对
	Change24Price         decimal.Decimal `json:"p"` // 24小时价格变化
	Change24Percent       decimal.Decimal `json:"P"` // 24小时价格变化(百分比)
	AvgPrice              decimal.Decimal `json:"w"` // 平均价格
	First24PricePre       decimal.Decimal `json:"x"` // 整整24小时之前,向前数的最后一次成交价格
	LatestPrice           decimal.Decimal `json:"c"` // 最新成交价格
	LatestVol             decimal.Decimal `json:"Q"` // 最新成交交易的成交量
	LatestHighPriceBuy    decimal.Decimal `json:"b"` // 目前最高买单价
	LatestHighPriceBuyVol decimal.Decimal `json:"B"` // 目前最高买单价的挂单量
	LatestLowPriceSell    decimal.Decimal `json:"a"` // 目前最低卖单价
	LatestLowPriceSellVol decimal.Decimal `json:"A"` // 目前最低卖单价的挂单量
	First24PriceAft       decimal.Decimal `json:"o"` // 整整24小时前,向后数的第一次成交价格
	High24Price           decimal.Decimal `json:"h"` // 24小时内最高成交价
	Low24Price            decimal.Decimal `json:"l"` // 24小时内最低成交价
	Vol                   decimal.Decimal `json:"v"` // 24小时内成交量
	Amount                decimal.Decimal `json:"q"` // 24小时内成交额
	StartTime             float64         `json:"O"` // 统计开始时间
	EndTime               float64         `json:"C"` // 统计结束时间
	FirstOrderId          int             `json:"F"` // 24小时内第一笔成交交易ID
	EndOrderId            int             `json:"L"` // 24小时内最后一笔成交交易ID
	OrderNum              int             `json:"n"` // 24小时内成交数
}

type Type

type Type string
const (
	BinanceSpot   Type = "BinanceSpot"
	BinanceFuture Type = "BinanceFuture"
	Mock          Type = "Mock"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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