zb

package module
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: MIT Imports: 18 Imported by: 0

README

zb-api

zb.live api client for Golang

参考文档

Documentation

Index

Constants

View Source
const (
	OK = 1000
)

Variables

View Source
var (
	DefaultTransport *http.Transport
)

Functions

func CloneDefaultTransport

func CloneDefaultTransport() *http.Transport

func GetParamHmacMD5Sign

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

func GetParamHmacSHA256Base64Sign

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

func GetParamHmacSHA256Sign

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

func GetParamMD5Sign

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

*

*md5签名

func GetSHA

func GetSHA(text string) (string, error)

func ParseProxy

func ParseProxy(proxyURL string) (res func(*http.Request) (*url.URL, error), err error)

"socks5://127.0.0.1:1080"

Types

type AccountInfo

type AccountInfo struct {
	Result      AccountInfoResult `json:"result"`
	LeverPerm   bool              `json:"leverPerm"`
	OtcPerm     bool              `json:"otcPerm"`
	AssetPerm   bool              `json:"assetPerm"`
	MoneyPerm   bool              `json:"moneyPerm"`
	SubUserPerm bool              `json:"subUserPerm"`
	EntrustPerm bool              `json:"entrustPerm"`
}

type AccountInfoBase

type AccountInfoBase struct {
	AuthGoogleEnabled    bool   `json:"auth_google_enabled"`
	AuthMobileEnabled    bool   `json:"auth_mobile_enabled"`
	TradePasswordEnabled bool   `json:"trade_password_enabled"`
	Username             string `json:"username"`
}

type AccountInfoCoin

type AccountInfoCoin struct {
	IsCanWithdraw bool    `json:"isCanWithdraw"`
	CanLoan       bool    `json:"canLoan"`
	FundsType     int     `json:"fundstype"`
	ShowName      string  `json:"showName"`
	IsCanRecharge bool    `json:"isCanRecharge"`
	CnName        string  `json:"cnName"`
	EnName        string  `json:"enName"`
	Available     float64 `json:"available,string"`
	FreeZ         float64 `json:"freez,string"`
	UnitTag       string  `json:"unitTag"`
	Key           string  `json:"key"`
	UnitDecimal   int     `json:"unitDecimal"`
}

type AccountInfoResult

type AccountInfoResult struct {
	Coins   []AccountInfoCoin `json:"coins"`
	Version int64             `json:"version"`
	Base    AccountInfoBase   `json:"base"`
}

type AllTicker

type AllTicker map[string]TickerData

type Depth

type Depth struct {
	Asks      [][]float64 `json:"asks"`
	Bids      [][]float64 `json:"bids"`
	Timestamp int64       `json:"timestamp"` // 1587953173
}

type GeneralResult

type GeneralResult struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

type KLine

type KLine struct {
	Symbol    string      `json:"symbol"`
	Data      [][]float64 `json:"data"` // 时间戳(ms),Open,High,Low,Close,Volume
	MoneyType string      `json:"moneyType"`
}

type LeverAssetsInfo

type LeverAssetsInfo struct {
	Code    int                 `json:"code"`
	Message LeverAssetsInfoData `json:"message"`
}

type LeverAssetsInfoData

type LeverAssetsInfoData struct {
	Des   string               `json:"des"`
	IsSuc bool                 `json:"isSuc"`
	Datas LeverAssetsInfoDatas `json:"datas"`
}

type LeverAssetsInfoDatas

type LeverAssetsInfoDatas struct {
	LeverPerm bool                   `json:"leverPerm"`
	Levers    []LeverAssetsInfoLever `json:"levers"`
}

type LeverAssetsInfoLever

type LeverAssetsInfoLever struct {
	TotalConvertCNY      string  `json:"totalConvertCNY"`
	LoanOutConvertUSD    string  `json:"loanOutConvertUSD"`
	UnwindPrice          string  `json:"unwindPrice"`
	FOverdraft           string  `json:"fOverdraft"`
	FShowName            string  `json:"fShowName"`
	StatusShow           string  `json:"statusShow"`
	RepayLeverShow       string  `json:"repayLeverShow"`
	CCanLoanIn           int     `json:"cCanLoanIn"`
	FLoanIn              string  `json:"fLoanIn"`
	COverdraft           string  `json:"cOverdraft"`
	NetConvertUSD        string  `json:"netConvertUSD"`
	LoanInConvertCNY     string  `json:"loanInConvertCNY"`
	Key                  string  `json:"key"`
	FUnitDecimal         int     `json:"fUnitDecimal"`
	RepayLevel           int     `json:"repayLevel"`
	ShowName             string  `json:"showName"`
	LoanInConvertUSD     string  `json:"loanInConvertUSD"`
	Level                int     `json:"level"`
	NetConvertCNY        string  `json:"netConvertCNY"`
	CFreeze              string  `json:"cFreeze"`
	CUnitTag             string  `json:"cUnitTag"`
	CouldTransferOutCoin string  `json:"couldTransferOutCoin"`
	TotalConvertUSD      string  `json:"totalConvertUSD"`
	CEnName              string  `json:"cEnName"`
	LoanOutConvertCNY    string  `json:"loanOutConvertCNY"`
	FAvailable           string  `json:"fAvailable"`
	FEnName              string  `json:"fEnName"`
	CShowName            string  `json:"cShowName"`
	LeverMultiple        string  `json:"leverMultiple"`
	CouldTransferOutFiat string  `json:"couldTransferOutFiat"`
	FFreeze              string  `json:"fFreeze"`
	FCanLoanIn           float64 `json:"fCanLoanIn"`
	CLoanOut             string  `json:"cLoanOut"`
	CUnitDecimal         float64 `json:"cUnitDecimal"`
	CLoanIn              string  `json:"cLoanIn"`
	CAvailable           string  `json:"cAvailable"`
	FLoanOut             string  `json:"fLoanOut"`
	RepayLock            bool    `json:"repayLock"`
	Status               int     `json:"status"`
}

type Loan

type Loan struct {
	Amount            float64 `json:"amount,string"`
	Balance           float64 `json:"balance,string"`
	CoinName          string  `json:"coinName"` // QC
	RepaymentDay      int     `json:"repaymentDay"`
	InterestRateOfDay float64 `json:"interestRateOfDay,string"`
	LowestAmount      float64 `json:"lowestAmount"`
	RateOfDayShow     string  `json:"rateOfDayShow"` // 0.05 %
}

type LoanRecord

type LoanRecord struct {
	CreateTime           int64  `json:"createTime"`
	StatusShow           string `json:"statusShow"`
	FreezID              string `json:"freezId"`
	Tstatus              int    `json:"tstatus"`
	WithoutLxAmount      string `json:"withoutLxAmount"`
	InvestMark           bool   `json:"investMark"`
	WithoutLxDays        int    `json:"withoutLxDays"`
	HasRepay             string `json:"hasRepay"`
	Amount               string `json:"amount"`
	ID                   int64  `json:"id"`
	FwfScale             string `json:"fwfScale"`
	Rate                 string `json:"rate"`
	MarketName           string `json:"marketName"`
	HasLx                string `json:"hasLx"`
	IsIn                 bool   `json:"isIn"`
	BalanceAmount        string `json:"balanceAmount"`
	FundType             int    `json:"fundType"`
	OutUserID            int64  `json:"outUserId"`
	InUserID             int64  `json:"inUserId"`
	RepayDate            int64  `json:"repayDate"`
	ZheLx                string `json:"zheLx"`
	OutUserFees          string `json:"outUserFees"`
	DikouLx              string `json:"dikouLx"`
	SourceType           int    `json:"sourceType"`
	CoinName             string `json:"coinName"`
	Reward               string `json:"reward"`
	Status               int    `json:"status"`
	ArrearsLx            string `json:"arrearsLx"`
	BalanceWithoutLxDays int    `json:"balanceWithoutLxDays"`
	RiskManage           int    `json:"riskManage"`
	RateAddVal           string `json:"rateAddVal"`
	OutUserName          string `json:"outUserName"`
	InUserName           string `json:"inUserName"`
	InUserLock           bool   `json:"inUserLock"`
	RateForm             int    `json:"rateForm"`
	LoanID               int64  `json:"loanId"`
	NextRepayDate        int64  `json:"nextRepayDate"`
}

type LoanRecordResponse

type LoanRecordResponse struct {
	Code    int          `json:"code"`
	Message string       `json:"message"`
	Result  []LoanRecord `json:"result"`
}

type LoansResponse

type LoansResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Result  []Loan `json:"result"`
}

type Order

type Order struct {
	Currency    string  `json:"currency"`
	ID          string  `json:"id"`
	Price       float64 `json:"price"`
	Status      int     `json:"status"`
	TotalAmount float64 `json:"total_amount"`
	TradeAmount float64 `json:"trade_amount"`
	TradeDate   int64   `json:"trade_date"`
	TradeMoney  float64 `json:"trade_money"`
	Type        int     `json:"type"`
}

type OrderMoreV2Response

type OrderMoreV2Response struct {
	Code    int     `json:"code"`
	Message string  `json:"message"`
	Data    []int64 `json:"data"`
}

type OrderResponse

type OrderResponse struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	ID      string `json:"id"`
}

type Repayment

type Repayment struct {
	BenJin     string `json:"benJin"`
	ID         int64  `json:"id"`
	StatusShow string `json:"statusShow"`
	Status     int    `json:"status"`
	LiXi       string `json:"liXi"`
	ActureDate int64  `json:"actureDate"`
}

type RepaymentsResponse

type RepaymentsResponse struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Result  []Repayment `json:"result"`
}

type Ticker

type Ticker struct {
	Date   int64      `json:"date,string"` // 1587952260502
	Ticker TickerData `json:"ticker"`
}

type TickerData

type TickerData struct {
	High float64 `json:"high,string"`
	Vol  float64 `json:"vol,string"`
	Last float64 `json:"last,string"`
	Low  float64 `json:"low,string"`
	Buy  float64 `json:"buy,string"`
	Sell float64 `json:"sell,string"`
}

type Trade

type Trade struct {
	Amount    float64 `json:"amount,string"`
	Date      int64   `json:"date"`
	Price     float64 `json:"price,string"`
	Tid       int64   `json:"tid"`
	TradeType string  `json:"trade_type"`
	Type      string  `json:"type"`
}

type WSDepth added in v1.0.1

type WSDepth struct {
	Asks      [][]float64 `json:"asks"`
	DataType  string      `json:"dataType"`
	Bids      [][]float64 `json:"bids"`
	Channel   string      `json:"channel"`
	Timestamp int64       `json:"timestamp"`
}

type WSTicker added in v1.0.1

type WSTicker struct {
	Date     int64        `json:"date,string"` // (ms)
	Ticker   WSTickerData `json:"ticker"`
	DataType string       `json:"dataType"`
	Channel  string       `json:"channel"`
}

type WSTickerData added in v1.0.1

type WSTickerData struct {
	High float64 `json:"high,string"`
	Vol  float64 `json:"vol,string"`
	Last float64 `json:"last,string"`
	Low  float64 `json:"low,string"`
	Buy  float64 `json:"buy,string"`
	Sell float64 `json:"sell,string"`
}

type WSTrade added in v1.0.1

type WSTrade struct {
	Date      int64   `json:"date"`
	Amount    float64 `json:"amount,string"`
	Price     float64 `json:"price,string"`
	TradeType string  `json:"trade_type"`
	Type      string  `json:"type"`
	Tid       int64   `json:"tid"`
}

type WSTrades added in v1.0.1

type WSTrades struct {
	Data     []WSTrade `json:"data"`
	DataType string    `json:"dataType"`
	Channel  string    `json:"channel"`
}

type ZB

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

func NewZB

func NewZB(httpClient *http.Client, host string, accessKey string, secretKey string, debugMode bool) *ZB

domain: zb.live/zb.com

func (*ZB) AutoBorrow

func (z *ZB) AutoBorrow(marketName string, coin string, amount float64, interestRateOfDay float64, repaymentDay int, safePwd string) (result GeneralResult, err error)

AutoBorrow 自动借款 amount: 借入金额,小数位数不能超过4,超过系统自动截取前4位 interestRateOfDay: 日利率 [0.05-0.2] 百分比,小数位数不能超过3,超过系统自动截取前3位 repaymentDay: 借款期限 [10/20/30]天 safePwd: 资金安全密码

func (*ZB) Borrow

func (z *ZB) Borrow(marketName string, coin string, amount float64, interestRateOfDay float64, repaymentDay int, isLoop int) (result GeneralResult, err error)

Borrow 借款 amount: 借入金额,小数位数不能超过4,超过系统自动截取前4位 interestRateOfDay: 日利率 [0.05-0.2] 百分比,小数位数不能超过3,超过系统自动截取前3位 repaymentDay: 借款期限 [10/20/30]天 isLoop: 是否自动续借 1/0(到期自动续借/到期自动还款)

func (*ZB) CancelOrder

func (z *ZB) CancelOrder(symbol string, id int64, customOrderID string) (result OrderResponse, err error)

CancelOrder 取消委托

func (*ZB) DoAllRepay

func (z *ZB) DoAllRepay(marketName string) (result GeneralResult, err error)

DoAllRepay 一键还款 marketName: 杠杆市场,示例:btcqc

func (*ZB) DoTransferFunds

func (z *ZB) DoTransferFunds(amount float64, currency string, fromUserName string, toUserName string) (result GeneralResult, err error)

DoTransferFunds 主子账号内部转账 amount: 金额 currency: 币种 fromUserName: 转出方用户名 toUserName: 转入方用户名

func (*ZB) GetAccountInfo

func (z *ZB) GetAccountInfo() (result AccountInfo, err error)

GetAccountInfo 获取用户信息

func (*ZB) GetAllTicker

func (z *ZB) GetAllTicker() (tickers AllTicker, err error)

GetAllTicker 获取allTicker数据

func (*ZB) GetDepth

func (z *ZB) GetDepth(symbol string, size int) (depth Depth, err error)

GetDepth 获取市场深度 size: 1-50

func (*ZB) GetKLine

func (z *ZB) GetKLine(symbol string, _type string, since int64, size int) (kLine KLine, err error)

GetKLine 获取K线 symbol: btc_usdt _type: 1min/3min/5min/15min/30min/1day/3day/1week/1hour/2hour/4hour/6hour/12hour since: 从这个时间戳之后的 (ms) size: 返回数据的条数限制(默认为1000,如果返回数据多于1000条,那么只返回1000条)

func (*ZB) GetLeverAssetsInfo

func (z *ZB) GetLeverAssetsInfo() (result LeverAssetsInfo, err error)

GetLeverAssetsInfo 获取用户杠杆信息

func (*ZB) GetLoanRecords

func (z *ZB) GetLoanRecords(loanId string, marketName string, status int, pageIndex int, pageSize int) (result []LoanRecord, err error)

GetLoanRecords 获取借贷记录 loanId: 理财id(借出就传 借入不用传) marketName: btsqc status: 状态(1还款中 2已还款 3 需要平仓 4 平仓还款 5自动还款中 6自动还款)

func (*ZB) GetLoans

func (z *ZB) GetLoans(coin string, pageIndex int, pageSize int) (result []Loan, err error)

GetLoans 获取可借贷列表 coin: qc

func (*ZB) GetOrder

func (z *ZB) GetOrder(symbol string, id int64, customOrderID string) (result Order, err error)

GetOrder 获取委托单

func (*ZB) GetOrders

func (z *ZB) GetOrders(symbol string, tradeType int, pageIndex int) (result []Order, err error)

GetOrders 获取多个委托单

func (*ZB) GetOrdersIgnoreTradeType

func (z *ZB) GetOrdersIgnoreTradeType(symbol string, pageIndex int, pageSize int) (result []Order, err error)

GetOrdersIgnoreTradeType 获取委托单忽略类型

func (*ZB) GetRepayments

func (z *ZB) GetRepayments(loanRecordId string, pageIndex int, pageSize int) (result []Repayment, err error)

GetRepayments 获取还款记录 loanRecordId: 借贷记录id

func (*ZB) GetTicker

func (z *ZB) GetTicker(symbol string) (ticker Ticker, err error)

GetTicker 获取Ticker数据

func (*ZB) GetTrades

func (z *ZB) GetTrades(symbol string) (trades []Trade, err error)

GetTrades 获取历史成交 symbol: btc_usdt

func (*ZB) GetUnfinishedOrdersIgnoreTradeType

func (z *ZB) GetUnfinishedOrdersIgnoreTradeType(symbol string, pageIndex int, pageSize int) (result []Order, err error)

GetUnfinishedOrdersIgnoreTradeType 未成交或部份成交挂单

func (*ZB) HttpGet

func (z *ZB) HttpGet(reqUrl string, postData string, headers map[string]string, result interface{}) ([]byte, error)

func (*ZB) HttpPost

func (z *ZB) HttpPost(reqUrl string, postData string, headers map[string]string, result interface{}) ([]byte, error)

func (*ZB) NewHttpRequest

func (z *ZB) NewHttpRequest(method string, reqUrl string, postData string, requestHeaders map[string]string, result interface{}) ([]byte, error)

func (*ZB) PlaceOrder

func (z *ZB) PlaceOrder(symbol string, price float64, amount float64, tradeType int, acctType int, customOrderID string) (result OrderResponse, err error)

PlaceOrder 委托下单 tradeType: 交易类型1/0[buy/sell] acctType: 杠杆 1/0[杠杆/现货](选填,默认为: 0 现货)

func (*ZB) PlaceOrderMore

func (z *ZB) PlaceOrderMore(symbol string, tradeParams [][]float64, tradeType int, acctType int) (result OrderMoreV2Response, err error)

PlaceOrderMore 批量委托下单 交易参数,数组格式[[价格,数量],[价格,数量]],最多20个 tradeType: 交易类型1/0[buy/sell] acctType: 杠杆 1/0[杠杆/现货](选填,默认为: 0 现货)

func (*ZB) Repay

func (z *ZB) Repay(loanRecordId string, repayAmount float64, repayType int) (result GeneralResult, err error)

Repay 还款 loanRecordId: 借贷记录id repayAmount: 还款金额 repayType: 还款方式 0/1(全部/部分)

func (*ZB) SetProxy

func (z *ZB) SetProxy(proxyURL string) (err error)

SetProxy 设置代理 proxyURL: "socks5://127.0.0.1:1080"

type ZBWebsocket added in v1.0.1

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

func NewZBWebsocket added in v1.0.1

func NewZBWebsocket(host string, accessKey string, secretKey string, debugMode bool) *ZBWebsocket

NewZBWebsocket host: zb.live/zb.com

func (*ZBWebsocket) SetDepthCallback added in v1.0.1

func (ws *ZBWebsocket) SetDepthCallback(callback func(depth *WSDepth))

func (*ZBWebsocket) SetTickerCallback added in v1.0.1

func (ws *ZBWebsocket) SetTickerCallback(callback func(ticker *WSTicker))

func (*ZBWebsocket) SetTradesCallback added in v1.0.1

func (ws *ZBWebsocket) SetTradesCallback(callback func(trades *WSTrades))

func (*ZBWebsocket) Subscribe added in v1.0.1

func (ws *ZBWebsocket) Subscribe(event string, channel string) (err error)

func (*ZBWebsocket) SubscribeDepth added in v1.0.1

func (ws *ZBWebsocket) SubscribeDepth(symbol string) (err error)

func (*ZBWebsocket) SubscribeTicker added in v1.0.1

func (ws *ZBWebsocket) SubscribeTicker(symbol string) (err error)

func (*ZBWebsocket) SubscribeTrades added in v1.0.1

func (ws *ZBWebsocket) SubscribeTrades(symbol string) (err error)

Jump to

Keyboard shortcuts

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