lbank

package
v0.0.8 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2020 License: MIT Imports: 32 Imported by: 0

README

GoCryptoTrader package Lbank

Build Status Software License GoDoc Coverage Status Go Report Card

This lbank package is part of the GoCryptoTrader codebase.

This is still in active development

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

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

Lbank Exchange

Current Features
  • REST Support
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 l exchange.IBotExchange

for i := range Bot.Exchanges {
  if Bot.Exchanges[i].GetName() == "Lbank" {
    l = Bot.Exchanges[i]
  }
}

// Public calls - wrapper functions

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

// Fetches current orderbook information
ob, err := l.FetchOrderbook()
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 := l.GetAccountInfo()
if err != nil {
  // Handle error
}
  • If enabled via individually importing package, rudimentary example below:
// Public calls

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

// Fetches current orderbook information
ob, err := l.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 := l.GetUserInfo(...)
if err != nil {
  // Handle error
}

// Submits an order and the exchange and returns its tradeID
tradeID, err := l.Trade(...)
if err != nil {
  // Handle error
}
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:

bc1qk0jareu4jytc0cfrhr5wgshsq8282awpavfahc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorCapture

func ErrorCapture(code int64) error

ErrorCapture captures errors

Types

type CreateOrderResponse

type CreateOrderResponse struct {
	ErrCapture `json:",omitempty"`
	OrderID    string `json:"order_id"`
}

CreateOrderResponse stores the result of the Order and

type ErrCapture

type ErrCapture struct {
	Error  int64 `json:"error_code"`
	Result bool  `json:"result,string"`
}

ErrCapture helps with error info

type ExchangeRateResponse

type ExchangeRateResponse struct {
	USD2CNY string `json:"USD2CNY"`
}

ExchangeRateResponse stores information about USD-RMB rate

type GetAllOpenIDResp

type GetAllOpenIDResp struct {
	CurrencyPair string
	OrderID      string
}

GetAllOpenIDResp stores orderIds and currency pairs for open orders

type InfoFinalResponse

type InfoFinalResponse struct {
	ErrCapture `json:",omitempty"`
	Info       InfoResponse `json:"info"`
}

InfoFinalResponse stores info

type InfoResponse

type InfoResponse struct {
	Freeze map[string]string `json:"freeze"`
	Asset  map[string]string `json:"asset"`
	Free   map[string]string `json:"Free"`
}

InfoResponse stores info

type KlineResponse

type KlineResponse struct {
	TimeStamp     int64   `json:"timestamp"`
	OpenPrice     float64 `json:"openprice"`
	HigestPrice   float64 `json:"highestprice"`
	LowestPrice   float64 `json:"lowestprice"`
	ClosePrice    float64 `json:"closeprice"`
	TradingVolume float64 `json:"tradingvolume"`
}

KlineResponse stores kline info for given currency exchange

type Lbank

type Lbank struct {
	exchange.Base

	WebsocketConn *stream.WebsocketConnection
	// contains filtered or unexported fields
}

Lbank is the overarching type across this package

func (*Lbank) CancelAllOrders

func (l *Lbank) CancelAllOrders(orders *order.Cancel) (order.CancelAllResponse, error)

CancelAllOrders cancels all orders associated with a currency pair

func (*Lbank) CancelOrder

func (l *Lbank) CancelOrder(order *order.Cancel) error

CancelOrder cancels an order by its corresponding ID number

func (*Lbank) CreateOrder

func (l *Lbank) CreateOrder(pair, side string, amount, price float64) (CreateOrderResponse, error)

CreateOrder creates an order

func (*Lbank) FetchAccountInfo

func (l *Lbank) FetchAccountInfo() (account.Holdings, error)

FetchAccountInfo retrieves balances for all enabled currencies

func (*Lbank) FetchOrderbook

func (l *Lbank) FetchOrderbook(currency currency.Pair, assetType asset.Item) (*orderbook.Base, error)

FetchOrderbook returns orderbook base on the currency pair

func (*Lbank) FetchTicker

func (l *Lbank) FetchTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error)

FetchTicker returns the ticker for a currency pair

func (*Lbank) FetchTradablePairs

func (l *Lbank) FetchTradablePairs(asset asset.Item) ([]string, error)

FetchTradablePairs returns a list of the exchanges tradable pairs

func (*Lbank) FormatExchangeKlineInterval

func (l *Lbank) FormatExchangeKlineInterval(in kline.Interval) string

FormatExchangeKlineInterval returns Interval to exchange formatted string

func (*Lbank) GetActiveOrders

func (l *Lbank) GetActiveOrders(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)

GetActiveOrders retrieves any orders that are active/open

func (*Lbank) GetCurrencyPairs

func (l *Lbank) GetCurrencyPairs() ([]string, error)

GetCurrencyPairs returns a list of supported currency pairs by the exchange

func (*Lbank) GetDefaultConfig

func (l *Lbank) GetDefaultConfig() (*config.ExchangeConfig, error)

GetDefaultConfig returns a default exchange config

func (*Lbank) GetDepositAddress

func (l *Lbank) GetDepositAddress(cryptocurrency currency.Code, accountID string) (string, error)

GetDepositAddress returns a deposit address for a specified currency

func (*Lbank) GetExchangeHistory

func (l *Lbank) GetExchangeHistory(p currency.Pair, assetType asset.Item, timestampStart, timestampEnd time.Time) ([]exchange.TradeHistory, error)

GetExchangeHistory returns historic trade data within the timeframe provided.

func (*Lbank) GetFeeByType

func (l *Lbank) GetFeeByType(feeBuilder *exchange.FeeBuilder) (float64, error)

GetFeeByType returns an estimate of fee based on the type of transaction *

func (*Lbank) GetFundingHistory

func (l *Lbank) GetFundingHistory() ([]exchange.FundHistory, error)

GetFundingHistory returns funding history, deposits and withdrawals

func (*Lbank) GetHistoricCandles

func (l *Lbank) GetHistoricCandles(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)

GetHistoricCandles returns candles between a time period for a set time interval

func (*Lbank) GetHistoricCandlesExtended

func (l *Lbank) GetHistoricCandlesExtended(pair currency.Pair, a asset.Item, start, end time.Time, interval kline.Interval) (kline.Item, error)

GetHistoricCandlesExtended returns candles between a time period for a set time interval

func (*Lbank) GetKlines

func (l *Lbank) GetKlines(symbol, size, klineType, time string) ([]KlineResponse, error)

GetKlines returns kline data

func (*Lbank) GetMarketDepths

func (l *Lbank) GetMarketDepths(symbol, size, merge string) (MarketDepthResponse, error)

GetMarketDepths returns arrays of asks, bids and timestamp

func (*Lbank) GetOpenOrders

func (l *Lbank) GetOpenOrders(pair, pageNumber, pageLength string) (OpenOrderFinalResponse, error)

GetOpenOrders gets opening orders Lbank returns an empty string as their []OrderResponse instead of returning an empty array, so when len(tempResp.Orders) > 2 its not empty and should be unmarshalled separately

func (*Lbank) GetOrderHistory

func (l *Lbank) GetOrderHistory(getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)

GetOrderHistory retrieves account order information * Can Limit response to specific order status

func (*Lbank) GetOrderHistoryById

func (b *Lbank) GetOrderHistoryById(getOrdersRequest string) ([]order.Detail, error)

GetOrderHistoryById retrieves specified closed order information Can Limit response to specific order status

func (*Lbank) GetOrderInfo

func (l *Lbank) GetOrderInfo(orderID string) (order.Detail, error)

GetOrderInfo returns information on a current open order

func (*Lbank) GetPairInfo

func (l *Lbank) GetPairInfo() ([]PairInfoResponse, error)

GetPairInfo finds information about all trading pairs

func (*Lbank) GetTicker

func (l *Lbank) GetTicker(symbol string) (TickerResponse, error)

GetTicker returns a ticker for the specified symbol symbol: eth_btc

func (*Lbank) GetTickers

func (l *Lbank) GetTickers() ([]TickerResponse, error)

GetTickers returns all tickers

func (*Lbank) GetTrades

func (l *Lbank) GetTrades(symbol, size, time string) ([]TradeResponse, error)

GetTrades returns an array of available trades regarding a particular exchange

func (*Lbank) GetUserInfo

func (l *Lbank) GetUserInfo() (InfoFinalResponse, error)

GetUserInfo gets users account info

func (*Lbank) GetWithdrawConfig

func (l *Lbank) GetWithdrawConfig(assetCode string) ([]WithdrawConfigResponse, error)

GetWithdrawConfig gets information about withdrawals

func (*Lbank) GetWithdrawalRecords

func (l *Lbank) GetWithdrawalRecords(assetCode, status, pageNo, pageSize string) (WithdrawalResponse, error)

GetWithdrawalRecords gets withdrawal records

func (*Lbank) ModifyOrder

func (l *Lbank) ModifyOrder(action *order.Modify) (string, error)

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

func (*Lbank) OrderTransactionDetails

func (l *Lbank) OrderTransactionDetails(symbol, orderID string) (TransactionHistoryResp, error)

OrderTransactionDetails gets info about transactions

func (*Lbank) QueryOrder

func (l *Lbank) QueryOrder(pair, orderIDs string) (QueryOrderFinalResponse, error)

QueryOrder finds out information about orders (can pass up to 3 comma separated values to this) Lbank returns an empty string as their []OrderResponse instead of returning an empty array, so when len(tempResp.Orders) > 2 its not empty and should be unmarshalled separately

func (*Lbank) QueryOrderHistory

func (l *Lbank) QueryOrderHistory(pair, pageNumber, pageLength string) (OrderHistoryFinalResponse, error)

QueryOrderHistory finds order info in the past 2 days Lbank returns an empty string as their []OrderResponse instead of returning an empty array, so when len(tempResp.Orders) > 2 its not empty and should be unmarshalled separately

func (*Lbank) RemoveOrder

func (l *Lbank) RemoveOrder(pair, orderID string) (RemoveOrderResponse, error)

RemoveOrder cancels a given order

func (*Lbank) RevokeWithdraw

func (l *Lbank) RevokeWithdraw(withdrawID string) (RevokeWithdrawResponse, error)

RevokeWithdraw cancels the withdrawal given the withdrawalID

func (*Lbank) Run

func (l *Lbank) Run()

Run implements the Lbank wrapper

func (*Lbank) SendAuthHTTPRequest

func (l *Lbank) SendAuthHTTPRequest(method, endpoint string, vals url.Values, result interface{}) error

SendAuthHTTPRequest sends an authenticated request

func (*Lbank) SendHTTPRequest

func (l *Lbank) SendHTTPRequest(path string, result interface{}) error

SendHTTPRequest sends an unauthenticated HTTP request

func (*Lbank) SetDefaults

func (l *Lbank) SetDefaults()

SetDefaults sets the basic defaults for Lbank

func (*Lbank) Setup

func (l *Lbank) Setup(exch *config.ExchangeConfig) error

Setup sets exchange configuration profile

func (*Lbank) Start

func (l *Lbank) Start(wg *sync.WaitGroup)

Start starts the LakeBTC go routine

func (*Lbank) SubmitOrder

func (l *Lbank) SubmitOrder(s *order.Submit) (order.SubmitResponse, error)

SubmitOrder submits a new order

func (*Lbank) TransactionHistory

func (l *Lbank) TransactionHistory(symbol, transactionType, startDate, endDate, from, direct, size string) (TransactionHistoryResp, error)

TransactionHistory stores info about transactions

func (*Lbank) USD2RMBRate

func (l *Lbank) USD2RMBRate() (ExchangeRateResponse, error)

USD2RMBRate finds USD-CNY Rate

func (*Lbank) UpdateAccountInfo

func (l *Lbank) UpdateAccountInfo() (account.Holdings, error)

UpdateAccountInfo retrieves balances for all enabled currencies for the Lbank exchange

func (*Lbank) UpdateOrderbook

func (l *Lbank) UpdateOrderbook(p currency.Pair, assetType asset.Item) (*orderbook.Base, error)

UpdateOrderbook updates and returns the orderbook for a currency pair

func (*Lbank) UpdateTicker

func (l *Lbank) UpdateTicker(p currency.Pair, assetType asset.Item) (*ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*Lbank) UpdateTradablePairs

func (l *Lbank) UpdateTradablePairs(forceUpdate bool) error

UpdateTradablePairs updates the exchanges available pairs and stores them in the exchanges config

func (*Lbank) ValidateCredentials

func (l *Lbank) ValidateCredentials() error

ValidateCredentials validates current credentials used for wrapper functionality

func (*Lbank) Withdraw

func (l *Lbank) Withdraw(account, assetCode, amount, memo, mark, withdrawType string) (WithdrawResponse, error)

Withdraw sends a withdrawal request

func (*Lbank) WithdrawCryptocurrencyFunds

func (l *Lbank) WithdrawCryptocurrencyFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*Lbank) WithdrawFiatFunds

func (l *Lbank) WithdrawFiatFunds(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*Lbank) WithdrawFiatFundsToInternationalBank

func (l *Lbank) WithdrawFiatFundsToInternationalBank(withdrawRequest *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFundsToInternationalBank returns a withdrawal ID when a withdrawal is submitted

type ListDataResponse

type ListDataResponse struct {
	ErrCapture `json:",omitempty"`
	Amount     float64 `json:"amount"`
	AssetCode  string  `json:"assetCode"`
	Address    string  `json:"address"`
	Fee        float64 `json:"fee"`
	ID         int64   `json:"id"`
	Time       int64   `json:"time"`
	TXHash     string  `json:"txhash"`
	Status     string  `json:"status"`
}

ListDataResponse contains some of withdrawal data

type MarketDepthResponse

type MarketDepthResponse struct {
	ErrCapture `json:",omitempty"`
	Asks       [][]float64 `json:"asks"`
	Bids       [][]float64 `json:"bids"`
	Timestamp  int64       `json:"timestamp"`
}

MarketDepthResponse stores arrays for asks, bids and a timestamp for a currecy pair

type OpenOrderFinalResponse

type OpenOrderFinalResponse struct {
	ErrCapture
	PageLength uint8
	PageNumber uint8
	Total      string
	Orders     []OrderResponse
}

OpenOrderFinalResponse stores the unmarshalled value of OpenOrderResponse

type OpenOrderResponse

type OpenOrderResponse struct {
	ErrCapture `json:",omitempty"`
	PageLength uint8           `json:"page_length"`
	PageNumber uint8           `json:"page_number"`
	Total      string          `json:"total"`
	Orders     json.RawMessage `json:"orders"`
}

OpenOrderResponse stores information about the opening orders

type OrderHistory

type OrderHistory struct {
	Result      bool            `json:"result,string"`
	Total       string          `json:"total"`
	PageLength  uint8           `json:"page_length"`
	Orders      json.RawMessage `json:"orders"`
	CurrentPage uint8           `json:"current_page"`
	ErrorCode   int64           `json:"error_code"`
}

OrderHistory stores data for past orders

type OrderHistoryFinalResponse

type OrderHistoryFinalResponse struct {
	ErrCapture
	PageLength  uint8
	Orders      []OrderResponse
	CurrentPage uint8
}

OrderHistoryFinalResponse stores past orders

type OrderHistoryResponse

type OrderHistoryResponse struct {
	ErrCapture  `json:",omitempty"`
	PageLength  uint8           `json:"page_length"`
	Orders      json.RawMessage `json:"orders"`
	CurrentPage uint8           `json:"current_page"`
}

OrderHistoryResponse stores past orders

type OrderResponse

type OrderResponse struct {
	Symbol     string  `json:"symbol"`
	Amount     float64 `json:"amount"`
	CreateTime int64   `json:"created_time"`
	Price      float64 `json:"price"`
	AvgPrice   float64 `json:"avg_price"`
	Type       string  `json:"type"`
	OrderID    string  `json:"order_id"`
	DealAmount float64 `json:"deal_amount"`
	Status     int64   `json:"status"`
}

OrderResponse stores the data related to the given OrderIDs

type PairInfoResponse

type PairInfoResponse struct {
	MinimumQuantity  string `json:"minTranQua"`
	PriceAccuracy    string `json:"priceAccuracy"`
	QuantityAccuracy string `json:"quantityAccuracy"`
	Symbol           string `json:"symbol"`
}

PairInfoResponse stores information about trading pairs

type QueryOrderFinalResponse

type QueryOrderFinalResponse struct {
	ErrCapture
	Orders []OrderResponse
}

QueryOrderFinalResponse stores data from queries

type QueryOrderResponse

type QueryOrderResponse struct {
	ErrCapture `json:",omitempty"`
	Orders     json.RawMessage `json:"orders"`
}

QueryOrderResponse stores the data from queries

type RemoveOrderResponse

type RemoveOrderResponse struct {
	ErrCapture `json:",omitempty"`
	Err        string `json:"error"`
	OrderID    string `json:"order_id"`
	Success    string `json:"success"`
}

RemoveOrderResponse stores the result when an order is cancelled

type RevokeWithdrawResponse

type RevokeWithdrawResponse struct {
	ErrCapture `json:",omitempty"`
	WithdrawID string `json:"string"`
}

RevokeWithdrawResponse stores info about the revoked withdrawal

type Ticker

type Ticker struct {
	Change   float64 `json:"change"`
	High     float64 `json:"high"`
	Latest   float64 `json:"latest"`
	Low      float64 `json:"low"`
	Turnover float64 `json:"turnover"`
	Volume   float64 `json:"vol"`
}

Ticker stores the ticker price data for a currency pair

type TickerResponse

type TickerResponse struct {
	Symbol    currency.Pair `json:"symbol"`
	Timestamp int64         `json:"timestamp"`
	Ticker    Ticker        `json:"ticker"`
}

TickerResponse stores the ticker price data and timestamp for a currency pair

type TradeResponse

type TradeResponse struct {
	DateMS int64   `json:"date_ms"`
	Amount float64 `json:"amount"`
	Price  float64 `json:"price"`
	Type   string  `json:"type"`
	TID    string  `json:"tid"`
}

TradeResponse stores date_ms, amount, price, type, tid for a currency pair

type TransactionHistoryResp

type TransactionHistoryResp struct {
	ErrCapture  `json:",omitempty"`
	Transaction []TransactionTemp `json:"transaction"`
}

TransactionHistoryResp stores details about past transactions

type TransactionTemp

type TransactionTemp struct {
	TxUUID       string  `json:"txUuid"`
	OrderUUID    string  `json:"orderUuid"`
	TradeType    string  `json:"tradeType"`
	DealTime     int64   `json:"dealTime"`
	DealPrice    float64 `json:"dealPrice"`
	DealQuantity float64 `json:"dealQuantity"`
	DealVolPrice float64 `json:"dealVolumePrice"`
	TradeFee     float64 `json:"tradeFee"`
	TradeFeeRate float64 `json:"tradeFeeRate"`
}

TransactionTemp stores details about transactions

type WithdrawConfigResponse

type WithdrawConfigResponse struct {
	AssetCode   string `json:"assetCode"`
	Minimum     string `json:"min"`
	CanWithDraw bool   `json:"canWithDraw"`
	Fee         string `json:"fee"`
}

WithdrawConfigResponse stores info about withdrawal configurations

type WithdrawResponse

type WithdrawResponse struct {
	ErrCapture `json:",omitempty"`
	WithdrawID string  `json:"withdrawId"`
	Fee        float64 `json:"fee"`
}

WithdrawResponse stores info about the withdrawal

type WithdrawalResponse

type WithdrawalResponse struct {
	ErrCapture `json:",omitempty"`
	TotalPages int64              `json:"totalPages"`
	PageSize   int64              `json:"pageSize"`
	PageNo     int64              `json:"pageNo"`
	List       []ListDataResponse `json:"list"`
}

WithdrawalResponse stores data for withdrawals

Jump to

Keyboard shortcuts

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