zb

package
v0.0.0-...-a2c5123 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 16 Imported by: 0

README

GoCryptoTrader package Zb

Build Status Software License GoDoc Coverage Status Go Report Card

This zb package is part of the GoCryptoTrader codebase.

This is still in active development

You can track ideas, planned features and what's in progresss on this Trello board: https://trello.com/b/ZAhMhpOy/gocryptotrader.

Join our slack to discuss all things related to GoCryptoTrader! GoCryptoTrader Slack

ZB Exchange

Current Features
  • REST functions
How to enable
  // Exchanges will be abstracted out in further updates and examples will be
  // supplied then
How to do REST public/private calls
  • If enabled via "configuration".json file the exchange will be added to the IBotExchange array in the go var bot Bot and you will only be able to use the wrapper interface functions for accessing exchange data. View routines.go for an example of integration usage with GoCryptoTrader. Rudimentary example below:

main.go

var z exchange.IBotExchange

for i := range bot.exchanges {
  if bot.exchanges[i].GetName() == "ZB" {
    z = bot.exchanges[i]
  }
}

// Public calls - wrapper functions

// Fetches current ticker information
tick, err := z.GetTickerPrice()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := z.GetOrderbookEx()
if err != nil {
  // Handle error
}

// Private calls - wrapper functions - make sure your APIKEY and APISECRET are
// set and AuthenticatedAPISupport is set to true

// Fetches current account information
accountInfo, err := z.GetExchangeAccountInfo()
if err != nil {
  // Handle error
}
  • If enabled via individually importing package, rudimentary example below:
// Public calls

// Fetches current ticker information
ticker, err := z.GetTicker()
if err != nil {
  // Handle error
}

// Fetches current orderbook information
ob, err := z.GetOrderBook()
if err != nil {
  // Handle error
}

// Private calls - make sure your APIKEY and APISECRET are set and
// AuthenticatedAPISupport is set to true

// GetUserInfo returns account info
accountInfo, err := z.GetUserInfo(...)
if err != nil {
  // Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := z.Trade(...)
if err != nil {
  // Handle error
}
How to do LongPolling public/private calls
  // Exchanges will be abstracted out in further updates and examples will be
  // supplied then
Please click GoDocs chevron above to view current GoDoc information for this package

Contribution

Please feel free to submit any pull requests or suggest any desired features to be added.

When submitting a PR, please abide by our coding guidelines:

  • Code must adhere to the official Go formatting guidelines (i.e. uses gofmt).
  • Code must be documented adhering to the official Go commentary guidelines.
  • Code must adhere to our coding style.
  • Pull requests need to be based on and opened against the master branch.

Donations

If this framework helped you in any way, or you would like to support the developers working on it, please donate Bitcoin to:

1F5zVDgNjorJ51oGebSvNCrSAHpwGkUdDB

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SpotNewOrderRequestParamsTypeBuy 买
	SpotNewOrderRequestParamsTypeBuy = SpotNewOrderRequestParamsType("1")
	// SpotNewOrderRequestParamsTypeSell 卖
	SpotNewOrderRequestParamsTypeSell = SpotNewOrderRequestParamsType("0")
)
View Source
var (
	TimeIntervalMinute         = TimeInterval("1min")
	TimeIntervalThreeMinutes   = TimeInterval("3min")
	TimeIntervalFiveMinutes    = TimeInterval("5min")
	TimeIntervalFifteenMinutes = TimeInterval("15min")
	TimeIntervalThirtyMinutes  = TimeInterval("30min")
	TimeIntervalHour           = TimeInterval("1hour")
	TimeIntervalTwoHours       = TimeInterval("2hour")
	TimeIntervalFourHours      = TimeInterval("4hour")
	TimeIntervalSixHours       = TimeInterval("6hour")
	TimeIntervalTwelveHours    = TimeInterval("12hour")
	TimeIntervalDay            = TimeInterval("1day")
	TimeIntervalThreeDays      = TimeInterval("3day")
	TimeIntervalWeek           = TimeInterval("1week")
)

TimeInterval vars

Functions

This section is empty.

Types

type AccountsBaseResponse

type AccountsBaseResponse struct {
	UserName             string `json:"username"`               //用户名
	TradePasswordEnabled bool   `json:"trade_password_enabled"` //是否开通交易密码
	AuthGoogleEnabled    bool   `json:"auth_google_enabled"`    //是否开通谷歌验证
	AuthMobileEnabled    bool   `json:"auth_mobile_enabled"`    //是否开通手机验证
}

AccountsBaseResponse holds basic account details

type AccountsResponse

type AccountsResponse struct {
	Result struct {
		Coins []AccountsResponseCoin `json:"coins"`
		Base  AccountsBaseResponse   `json:"base"`
	} `json:"result"` //用户名
	AssetPerm   bool `json:"assetPerm"`   //是否开通交易密码
	LeverPerm   bool `json:"leverPerm"`   //是否开通谷歌验证
	EntrustPerm bool `json:"entrustPerm"` //是否开通手机验证
	MoneyPerm   bool `json:"moneyPerm"`   // 资产列表
}

AccountsResponse 用户基本信息

type AccountsResponseCoin

type AccountsResponseCoin struct {
	Freez       string `json:"freez"`       //冻结资产
	EnName      string `json:"enName"`      //币种英文名
	UnitDecimal int    `json:"unitDecimal"` //保留小数位
	UnName      string `json:"cnName"`      //币种中文名
	UnitTag     string `json:"unitTag"`     //币种符号
	Available   string `json:"available"`   //可用资产
	Key         string `json:"key"`         //币种
}

AccountsResponseCoin holds the accounts coin details

type KLineResponse

type KLineResponse struct {
	// Data      string                `json:"data"`      // 买入货币
	MoneyType string               `json:"moneyType"` // 卖出货币
	Symbol    string               `json:"symbol"`    // 内容说明
	Data      []*KLineResponseData `json:"data"`      // KLine数据
}

KLineResponse K线返回类型

type KLineResponseData

type KLineResponseData struct {
	ID        float64   `json:"id"` // K线ID
	KlineTime time.Time `json:"klineTime"`
	Open      float64   `json:"open"`  // 开盘价
	Close     float64   `json:"close"` // 收盘价, 当K线为最晚的一根时, 时最新成交价
	Low       float64   `json:"low"`   // 最低价
	High      float64   `json:"high"`  // 最高价
	Volume    float64   `json:"vol"`   // 成交量
}

KLineResponseData Kline Data

type KlinesRequestParams

type KlinesRequestParams struct {
	Symbol string       //交易对, zb_qc,zb_usdt,zb_btc...
	Type   TimeInterval //K线类型, 1min, 3min, 15min, 30min, 1hour......
	Since  string       //从这个时间戳之后的
	Size   int          //返回数据的条数限制(默认为1000,如果返回数据多于1000条,那么只返回1000条)
}

KlinesRequestParams represents Klines request data.

type MarketResponseItem

type MarketResponseItem struct {
	AmountScale float64 `json:"amountScale"`
	PriceScale  float64 `json:"priceScale"`
}

MarketResponseItem stores market data

type OrderbookResponse

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

OrderbookResponse holds the orderbook data for a symbol

type SpotNewOrderRequestParams

type SpotNewOrderRequestParams struct {
	Amount float64                       `json:"amount"`    // 交易数量
	Price  float64                       `json:"price"`     // 下单价格,
	Symbol string                        `json:"currency"`  // 交易对, btcusdt, bccbtc......
	Type   SpotNewOrderRequestParamsType `json:"tradeType"` // 订单类型, buy-market: 市价买, sell-market: 市价卖, buy-limit: 限价买, sell-limit: 限价卖
}

SpotNewOrderRequestParams is the params used for placing an order

type SpotNewOrderRequestParamsType

type SpotNewOrderRequestParamsType string

SpotNewOrderRequestParamsType ZB 交易类型

type SpotNewOrderResponse

type SpotNewOrderResponse struct {
	Code    int    `json:"code"`    //返回代码
	Message string `json:"message"` //提示信息
	ID      string `json:"id"`      //委托挂单号
}

SpotNewOrderResponse stores the new order response data

type TickerChildResponse

type TickerChildResponse struct {
	Vol  float64 `json:"vol,string"`  //成交量(最近的24小时)
	Last float64 `json:"last,string"` //最新成交价
	Sell float64 `json:"sell,string"` //卖一价
	Buy  float64 `json:"buy,string"`  //买一价
	High float64 `json:"high,string"` //最高价
	Low  float64 `json:"low,string"`  //最低价
}

TickerChildResponse holds the ticker child response data

type TickerResponse

type TickerResponse struct {
	Date   string              `json:"date"`
	Ticker TickerChildResponse `json:"ticker"`
}

TickerResponse holds the ticker response data

type TimeInterval

type TimeInterval string

TimeInterval represents interval enum.

type ZB

type ZB struct {
	exchange.Base
}

ZB is the overarching type across this package 47.91.169.147 api.zb.com 47.52.55.212 trade.zb.com

func (*ZB) CancelAllExchangeOrders

func (z *ZB) CancelAllExchangeOrders() error

CancelAllExchangeOrders cancels all orders associated with a currency pair

func (*ZB) CancelExchangeOrder

func (z *ZB) CancelExchangeOrder(orderID int64) error

CancelExchangeOrder cancels an order by its corresponding ID number

func (*ZB) CancelOrder

func (z *ZB) CancelOrder(orderID int64, symbol string) error

CancelOrder cancels an order on Huobi

func (*ZB) GetAccountInfo

func (z *ZB) GetAccountInfo() (AccountsResponse, error)

GetAccountInfo returns account information including coin information and pricing

func (*ZB) GetExchangeAccountInfo

func (z *ZB) GetExchangeAccountInfo() (exchange.AccountInfo, error)

GetExchangeAccountInfo retrieves balances for all enabled currencies for the ZB exchange

func (*ZB) GetExchangeDepositAddress

func (z *ZB) GetExchangeDepositAddress(cryptocurrency pair.CurrencyItem) (string, error)

GetExchangeDepositAddress returns a deposit address for a specified currency

func (*ZB) GetExchangeFundTransferHistory

func (z *ZB) GetExchangeFundTransferHistory() ([]exchange.FundHistory, error)

GetExchangeFundTransferHistory returns funding history, deposits and withdrawals

func (*ZB) GetExchangeHistory

func (z *ZB) GetExchangeHistory(p pair.CurrencyPair, assetType string) ([]exchange.TradeHistory, error)

GetExchangeHistory returns historic trade data since exchange opening.

func (*ZB) GetExchangeOrderInfo

func (z *ZB) GetExchangeOrderInfo(orderID int64) (exchange.OrderDetail, error)

GetExchangeOrderInfo returns information on a current open order

func (*ZB) GetLatestSpotPrice

func (z *ZB) GetLatestSpotPrice(symbol string) (float64, error)

GetLatestSpotPrice returns latest spot price of symbol

symbol: string of currency pair 获取最新价格

func (*ZB) GetMarkets

func (z *ZB) GetMarkets() (map[string]MarketResponseItem, error)

GetMarkets returns market information including pricing, symbols and each symbols decimal precision

func (*ZB) GetOrderbook

func (z *ZB) GetOrderbook(symbol string) (OrderbookResponse, error)

GetOrderbook returns the orderbook for a given symbol

func (*ZB) GetOrderbookEx

func (z *ZB) GetOrderbookEx(currency pair.CurrencyPair, assetType string) (orderbook.Base, error)

GetOrderbookEx returns orderbook base on the currency pair

func (*ZB) GetSpotKline

func (z *ZB) GetSpotKline(arg KlinesRequestParams) (KLineResponse, error)

GetSpotKline returns Kline data

func (*ZB) GetTicker

func (z *ZB) GetTicker(symbol string) (TickerResponse, error)

GetTicker returns a ticker for a given symbol

func (*ZB) GetTickerPrice

func (z *ZB) GetTickerPrice(p pair.CurrencyPair, assetType string) (ticker.Price, error)

GetTickerPrice returns the ticker for a currency pair

func (*ZB) GetTickers

func (z *ZB) GetTickers() (map[string]TickerChildResponse, error)

GetTickers returns ticker data for all supported symbols

func (*ZB) ModifyExchangeOrder

func (z *ZB) ModifyExchangeOrder(orderID int64, action exchange.ModifyOrder) (int64, error)

ModifyExchangeOrder will allow of changing orderbook placement and limit to market conversion

func (*ZB) Run

func (z *ZB) Run()

Run implements the OKEX wrapper

func (*ZB) SendAuthenticatedHTTPRequest

func (z *ZB) SendAuthenticatedHTTPRequest(method, endpoint string, values url.Values, result interface{}) error

SendAuthenticatedHTTPRequest sends authenticated requests to the zb API

func (*ZB) SendHTTPRequest

func (z *ZB) SendHTTPRequest(path string, result interface{}) error

SendHTTPRequest sends an unauthenticated HTTP request

func (*ZB) SetDefaults

func (z *ZB) SetDefaults()

SetDefaults sets default values for the exchange

func (*ZB) Setup

func (z *ZB) Setup(exch config.ExchangeConfig)

Setup sets user configuration

func (*ZB) SpotNewOrder

func (z *ZB) SpotNewOrder(arg SpotNewOrderRequestParams) (int64, error)

SpotNewOrder submits an order to ZB

func (*ZB) Start

func (z *ZB) Start(wg *sync.WaitGroup)

Start starts the OKEX go routine

func (*ZB) SubmitExchangeOrder

func (z *ZB) SubmitExchangeOrder(p pair.CurrencyPair, side exchange.OrderSide, orderType exchange.OrderType, amount, price float64, clientID string) (int64, error)

SubmitExchangeOrder submits a new order

func (*ZB) UpdateOrderbook

func (z *ZB) UpdateOrderbook(p pair.CurrencyPair, assetType string) (orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*ZB) UpdateTicker

func (z *ZB) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*ZB) WithdrawCryptoExchangeFunds

func (z *ZB) WithdrawCryptoExchangeFunds(address string, cryptocurrency pair.CurrencyItem, amount float64) (string, error)

WithdrawCryptoExchangeFunds returns a withdrawal ID when a withdrawal is submitted

func (*ZB) WithdrawFiatExchangeFunds

func (z *ZB) WithdrawFiatExchangeFunds(currency pair.CurrencyItem, amount float64) (string, error)

WithdrawFiatExchangeFunds returns a withdrawal ID when a withdrawal is submitted

func (*ZB) WithdrawFiatExchangeFundsToInternationalBank

func (z *ZB) WithdrawFiatExchangeFundsToInternationalBank(currency pair.CurrencyItem, amount float64) (string, error)

WithdrawFiatExchangeFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted

Jump to

Keyboard shortcuts

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