exapi

package module
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

README

exapi

a wrapper of digital exchange api

Documentation

Index

Constants

View Source
const (
	Depth_Default = 0   // 默认深度
	Depth5        = 5   // 5档
	Depth10       = 10  // 10档
	Depth20       = 20  // 20档
	Depth50       = 50  // 50档
	Depth100      = 100 // 100档
)

深度挡位。 有些挡位,在一些交易所不支持时,会置为Depth_Default,按交易所实际的挡位输出。

View Source
const (
	Depth_Aggregate_Default = 0 // 默认深度
	Depth_Aggregate1        = 1 // 5档
	Depth_Aggregate2        = 2 // 10档
	Depth_Aggregate3        = 3 // 20档
	Depth_Aggregate4        = 4 // 50档
	Depth_Aggregate5        = 5 // 100档
)

深度聚合。 挡位价格的聚合。

View Source
const (
	OPEN_BUY   = 1 + iota //开多
	OPEN_SELL             //开空
	CLOSE_BUY             //平多
	CLOSE_SELL            //平空
)
View Source
const (
	KLINE_PERIOD_1MIN = 1 + iota
	KLINE_PERIOD_3MIN
	KLINE_PERIOD_5MIN
	KLINE_PERIOD_15MIN
	KLINE_PERIOD_30MIN
	KLINE_PERIOD_60MIN
	KLINE_PERIOD_1H
	KLINE_PERIOD_2H
	KLINE_PERIOD_4H
	KLINE_PERIOD_6H
	KLINE_PERIOD_8H
	KLINE_PERIOD_12H
	KLINE_PERIOD_1DAY
	KLINE_PERIOD_3DAY
	KLINE_PERIOD_1WEEK
	KLINE_PERIOD_1MONTH
	KLINE_PERIOD_1YEAR
)

k线周期

View Source
const (
	HUOBI       = "huobi"
	BINANCE     = "binance"
	OKEX        = "okex"
	ZB          = "zb"
	ET          = "et"
	COINEX      = "coinex"
	OKCOIN_CN   = "okcoin"
	OKCOIN_COM  = "okcoin"
	OKEX_FUTURE = "okex"
	OKEX_SWAP   = "okex"
	BITSTAMP    = "bitstamp"
	KRAKEN      = "kraken"
	BITFINEX    = "bitfinex"
	POLONIEX    = "poloniex"
	BITHUMB     = "bithumb"
	GATE        = "gate"
	BITTREX     = "bittrex"
	GDAX        = "gdax"
	WEX_NZ      = "wex"
	BIGONE      = "bigone"
	COIN58      = "58coin"
	FCOIN       = "fcoin"
	HITBTC      = "hitbtc"
	BITMEX      = "bitmex"
	CRYPTOPIA   = "cryptopia"
	HBDM        = "hbdm"
	BITZ        = "bitz"
	AOFEX       = "aofex"
	JBEX        = "jbex"
	UPEX        = "upex"
)

exchanges const

View Source
const (
	STREAM_TICKER = "__TICKER"
	STREAM_DEPTH  = "__DEPTH"
	STREAM_TRADE  = "__TRADE"
)

Variables

View Source
var (
	THIS_WEEK_CONTRACT = "this_week" //周合约
	NEXT_WEEK_CONTRACT = "next_week" //次周合约
	QUARTER_CONTRACT   = "quarter"   //季度合约
)
View Source
var (
	UNKNOWN = Currency{"UNKNOWN"}
	CNY     = Currency{"CNY"}
	USD     = Currency{"USD"}
	USDT    = Currency{"USDT"}
	PAX     = Currency{"PAX"}
	USDC    = Currency{"USDC"}

	BCC = Currency{"BCC"}
	BCH = Currency{"BCH"}

	UNKNOWN_PAIR = CurrencyPair{UNKNOWN, UNKNOWN}
)
View Source
var ErrorAssetNotFound = errors.New("Asset not found")

币种未找到

View Source
var ErrorUnsupported = errors.New("Unsupported")

接口暂不支持的错误

Functions

func Close

func Close(klines []Kline) (data []float64)

func CloseLog

func CloseLog()

关闭日志

func Error

func Error(format string, v ...interface{})

打印错误日志,不可关闭

func FlateUnCompress

func FlateUnCompress(data []byte) ([]byte, error)

func FloatToString

func FloatToString(v float64, n int) string

n :保留的小数点位数

func GetCurrencyMap

func GetCurrencyMap(ssm map[string]SymbolSetting) (cm map[string]struct{})

func GetParamHmacMD5Sign

func GetParamHmacMD5Sign(secret, params string) (string, error)

func GetParamHmacSHA1Sign

func GetParamHmacSHA1Sign(secret, params string) (string, error)

func GetParamHmacSHA256Base64Sign

func GetParamHmacSHA256Base64Sign(secret, params string) (string, error)

func GetParamHmacSHA256Sign

func GetParamHmacSHA256Sign(secret, params string) (string, error)

func GetParamHmacSHA512Base64Sign

func GetParamHmacSHA512Base64Sign(hmac_key string, hmac_data string) string

func GetParamHmacSHA512Sign

func GetParamHmacSHA512Sign(secret, params string) (string, error)

func GetParamHmacSha384Sign

func GetParamHmacSha384Sign(secret, params string) (string, error)

for bitfinex.com

func GetParamMD5Sign

func GetParamMD5Sign(secret, params string) (string, error)

*

*md5签名,okcoin和huobi适用

func GetSHA

func GetSHA(text string) (string, error)

func GzipUnCompress

func GzipUnCompress(data []byte) ([]byte, error)

func High

func High(klines []Kline) (data []float64)

func HttpDeleteForm

func HttpDeleteForm(client *http.Client, reqUrl string, postData url.Values, headers map[string]string) ([]byte, error)

func HttpDeleteForm2 added in v1.0.5

func HttpDeleteForm2(client *http.Client, reqUrl string, postData string, headers map[string]string) ([]byte, error)

func HttpGet

func HttpGet(client *http.Client, reqUrl string) (map[string]interface{}, error)

func HttpGet2

func HttpGet2(client *http.Client, reqUrl string, headers map[string]string) (map[string]interface{}, error)

func HttpGet3

func HttpGet3(client *http.Client, reqUrl string, headers map[string]string) ([]interface{}, error)

func HttpGet4

func HttpGet4(client *http.Client, reqUrl string, headers map[string]string, result interface{}) error

func HttpGet5

func HttpGet5(client *http.Client, reqUrl string, headers map[string]string) ([]byte, error)

func HttpPostForm

func HttpPostForm(client *http.Client, reqUrl string, postData url.Values) ([]byte, error)

func HttpPostForm2

func HttpPostForm2(client *http.Client, reqUrl string, postData url.Values, headers map[string]string) ([]byte, error)

func HttpPostForm3

func HttpPostForm3(client *http.Client, reqUrl string, postData string, headers map[string]string) ([]byte, error)

func HttpPostForm4

func HttpPostForm4(client *http.Client, reqUrl string, postData map[string]string, headers map[string]string) ([]byte, error)

func HttpPostForm5

func HttpPostForm5(client *http.Client, reqUrl string, postData string, headers map[string]string) ([]byte, error)

func HttpPostForm6

func HttpPostForm6(client *http.Client, reqUrl string, postData map[string]interface{}, headers map[string]string) ([]byte, error)

func IntersectCurrencies

func IntersectCurrencies(a, b map[string]struct{}) (currencies map[string]struct{})

func IntersectSymbols

func IntersectSymbols(a, b map[string]SymbolSetting) (symbols map[string]SymbolSetting)

func IsLoging

func IsLoging() bool

获取日志状态

func Log

func Log(format string, v ...interface{})

打印日志

func Low

func Low(klines []Kline) (data []float64)

func NewHttpRequest

func NewHttpRequest(client *http.Client, reqType string, reqUrl string, postData string, requstHeaders map[string]string) ([]byte, error)

func Open

func Open(klines []Kline) (data []float64)

k线取字段集合api

func OpenLog

func OpenLog()

开启日志

func SetLogger

func SetLogger(l Logger)

设置自定义日志接口,只需要实现接口 Write(string)

func ToBool

func ToBool(v interface{}) bool

func ToFloat64

func ToFloat64(v interface{}) float64

func ToInt

func ToInt(v interface{}) int

func ToInt64

func ToInt64(v interface{}) int64

func ToString

func ToString(v interface{}) string

func ToUint64

func ToUint64(v interface{}) uint64

func ValuesToJson

func ValuesToJson(v url.Values) ([]byte, error)

Types

type APIConfig

type APIConfig struct {
	HttpClient    *http.Client
	Endpoint      string
	ApiKey        string
	ApiSecretKey  string
	ApiPassphrase string //for okex.com v3 api
	ClientId      string //for bitstamp.net , huobi.pro

	Lever int //杠杆倍数 , for future
}

type Account

type Account struct {
	Exchange    string                  `json:"exchange,string"` // 交易所名字
	Asset       float64                 `json:"asset,string"`    //总资产
	NetAsset    float64                 `json:"netasset,string"` //净资产
	SubAccounts map[Currency]SubAccount `json:"sub_accounts"`    // 每个币种账本
}

type Connection

type Connection struct {
	// 互斥锁
	sync.Mutex

	// 消息处理函数,当有数据时调用,当断开连接时,data传nil
	OnMessage func([]byte) error
	// contains filtered or unexported fields
}

封装websocket连接,可双工读写

func NewConnection

func NewConnection(wsConn *websocket.Conn, onMessage func([]byte) error) (conn *Connection, err error)

初始化长连接

func NewConnectionWithURL

func NewConnectionWithURL(wsurl, proxyurl string, onMessage func([]byte) error) (conn *Connection, err error)

初始化长连接

func (*Connection) Close

func (conn *Connection) Close()

关闭连接

func (*Connection) ReceiveMessage

func (conn *Connection) ReceiveMessage() (data []byte, err error)

接收数据

func (*Connection) SendMessage

func (conn *Connection) SendMessage(data []byte) (err error)

发送数据

type Currency

type Currency struct {
	Name string `json:"name"`
}

func NewCurrency

func NewCurrency(name string) Currency

func (Currency) AdaptBccToBch

func (c Currency) AdaptBccToBch() Currency

func (Currency) AdaptBchToBcc

func (c Currency) AdaptBchToBcc() Currency

BCC就是BCH的别名,很多交易所已经移除了BCC的叫法。

func (Currency) Equal

func (c Currency) Equal(c2 Currency) bool

func (Currency) LowerSymbol

func (c Currency) LowerSymbol() string

func (Currency) String

func (c Currency) String() string

func (Currency) Symbol

func (c Currency) Symbol() string

type CurrencyPair

type CurrencyPair struct {
	Stock Currency `json:"stock"`
	Money Currency `json:"money"`
}

func NewCurrencyPair

func NewCurrencyPair(stock Currency, money Currency) CurrencyPair

func NewCurrencyPairFromString

func NewCurrencyPairFromString(market string) CurrencyPair

func (CurrencyPair) AdaptBccToBch

func (pair CurrencyPair) AdaptBccToBch() CurrencyPair

func (CurrencyPair) AdaptBchToBcc

func (pair CurrencyPair) AdaptBchToBcc() CurrencyPair

It is currently applicable to binance and zb

func (CurrencyPair) AdaptUsdToUsdt

func (pair CurrencyPair) AdaptUsdToUsdt() CurrencyPair

func (CurrencyPair) AdaptUsdtToUsd

func (pair CurrencyPair) AdaptUsdtToUsd() CurrencyPair

func (CurrencyPair) Equal

func (pair CurrencyPair) Equal(c2 CurrencyPair) bool

func (CurrencyPair) Reverse

func (pair CurrencyPair) Reverse() CurrencyPair

func (CurrencyPair) String

func (pair CurrencyPair) String() string

func (CurrencyPair) ToLowerSymbol

func (pair CurrencyPair) ToLowerSymbol(sep string) string

func (CurrencyPair) ToSymbol

func (pair CurrencyPair) ToSymbol(sep string) string

type CurrencyStatus

type CurrencyStatus struct {
	Deposit  bool // 是否可以充值
	Withdraw bool // 是否可以提币
}

type Depth

type Depth struct {
	ContractType string       `json:"contract_type"` // for future
	Market       CurrencyPair `json:"market"`        // 交易对
	Symbol       string       `json:"symbol"`        // 交易对
	TS           int64        `json:"ts"`            // 时间,单位为毫秒(millisecond)
	AskList      DepthRecords `json:"asks"`          // 卖方订单列表,价格从低到高排序
	BidList      DepthRecords `json:"bids"`          // 买方订单列表,价格从高到底排序
}

type DepthRecord

type DepthRecord struct {
	Price  float64 `json:"price,string"`  // 报价
	Amount float64 `json:"amount,string"` // 数量
}

type DepthRecords

type DepthRecords []DepthRecord

func (DepthRecords) Len

func (dr DepthRecords) Len() int

func (DepthRecords) Less

func (dr DepthRecords) Less(i, j int) bool

func (DepthRecords) Swap

func (dr DepthRecords) Swap(i, j int)

type FutureAccount

type FutureAccount struct {
	FutureSubAccounts map[Currency]FutureSubAccount
}

type FutureKline

type FutureKline struct {
	*Kline
	Vol2 float64 //个数
}

type FutureOrder

type FutureOrder struct {
	OrderID2     string //请尽量用这个字段替代OrderID字段
	Price        float64
	Amount       float64
	AvgPrice     float64
	DealAmount   float64
	OrderID      int64
	OrderTime    int64
	Status       TradeStatus
	Currency     CurrencyPair
	OType        int     //1:开多 2:开空 3:平多 4: 平空
	LeverRate    int     //倍数
	Fee          float64 //手续费
	ContractName string
}

type FuturePosition

type FuturePosition struct {
	BuyAmount      float64
	BuyAvailable   float64
	BuyPriceAvg    float64
	BuyPriceCost   float64
	BuyProfitReal  float64
	CreateDate     int64
	LeverRate      int
	SellAmount     float64
	SellAvailable  float64
	SellPriceAvg   float64
	SellPriceCost  float64
	SellProfitReal float64
	Symbol         CurrencyPair //btc_usd:比特币,ltc_usd:莱特币
	ContractType   string
	ContractId     int64
	ForceLiquPrice float64 //预估爆仓价
}

type FutureSubAccount

type FutureSubAccount struct {
	Currency      Currency
	AccountRights float64 //账户权益
	KeepDeposit   float64 //保证金
	ProfitReal    float64 //已实现盈亏
	ProfitUnreal  float64
	RiskRate      float64 //保证金率
}

type FutureTicker

type FutureTicker struct {
	*Ticker
	ContractType string  `json:"omitempty"`
	ContractId   int     `json:"contractId"`
	LimitHigh    float64 `json:"limitHigh,string"`
	LimitLow     float64 `json:"limitLow,string"`
	HoldAmount   float64 `json:"hold_amount,string"`
	UnitAmount   float64 `json:"unitAmount,string"`
}

type Kline

type Kline struct {
	Market CurrencyPair `json:"market"`       // 交易对
	Symbol string       `json:"symbol"`       // 交易对
	TS     int64        `json:"ts"`           // 开盘时间,单位为秒(second)
	Open   float64      `json:"open,string"`  // 开盘价
	Close  float64      `json:"close,string"` // 收盘价
	High   float64      `json:"high,string"`  // 最高价
	Low    float64      `json:"low,string"`   // 最低价
	Vol    float64      `json:"vol,string"`   // 报价币种成交量
}

type KlinePeriod

type KlinePeriod int

K线周期。

const (
	KLINE_M1    KlinePeriod = iota // k线,周期1分钟
	KLINE_M5                       // k线,周期5分钟
	KLINE_M15                      // k线,周期15分钟
	KLINE_M30                      // k线,周期30分钟
	KLINE_H1                       // k线,周期1小时
	KLINE_H4                       // k线,周期4小时
	KLINE_DAY                      // k线,周期1天
	KLINE_WEEK                     // k线,周期1星期
	KLINE_MONTH                    // k线,周期1个月
)

type Logger

type Logger interface {
	Write(string)
}

日志接口,外部系统可以使用此接口来替换默认日志

type Order

type Order struct {
	OrderID    string       `json:"order_id"`           // 订单id
	Price      float64      `json:"price,string"`       // 委托价格
	Amount     float64      `json:"amount,string"`      // 委托量
	AvgPrice   float64      `json:"avg_price,string"`   // 平均成交价
	DealAmount float64      `json:"deal_amount,string"` // 成交量
	Fee        float64      `json:"fee,string"`         // 手续费
	TS         int64        `json:"ts"`                 // 时间,单位为毫秒(millisecond)
	Status     TradeStatus  `json:"status"`             // 订单状态
	Market     CurrencyPair `json:"market"`             // 交易对
	Symbol     string       `json:"symbol"`             // 交易对
	Side       TradeSide    `json:"side"`               // 交易方向
}

type OrderDeal

type OrderDeal struct {
	OrderID          string       `json:"order_id"`                  // 订单id
	DealID           string       `json:"deal_id"`                   // 本次成交id
	TS               int64        `json:"ts"`                        // 时间,单位为毫秒(millisecond)
	Price            float64      `json:"price,string"`              // 委托价格
	FilledAmount     float64      `json:"filled_amount,string"`      // 本次成交量
	FilledCashAmount float64      `json:"filled_cash_amount,string"` // 本次成交金额
	UnFilledAmount   float64      `json:"unfilled_amount,string"`    // 未成交的量
	Side             TradeSide    `json:"side"`                      // 交易方向
	Market           CurrencyPair `json:"market"`                    // 交易对
	Symbol           string       `json:"symbol"`                    // 交易对
}

type SpotAPI

type SpotAPI interface {
	// 获取交易所名称
	GetExchangeName() string
	// 设置交易所地址,仅在初始化时设置,不支持后续动态更改
	SetURL(exurl string)
	// 获取交易所地址
	GetURL() string

	// 获取支持的交易对
	GetAllCurrencyPair() (map[string]SymbolSetting, error)
	// 获取此币种是否可以充提币
	GetCurrencyStatus(currency Currency) (CurrencyStatus, error)
	// 获取所有币种是否可以充提币
	GetAllCurrencyStatus() (map[string]CurrencyStatus, error)

	// 公共行情
	// 获取单一币种对的行情
	GetTicker(pair CurrencyPair) (*Ticker, error)
	// 获取所有币种对的行情
	GetAllTicker() ([]Ticker, error)
	//获取单一币种对的深度
	GetDepth(pair CurrencyPair, size int, step int) (*Depth, error)
	// 获取单一币种对的成交记录
	GetTrades(pair CurrencyPair, size int) ([]Trade, error)
	// 获取单一币种对的K线记录,按时间升序排列
	GetKlineRecords(pair CurrencyPair, period KlinePeriod, size, since int) ([]Kline, error)

	// 交易相关
	// 限价单
	LimitBuy(pair CurrencyPair, price, amount string) (*Order, error)
	LimitSell(pair CurrencyPair, price, amount string) (*Order, error)
	// 市价单,下单后返回的数据不准,需要调用GetOrder获取准确信息
	// 买入金额,单位为计价货币
	MarketBuy(pair CurrencyPair, amount string) (*Order, error)
	// 卖出数量,单位为基础货币
	MarketSell(pair CurrencyPair, amount string) (*Order, error)
	// 撤单
	Cancel(orderId string, pair CurrencyPair) (bool, error)
	// 获取订单详情
	GetOrder(orderId string, pair CurrencyPair) (*Order, error)
	// 获取当前未完成订单列表
	GetPendingOrders(pair CurrencyPair) ([]Order, error)
	// 获取最近完成订单
	GetFinishedOrders(pair CurrencyPair) ([]Order, error)
	// 获取订单的成交明细
	GetOrderDeal(orderId string, pair CurrencyPair) ([]OrderDeal, error)
	// 获取单一币种对的最近成交明细
	GetUserTrades(pair CurrencyPair) ([]Trade, error)
	// 获取账户余额
	GetAccount() (*Account, error)
}

spot api interface

type SpotWebsocket

type SpotWebsocket interface {
	// 设置交易所地址,仅在初始化时设置,不支持后续动态更改
	SetURL(exURL string)
	// 获取交易所地址
	GetURL() string
	// 设置代理地址
	SetProxyURL(proxyURL string)
	// 获取代理地址
	GetProxyURL() string

	// 订阅或取消行情,cb传nil为取消,目前cb只有最后一次设置的生效
	SubTicker(pair CurrencyPair, cb func(*Ticker) error) (err error)
	SubDepth(pair CurrencyPair, cb func(*Depth) error) (err error)
	SubTrade(pair CurrencyPair, cb func([]Trade) error) (err error)
	//SubKline(pair CurrencyPair, period KlinePeriod, cb func([]Kline) error) (err error)
	// 全部重新订阅
	Resubscribe() (err error)
	// 全部取消订阅
	Unsubscribe() (err error)
	// 设置初始化函数,当连接建立时调用
	SetConnectHandler(h func(*Connection) error)
	// 设置心跳函数
	SetHeartBeatHandler(h func(*Connection) error)
	// 关闭连接
	Close()

	// 以下为需要单独定制的接口
	// 获取交易所名称
	GetExchangeName() string
	// 格式化主题名称
	FormatTopicName(topic string, pair CurrencyPair) string
	// 格式化主题订阅消息
	FormatTopicSubData(topic string, pair CurrencyPair) []byte
	// 格式化主题取消订阅消息
	FormatTopicUnsubData(topic string, pair CurrencyPair) []byte
	// 消息解析函数
	OnMessage([]byte) error
}

type SpotWsBase

type SpotWsBase struct {
	SpotWebsocket
	// 交易所地址
	WsURL string
	// 代理地址
	ProxyURL string
	// 心跳时长
	HeartbeatIntervalTime time.Duration

	// 底层websocket连接
	Conn *Connection
	// 消息主题的map
	TopicMap TopicMap

	// 连接建立处理函数
	OnConnect func(*Connection) error

	// 心跳处理函数
	OnHeartBeat func(*Connection) error

	// callbacks
	OnTicker func(*Ticker) error
	OnDepth  func(*Depth) error
	OnTrade  func([]Trade) error
	// contains filtered or unexported fields
}

func (*SpotWsBase) Close

func (ws *SpotWsBase) Close()

关闭连接

func (*SpotWsBase) GetPairByStream

func (ws *SpotWsBase) GetPairByStream(topic string) (pair CurrencyPair)

func (*SpotWsBase) GetProxyURL

func (ws *SpotWsBase) GetProxyURL() string

func (*SpotWsBase) GetURL

func (ws *SpotWsBase) GetURL() string

func (*SpotWsBase) Loop

func (ws *SpotWsBase) Loop()

func (*SpotWsBase) Pack

func (ws *SpotWsBase) Pack(topic interface{}) []byte

func (*SpotWsBase) Resubscribe

func (ws *SpotWsBase) Resubscribe() (err error)

全部重新订阅

func (*SpotWsBase) SetConnectHandler

func (ws *SpotWsBase) SetConnectHandler(h func(*Connection) error)

设置初始化函数,当连接建立时调用

func (*SpotWsBase) SetDisconnected

func (ws *SpotWsBase) SetDisconnected(disconnected bool)

func (*SpotWsBase) SetHeartBeatHandler

func (ws *SpotWsBase) SetHeartBeatHandler(h func(*Connection) error)

设置心跳处理函数

func (*SpotWsBase) SetProxyURL

func (ws *SpotWsBase) SetProxyURL(proxyURL string)

func (*SpotWsBase) SetURL

func (ws *SpotWsBase) SetURL(exURL string)

func (*SpotWsBase) SubDepth

func (ws *SpotWsBase) SubDepth(pair CurrencyPair, cb func(*Depth) error) (err error)

func (*SpotWsBase) SubTicker

func (ws *SpotWsBase) SubTicker(pair CurrencyPair, cb func(*Ticker) error) (err error)

func (*SpotWsBase) SubTrade

func (ws *SpotWsBase) SubTrade(pair CurrencyPair, cb func([]Trade) error) (err error)

func (*SpotWsBase) Unsubscribe

func (ws *SpotWsBase) Unsubscribe() (err error)

全部取消订阅

type StreamType

type StreamType string

流常量

type SubAccount

type SubAccount struct {
	Currency     Currency // 币种
	Amount       float64  `json:"amount,string"`        // 可用余额
	FrozenAmount float64  `json:"frozen_amount,string"` // 冻结余额
	LoanAmount   float64  `json:"loan_amount,string"`   // 借贷余额
}

type SymbolSetting

type SymbolSetting struct {
	Symbol      string  `json:"symbol"`       // 币对名称
	Base        string  `json:"base"`         // 基础币种
	Quote       string  `json:"quote"`        // 报价币种
	MinSize     float64 `json:"min_size"`     // 最小交易量
	MinPrice    float64 `json:"min_price"`    // 最小价格
	MinNotional float64 `json:"min_notional"` // 最小成交量,价格和数量相乘必须要大于此值
	MakerFee    float64 `json:"maker_fee"`    // 挂单手续费
	TakerFee    float64 `json:"taker_fee"`    // 吃单手续费
}

币对基本信息

type Ticker

type Ticker struct {
	//Symbol string       `json:"symbol"`      // 交易对
	Market CurrencyPair `json:"market"`      // 交易对
	Symbol string       `json:"symbol"`      // 交易对
	Open   float64      `json:"open,string"` // 开盘价
	Last   float64      `json:"last,string"` // 收盘价
	High   float64      `json:"high,string"` // 最高价
	Low    float64      `json:"low,string"`  // 最低价
	Vol    float64      `json:"vol,string"`  // 基础币种成交量
	Buy    float64      `json:"buy,string"`  // 最优买价
	Sell   float64      `json:"sell,string"` // 最优卖家
	TS     int64        `json:"ts"`          // 最新时间,单位为毫秒(millisecond)
}

type TopicMap

type TopicMap struct {
	// contains filtered or unexported fields
}

// 订单id到订单的映射

func NewStreamMap

func NewStreamMap() *TopicMap

func (*TopicMap) Delete

func (m *TopicMap) Delete(k string)

func (*TopicMap) Load

func (m *TopicMap) Load(k string) (pair CurrencyPair, ok bool)

func (*TopicMap) LoadOrStore

func (m *TopicMap) LoadOrStore(k string, pair CurrencyPair) (actualPair CurrencyPair, loaded bool)

func (*TopicMap) Range

func (m *TopicMap) Range(f func(k string, v CurrencyPair) bool)

func (*TopicMap) Store

func (m *TopicMap) Store(k string, v CurrencyPair)

type Trade

type Trade struct {
	Tid    int64        `json:"tid"`           // 交易id
	Side   TradeSide    `json:"type"`          // 交易方向
	Amount float64      `json:"amount,string"` // 成交量
	Price  float64      `json:"price,string"`  // 成交价
	TS     int64        `json:"ts"`            // 时间,单位为毫秒(millisecond)
	Market CurrencyPair `json:"market"`        // 交易对
	Symbol string       `json:"symbol"`        // 交易对
}

type TradeSide

type TradeSide int
const (
	BUY TradeSide = 1 + iota
	SELL
	BUY_MARKET
	SELL_MARKET
)

func AdaptTradeSide

func AdaptTradeSide(side string) TradeSide

func (TradeSide) String

func (ts TradeSide) String() string

type TradeStatus

type TradeStatus int
const (
	ORDER_UNFINISH TradeStatus = iota
	ORDER_PART_FINISH
	ORDER_FINISH
	ORDER_CANCEL
	ORDER_REJECT
	ORDER_CANCEL_ING
	ORDER_FAIL
)

func (TradeStatus) String

func (ts TradeStatus) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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