lbank

package
v0.9.4 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2022 License: MIT Imports: 35 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     time.Time `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(ctx context.Context, o *order.Cancel) (order.CancelAllResponse, error)

CancelAllOrders cancels all orders associated with a currency pair

func (*Lbank) CancelBatchOrders

func (l *Lbank) CancelBatchOrders(ctx context.Context, o []order.Cancel) (order.CancelBatchResponse, error)

CancelBatchOrders cancels an orders by their corresponding ID numbers

func (*Lbank) CancelOrder

func (l *Lbank) CancelOrder(ctx context.Context, o *order.Cancel) error

CancelOrder cancels an order by its corresponding ID number

func (*Lbank) CreateOrder

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

CreateOrder creates an order

func (*Lbank) FetchAccountInfo

func (l *Lbank) FetchAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error)

FetchAccountInfo retrieves balances for all enabled currencies

func (*Lbank) FetchOrderbook

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

FetchOrderbook returns orderbook base on the currency pair

func (*Lbank) FetchTicker

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

FetchTicker returns the ticker for a currency pair

func (*Lbank) FetchTradablePairs

func (l *Lbank) FetchTradablePairs(ctx context.Context, 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(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)

GetActiveOrders retrieves any orders that are active/open

func (*Lbank) GetCurrencyPairs

func (l *Lbank) GetCurrencyPairs(ctx context.Context) ([]string, error)

GetCurrencyPairs returns a list of supported currency pairs by the exchange

func (*Lbank) GetDefaultConfig

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

GetDefaultConfig returns a default exchange config

func (*Lbank) GetDepositAddress

func (l *Lbank) GetDepositAddress(_ context.Context, _ currency.Code, _, _ string) (*deposit.Address, error)

GetDepositAddress returns a deposit address for a specified currency

func (*Lbank) GetFeeByType

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

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

func (*Lbank) GetFundingHistory

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

GetFundingHistory returns funding history, deposits and withdrawals

func (*Lbank) GetHistoricCandles

func (l *Lbank) GetHistoricCandles(ctx context.Context, 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(ctx context.Context, 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) GetHistoricTrades

func (l *Lbank) GetHistoricTrades(ctx context.Context, p currency.Pair, assetType asset.Item, timestampStart, timestampEnd time.Time) ([]trade.Data, error)

GetHistoricTrades returns historic trade data within the timeframe provided

func (*Lbank) GetKlines

func (l *Lbank) GetKlines(ctx context.Context, symbol, size, klineType, tm string) ([]KlineResponse, error)

GetKlines returns kline data

func (*Lbank) GetMarketDepths

func (l *Lbank) GetMarketDepths(ctx context.Context, symbol, size, merge string) (MarketDepthResponse, error)

GetMarketDepths returns arrays of asks, bids and timestamp

func (*Lbank) GetOpenOrders

func (l *Lbank) GetOpenOrders(ctx context.Context, 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(ctx context.Context, getOrdersRequest *order.GetOrdersRequest) ([]order.Detail, error)

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

func (*Lbank) GetOrderInfo

func (l *Lbank) GetOrderInfo(ctx context.Context, orderID string, pair currency.Pair, assetType asset.Item) (order.Detail, error)

GetOrderInfo returns order information based on order ID

func (*Lbank) GetPairInfo

func (l *Lbank) GetPairInfo(ctx context.Context) ([]PairInfoResponse, error)

GetPairInfo finds information about all trading pairs

func (*Lbank) GetRecentTrades

func (l *Lbank) GetRecentTrades(ctx context.Context, p currency.Pair, assetType asset.Item) ([]trade.Data, error)

GetRecentTrades returns the most recent trades for a currency and asset

func (*Lbank) GetTicker

func (l *Lbank) GetTicker(ctx context.Context, symbol string) (TickerResponse, error)

GetTicker returns a ticker for the specified symbol symbol: eth_btc

func (*Lbank) GetTickers

func (l *Lbank) GetTickers(ctx context.Context) ([]TickerResponse, error)

GetTickers returns all tickers

func (*Lbank) GetTrades

func (l *Lbank) GetTrades(ctx context.Context, symbol string, limit, time int64) ([]TradeResponse, error)

GetTrades returns an array of available trades regarding a particular exchange

func (*Lbank) GetUserInfo

func (l *Lbank) GetUserInfo(ctx context.Context) (InfoFinalResponse, error)

GetUserInfo gets users account info

func (*Lbank) GetWithdrawConfig

func (l *Lbank) GetWithdrawConfig(ctx context.Context, assetCode string) ([]WithdrawConfigResponse, error)

GetWithdrawConfig gets information about withdrawals

func (*Lbank) GetWithdrawalRecords

func (l *Lbank) GetWithdrawalRecords(ctx context.Context, assetCode, status, pageNo, pageSize string) (WithdrawalResponse, error)

GetWithdrawalRecords gets withdrawal records

func (*Lbank) GetWithdrawalsHistory

func (l *Lbank) GetWithdrawalsHistory(ctx context.Context, c currency.Code) (resp []exchange.WithdrawalHistory, err error)

GetWithdrawalsHistory returns previous withdrawals data

func (*Lbank) ModifyOrder

func (l *Lbank) ModifyOrder(ctx context.Context, action *order.Modify) (order.Modify, error)

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

func (*Lbank) OrderTransactionDetails

func (l *Lbank) OrderTransactionDetails(ctx context.Context, symbol, orderID string) (TransactionHistoryResp, error)

OrderTransactionDetails gets info about transactions

func (*Lbank) QueryOrder

func (l *Lbank) QueryOrder(ctx context.Context, 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(ctx context.Context, 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(ctx context.Context, pair, orderID string) (RemoveOrderResponse, error)

RemoveOrder cancels a given order

func (*Lbank) RevokeWithdraw

func (l *Lbank) RevokeWithdraw(ctx context.Context, 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(ctx context.Context, method, endpoint string, vals url.Values, result interface{}) error

SendAuthHTTPRequest sends an authenticated request

func (*Lbank) SendHTTPRequest

func (l *Lbank) SendHTTPRequest(ctx context.Context, ep exchange.URL, 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.Exchange) error

Setup sets exchange configuration profile

func (*Lbank) Start

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

Start starts the Lbank go routine

func (*Lbank) SubmitOrder

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

SubmitOrder submits a new order

func (*Lbank) TransactionHistory

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

TransactionHistory stores info about transactions

func (*Lbank) USD2RMBRate

func (l *Lbank) USD2RMBRate(ctx context.Context) (ExchangeRateResponse, error)

USD2RMBRate finds USD-CNY Rate

func (*Lbank) UpdateAccountInfo

func (l *Lbank) UpdateAccountInfo(ctx context.Context, assetType asset.Item) (account.Holdings, error)

UpdateAccountInfo retrieves balances for all enabled currencies for the Lbank exchange

func (*Lbank) UpdateOrderbook

func (l *Lbank) UpdateOrderbook(ctx context.Context, 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(ctx context.Context, p currency.Pair, a asset.Item) (*ticker.Price, error)

UpdateTicker updates and returns the ticker for a currency pair

func (*Lbank) UpdateTickers

func (l *Lbank) UpdateTickers(ctx context.Context, a asset.Item) error

UpdateTickers updates the ticker for all currency pairs of a given asset type

func (*Lbank) UpdateTradablePairs

func (l *Lbank) UpdateTradablePairs(ctx context.Context, forceUpdate bool) error

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

func (*Lbank) ValidateCredentials

func (l *Lbank) ValidateCredentials(ctx context.Context, assetType asset.Item) error

ValidateCredentials validates current credentials used for wrapper functionality

func (*Lbank) Withdraw

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

Withdraw sends a withdrawal request

func (*Lbank) WithdrawCryptocurrencyFunds

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

WithdrawCryptocurrencyFunds returns a withdrawal ID when a withdrawal is submitted

func (*Lbank) WithdrawFiatFunds

func (l *Lbank) WithdrawFiatFunds(_ context.Context, _ *withdraw.Request) (*withdraw.ExchangeResponse, error)

WithdrawFiatFunds returns a withdrawal ID when a withdrawal is submitted

func (*Lbank) WithdrawFiatFundsToInternationalBank

func (l *Lbank) WithdrawFiatFundsToInternationalBank(_ context.Context, _ *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"`
	Data       struct {
		Asks      [][2]string `json:"asks"`
		Bids      [][2]string `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