exchange

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2020 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Constants

View Source
const (
	MIN1  = time.Minute
	MIN5  = time.Minute * 5
	MIN15 = time.Minute * 15
	MIN30 = time.Minute * 30
	HOUR1 = time.Hour
	HOUR4 = time.Hour * 4
	DAY1  = time.Hour * 24
	MON1  = DAY1 * 30
	WEEK1 = DAY1 * 7
	YEAR1 = DAY1 * 365
)
View Source
const (
	Open      OrderStatus = 1 // open but not filled
	Closed                = 2 // full filled
	Filled                = 3 // part filled
	Cancelled             = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Exchange added in v0.13.0

type Exchange interface {
	RestAPIExchange
	WsAPIExchange
}

common exchange interface, for all symbols, all crypto-exchanges

type Fee added in v0.15.0

type Fee struct {
	Symbol      string
	BaseMaker   decimal.Decimal `json:"baseMaker"`
	BaseTaker   decimal.Decimal `json:"baseTaker"`
	ActualMaker decimal.Decimal `json:"actualMaker"`
	ActualTaker decimal.Decimal `json:"actualTaker"`
}

type Order added in v0.13.0

type Order struct {
	Id            uint64 // Id should be uint64
	ClientOrderId string `bson:"clientOrderId"`

	Type      string
	Symbol    string
	Price     decimal.Decimal
	Amount    decimal.Decimal
	Timestamp int64

	Status string

	FilledPrice  decimal.Decimal
	FilledAmount decimal.Decimal
	Trades       []Trade
}

type OrderStatus added in v0.13.0

type OrderStatus = int

type OrderType added in v0.13.0

type OrderType = int
const (
	Buy  OrderType = 1
	Sell           = -1
)

type ResponseHandler added in v0.13.0

type ResponseHandler func(response interface{})

type RestAPIExchange added in v0.13.0

type RestAPIExchange interface {
	FormatSymbol(base, quote string) string
	AllSymbols(ctx context.Context) (s []Symbol, err error)
	GetSymbol(ctx context.Context, symbol string) (Symbol, error)
	GetFee(symbol string) (fee Fee, err error)
	SpotBalance() (map[string]decimal.Decimal, error)
	SpotAvailableBalance() (map[string]decimal.Decimal, error)
	LastPrice(symbol string) (decimal.Decimal, error)
	Last24hVolume(symbol string) (decimal.Decimal, error)
	CandleBySize(symbol string, period time.Duration, size int) (hs.Candle, error)
	CandleFrom(symbol, clientId string, period time.Duration, from, to time.Time) (hs.Candle, error)

	//PlaceOrder(orderType, symbol, clientOrderId string, price, amount decimal.Decimal) (uint64, error)
	BuyLimit(symbol, clientOrderId string, price, amount decimal.Decimal) (orderId uint64, err error)
	SellLimit(symbol, clientOrderId string, price, amount decimal.Decimal) (orderId uint64, err error)
	BuyMarket(symbol Symbol, clientOrderId string, amount decimal.Decimal) (orderId uint64, err error)
	SellMarket(symbol Symbol, clientOrderId string, amount decimal.Decimal) (orderId uint64, err error)
	BuyStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)
	SellStopLimit(symbol, clientOrderId string, price, amount, stopPrice decimal.Decimal) (orderId uint64, err error)

	GetOrderById(orderId uint64, symbol string) (Order, error)
	CancelOrder(symbol string, orderId uint64) error
	IsFullFilled(symbol string, orderId uint64) (Order, bool, error)
}

common exchange interface for all symbols

type Symbol added in v0.13.0

type Symbol struct {
	Symbol          string
	Disabled        bool
	BaseCurrency    string          `json:"baseCurrency"`  // 交易对中的基础币种, coin, eg. BTC
	QuoteCurrency   string          `json:"quoteCurrency"` // 交易对中的报价币种, cash, eg. USDT
	PricePrecision  int32           `json:"pricePrecision"`
	AmountPrecision int32           `json:"amountPrecision"`
	MinAmount       decimal.Decimal `json:"minAmount"`
	MinTotal        decimal.Decimal `json:"minTotal"`
}

type Ticker

type Ticker struct {
	Id            int64
	Last          decimal.Decimal // 最新成交价
	LowestAsk     decimal.Decimal // 卖1,卖方最低价
	HighestBid    decimal.Decimal // 买1,买方最高价
	PercentChange decimal.Decimal // 涨跌百分比
	BaseVolume    decimal.Decimal // 交易量
	QuoteVolume   decimal.Decimal // 兑换货币交易量
	High24hr      decimal.Decimal // 24小时最高价
	Low24hr       decimal.Decimal // 24小时最低价
}

type Trade added in v0.13.0

type Trade struct {
	Id          uint64 // Id should be uint64
	Price       decimal.Decimal
	Amount      decimal.Decimal
	FeeCurrency string
	FeeAmount   decimal.Decimal
}

type WsAPIExchange added in v0.13.0

type WsAPIExchange interface {
	SubscribeOrder(symbol, clientId string, responseHandler ResponseHandler)
	UnsubscribeOrder(symbol, clientId string)
	SubscribeCandlestick(symbol, clientId string, period time.Duration, responseHandler ResponseHandler)
	UnsubscribeCandlestick(symbol, clientId string, period time.Duration)
	SubscribeCandlestickWithReq(symbol, clientId string, period time.Duration, responseHandler ResponseHandler)
	UnsubscribeCandlestickWithReq(symbol, clientId string, period time.Duration)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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