bksdk

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const WS_HOST = "wss://api.bitkub.com/websocket-api/"
View Source
const WS_TICKER_STREAM = "market.ticker.%s"
View Source
const WS_TRADE_STREAM = "market.trade.%s"

Variables

This section is empty.

Functions

func CreateWsConnection added in v1.3.0

func CreateWsConnection(streamName string, reader chan string, ctx context.Context)

CreateWsConnection creates a websocket connection.

Parameters: - streamName: The name of the stream. - reader: A channel used to read messages from the websocket. - ctx: The context object for managing the connection's lifecycle.

func PrettyStruct

func PrettyStruct(data interface{}) (string, error)

PrettyStruct prints a pretty JSON representation of a struct. It takes in a `data` interface{} parameter and returns a string representation of the JSON. If there is an error during the marshaling process, it returns an empty string and the error.

Types

type SDK

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

func (*SDK) Balances added in v1.2.0

func (bksdk *SDK) Balances() (response.BalanceResult, error)

Balance returns the balances information, including both available and reserved balances.

Endpoint: /api/v3/market/balances Method: POST Parameter: N/A

func (*SDK) CancelOrder

func (bksdk *SDK) CancelOrder(sym, id, sd, hash string) (response.CancelOrder, error)

Endpoint: /api/v3/market/cancel-order Method: POST Desc: Cancel an open order Parameters: - sym string The symbol. Please note that the current endpoint requires the symbol thb_btc. However, it will be changed to btc_thb soon and you will need to update the configurations accordingly for uninterrupted API functionality. - id string Order id you wish to cancel - sd string Order side: buy or sell - hash string Cancel an order with order hash (optional). You don't need to specify sym, id, and sd when you specify order hash.

func (*SDK) CryptoAddresses added in v1.2.0

func (bksdk *SDK) CryptoAddresses(page, limit int) ([]response.CryptoAddressesResult, response.BKPaginate, error)

Addresses is a function that lists all crypto addresses. It sends a POST request to the /api/v3/crypto/addresses endpoint with optional pagination parameters (page and limit). It returns a response containing the crypto addresses and an error, if any.

func (*SDK) CryptoDepositHistory added in v1.2.0

func (bksdk *SDK) CryptoDepositHistory(page, limit int) ([]response.DepositHistoryResult, response.BKPaginate, error)

DepositHistory returns a list of crypto deposit history. It sends a POST request to the /api/v3/crypto/deposit-history endpoint. Parameters: - page: int, optional page number - limit: int, optional limit per page Returns: - response.DepositHistory: the deposit history response - error: any error that occurred during the request

func (*SDK) CryptoGenerateAddress added in v1.2.0

func (bksdk *SDK) CryptoGenerateAddress(symbol string) ([]response.CryptoGenerateAddressResult, error)

GenerateAddress generates a new crypto address for the given symbol. The previous address can still be used to receive funds. It makes a POST request to the /api/v3/crypto/generate-address endpoint.

Parameters: - symbol: The symbol for which to generate the address (e.g. THB_BTC, THB_ETH, etc.)

Returns: - response: The generated address and other relevant information. - error: An error if the request fails or if there is an issue parsing the response.

func (*SDK) CryptoInternalWithdraw added in v1.2.0

func (bksdk *SDK) CryptoInternalWithdraw(currency string, address string, memo string, amount float64) (response.InternalWithdrawResult, error)

InternalWithdraw makes a withdrawal to an internal address. The destination address does not need to be a trusted address. This API is not enabled by default. Only KYB users can request this feature by contacting us via support@bitkub.com.

func (*SDK) CryptoWithdraw added in v1.2.0

func (bksdk *SDK) CryptoWithdraw(currency string, address string, memo string, amount float64, network string) (response.CryptoWithdrawResult, error)

Withdraw makes a withdrawal to a trusted address. Endpoint: /api/v3/crypto/withdraw Method: POST Parameters:

  • currency: Currency for withdrawal (e.g. BTC, ETH)
  • amount: Amount you want to withdraw
  • address: Address to which you want to withdraw
  • memo: (Optional) Memo or destination tag to which you want to withdraw
  • network: Cryptocurrency network to withdraw No default value of this field. Please find the available network from the link as follows. https://www.bitkub.com/fee/cryptocurrency For example ETH refers to ERC-20. For request on ERC-20, please assign the network value as ETH. For request on BEP-20, please assign the network value as BSC. For request on KAP-20, please assign the network value as BKC.

Returns: - response: The response body with the withdrawal details - error: An error if the withdrawal request fails

func (*SDK) CryptoWithdrawHistory added in v1.2.0

func (bksdk *SDK) CryptoWithdrawHistory(page, limit int) ([]response.WithdrawHistoryResult, response.BKPaginate, error)

WithdrawHistory returns a list of crypto withdraw history. It sends a POST request to the /api/v3/crypto/withdraw-history endpoint. Parameters: - page: int, optional page number - limit: int, optional limit per page Returns: - response.WithdrawHistory: the withdraw history response - error: any error that occurred during the request

func (*SDK) FiatAccounts added in v1.2.0

func (bksdk *SDK) FiatAccounts(page int, limit int) ([]response.FiatAccountsResult, response.BKPaginate, error)

Accounts lists all approved bank accounts.

Parameters: - page: int, Page number (optional) - limit: int, Limit number of results (optional)

Returns: - response.FiatAccounts: List of approved bank accounts - error: Error if any occurs

func (*SDK) FiatDepositHistory added in v1.2.0

func (bksdk *SDK) FiatDepositHistory(page, limit int) ([]response.FiatDepositHistoryResult, response.BKPaginate, error)

Endpoint: /api/v3/fiat/deposit-history Method: POST Desc: List fiat deposit history Parameters: - p int Page (optional) - lmt int Limit (optional) Function: FiatDepositHistory retrieves the fiat deposit history using the specified page and limit. It returns a response object containing the deposit history and an error if any.

func (*SDK) FiatWithdraw added in v1.2.0

func (bksdk *SDK) FiatWithdraw(id string, amt float64) (response.FiatWithdrawResult, error)

FiatWithdraw makes a withdrawal to an approved bank account. It sends a POST request to the /api/v3/fiat/withdraw endpoint. Parameters: - id: string, the bank account id - amt: float64, the amount to withdraw Returns: - response.FiatWithdraw: the response body - error: any error that occurred during the request

func (*SDK) FiatWithdrawHistory added in v1.2.0

func (bksdk *SDK) FiatWithdrawHistory(page, limit int) ([]response.FiatWithdrawHistoryResult, response.BKPaginate, error)

FiatWithdrawHistory retrieves the list of fiat withdrawal history.

Parameters: - page: Page number (optional) - limit: Limit number (optional)

Returns: - response.FiatWithdrawHistory: The response body containing the fiat withdrawal history - error: Any error that occurred during the API request

func (*SDK) GetAsks

func (bksdk *SDK) GetAsks(sym string, limit int) (response.MarketResult, error)

GetAsks retrieves a list of open sell orders for a given symbol with a specified limit. It makes a GET request to the /api/market/asks endpoint. Returns the response body as a MarketAsks struct and any error encountered.

func (*SDK) GetBids

func (bksdk *SDK) GetBids(sym string, limit int) (response.MarketResult, error)

GetBids queries the /api/market/bids endpoint with the GET method and returns the response body containing the market bids.

Parameters: - sym: The symbol (e.g. thb_btc) - limit: The number of limit to query open buy orders

Returns: - response.MarketBids: The response body containing the market bids - error: An error if any occurred during the request or response handling

func (*SDK) GetBooks

func (bksdk *SDK) GetBooks(sym string, limit int) (response.MarketBooksResult, error)

GetBooks retrieves market books for a given symbol and limit Endpoint: /api/market/books Method: GET

Query Parameters:

sym string - The symbol (e.g. thb_btc)
lmt int - Number of limit to query open sell orders

func (*SDK) GetDepth

func (bksdk *SDK) GetDepth(sym string, limit int) (response.MarketDepth, error)

GetDepth queries the /api/market/books endpoint using the GET method to retrieve market depth information.

Parameters: - sym: The symbol (e.g. thb_btc) - limit: The number of orders to query

Returns: - response.MarketDepth: The market depth response - error: Any error that occurred during the request

func (*SDK) GetHistory

func (bksdk *SDK) GetHistory(symbol string, resolution string, from int, to int) (response.TradingviewHistory, error)

GetHistory retrieves trading view history for a given symbol

Endpoint: /tradingview/history Method: GET

Parameters: - symbol: string - The symbol (e.g. BTC_THB) - resolution: string - Chart resolution (1, 5, 15, 60, 240, 1D) - from: int - Timestamp of the starting time (e.g. 1633424427) - to: int - Timestamp of the ending time (e.g. 1633427427)

Returns: - response.TradingviewHistory: the trading view history - error: if there was an error retrieving the history

func (*SDK) GetServerTime

func (bksdk *SDK) GetServerTime() (string, error)

GetServerTime retrieves the server time from the API. Endpoint: /api/servertime Method: GET

func (*SDK) GetStatus

func (bksdk *SDK) GetStatus() (response.Status, error)

GetStatus retrieves the status from the API.

func (*SDK) GetSymbols

func (bksdk *SDK) GetSymbols() ([]response.MarketSymbolsResult, error)

GetSymbols retrieves the market symbols from the API. Endpoint: /api/market/symbols Method: GET

func (*SDK) GetTicker

func (bksdk *SDK) GetTicker(sym string) (map[string]response.MarketTickerData, error)

GetTicker retrieves the market ticker for a given symbol. It makes a GET request to the "/api/market/ticker" endpoint. If a symbol is provided, it is included as a query parameter. The response body is unmarshalled into a response.MarketTickerData struct. If the request is successful, the response body is returned along with nil error. If any error occurs during the request or unmarshalling, the response body is empty and the error is returned.

func (*SDK) GetTrade

func (bksdk *SDK) GetTrade(sym string, limit int) (response.MarketTradesResult, error)

GetTrade retrieves recent trades from the API. It makes a GET request to the /api/market/trades endpoint. Parameters: - sym: The symbol (e.g. thb_btc) - limit: No. of limit to query recent trades Returns: - response.MarketTrades: The response body containing the recent trades - error: An error if the request fails or if the response body cannot be parsed

func (*SDK) Limits

func (bksdk *SDK) Limits() (response.LimitsResult, error)

Limits checks deposit/withdraw limitations and usage.

func (*SDK) MyOpenOrder

func (bksdk *SDK) MyOpenOrder(sym string) ([]response.MyOpenOrderResult, error)

MyOpenOrder retrieves a list of all open orders for a given symbol. Endpoint: /api/v3/market/my-open-orders Method: GET Parameters: - sym string: The symbol (e.g. btc_thb) Returns: - response.MyOpenOrder: The response body containing the list of open orders - error: Any error that occurred during the API call

func (*SDK) MyOrderHistory

func (bksdk *SDK) MyOrderHistory(sym string, page, limit, start, end int) ([]response.MyOrderHistoryResult, response.BKPaginate, error)

MyOrderHistory retrieves a list of orders that have already matched.

Endpoint: /api/v3/market/my-order-history Method: GET

Parameters:

  • sym: string (required) - The symbol (e.g. btc_thb)
  • page: int (optional) - Page number
  • limit: int (optional) - Limit per page
  • start: int (optional) - Start timestamp
  • end: int (optional) - End timestamp

Returns:

  • response.MyOrderHistory: The response body containing the order history
  • error: An error if the request fails

func (*SDK) OrderInfo

func (bksdk *SDK) OrderInfo(sym, orderId, side string) (response.OrderInfoResult, error)

OrderInfo returns information regarding the specified order. It makes a GET request to the endpoint /api/v3/market/order-info. The function takes three parameters: - sym: the symbol of the order (e.g. btc_thb) - orderId: the ID of the order - side: the side of the order: buy or sell It returns an instance of response.OrderInfo and an error, if any.

func (*SDK) OrderInfoByHash

func (bksdk *SDK) OrderInfoByHash(hash string) (response.OrderInfoResult, error)

OrderInfoByHash retrieves information about the specified order. It sends a GET request to the /api/v3/market/order-info endpoint. The order is identified by its hash.

Parameters:

  • hash: The hash of the order to retrieve information about.

Returns:

  • response.OrderInfo: The information about the order.
  • error: An error if the request fails or if there is an issue with parsing the response.

func (*SDK) PlaceAsk

func (bksdk *SDK) PlaceAsk(sym string, amt, rat float64, typ, client_id string) (response.PlaceAskResult, error)

PlaceAsk creates a sell order. Endpoint: /api/v3/market/place-ask Method: POST Parameters: - sym: string - The symbol you want to trade (e.g. btc_thb). - amt: float64 - Amount you want to spend with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok). - rat: float64 - Rate you want for the order with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok). - typ: string - Order type: limit or market (for market order, please specify rat as 0). - client_id: string - Your id for reference (not required). It returns the response body and an error (if any).

func (*SDK) PlaceBid

func (bksdk *SDK) PlaceBid(sym string, amt, rat float64, typ, client_id string) (response.PlaceBidResult, error)

PlaceBid creates a buy order by sending a POST request to the /api/v3/market/place-bid endpoint. It takes the following parameters: - sym: string - The symbol you want to trade (e.g. btc_thb). - amt: float64 - Amount you want to spend with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok). - rat: float64 - Rate you want for the order with no trailing zero (e.g. 1000.00 is invalid, 1000 is ok). - typ: string - Order type: limit or market (for market order, please specify rat as 0). - client_id: string - Your id for reference (not required).

func (*SDK) TradingCredit

func (bksdk *SDK) TradingCredit() (float64, error)

TradingCredit retrieves the trading credit balance.

func (*SDK) Wallet

func (bksdk *SDK) Wallet() (response.WalletResult, error)

Wallet retrieves the user's available balances, including both available and reserved balances. It makes a POST request to the /api/v3/market/wallet endpoint. It returns the user's wallet information and any error that occurred during the API call.

func (*SDK) WsToken

func (bksdk *SDK) WsToken() (token string, err error)

WsToken retrieves the token for websocket authentication.

Endpoint: /api/v3/market/wstoken Method: POST Parameter: N/A

Returns: - response.WsToken: the response body containing the token. - error: if there was an error making the request or parsing the response.

type SDKEndpoints

type SDKEndpoints interface {
	// public endpoints
	GetStatus() (response.Status, error)
	GetServerTime() (string, error)
	GetSymbols() ([]response.MarketSymbolsResult, error)
	GetTicker(sym string) (map[string]response.MarketTickerData, error)
	GetTrade(sym string, limit int) (response.MarketTradesResult, error)
	GetBids(sym string, limit int) (response.MarketResult, error)
	GetAsks(sym string, limit int) (response.MarketResult, error)
	GetBooks(sym string, limit int) (response.MarketBooksResult, error)
	GetDepth(sym string, limit int) (response.MarketDepth, error)
	GetHistory(symbol string, resolution string, from int, to int) (response.TradingviewHistory, error)

	// User secure endpoints
	TradingCredit() (float64, error)
	Limits() (response.LimitsResult, error)

	// Market secure endpoints
	Wallet() (response.WalletResult, error)
	Balances() (response.BalanceResult, error)
	PlaceBid(sym string, amt, rat float64, typ, client_id string) (response.PlaceBidResult, error)
	PlaceAsk(sym string, amt, rat float64, typ, client_id string) (response.PlaceAskResult, error)
	CancelOrder(sym, id, sd, hash string) (response.CancelOrder, error)
	WsToken() (token string, err error)
	MyOpenOrder(sym string) ([]response.MyOpenOrderResult, error)
	MyOrderHistory(sym string, page, limit, start, end int) ([]response.MyOrderHistoryResult, response.BKPaginate, error)
	OrderInfo(sym, orderId, side string) (response.OrderInfoResult, error)
	OrderInfoByHash(hash string) (response.OrderInfoResult, error)

	// Crypto secure endpoints
	CryptoInternalWithdraw(currency string, address string, memo string, amount float64) (response.InternalWithdrawResult, error)
	CryptoAddresses(page, limit int) ([]response.CryptoAddressesResult, response.BKPaginate, error)
	CryptoWithdraw(currency string, address string, memo string, amount float64, network string) (response.CryptoWithdrawResult, error)
	CryptoDepositHistory(page, limit int) ([]response.DepositHistoryResult, response.BKPaginate, error)
	CryptoWithdrawHistory(page, limit int) ([]response.WithdrawHistoryResult, response.BKPaginate, error)
	CryptoGenerateAddress(symbol string) ([]response.CryptoGenerateAddressResult, error)

	// Fiat secure endpoints
	FiatAccounts(page int, limit int) ([]response.FiatAccountsResult, response.BKPaginate, error)
	FiatWithdraw(id string, amt float64) (response.FiatWithdrawResult, error)
	FiatDepositHistory(page, limit int) ([]response.FiatDepositHistoryResult, response.BKPaginate, error)
	FiatWithdrawHistory(page, limit int) ([]response.FiatWithdrawHistoryResult, response.BKPaginate, error)
}

func New

func New(apiKey, apiSecret string) SDKEndpoints

New creates a new SDK instance with the provided apiKey and apiSecret. It initializes the gorequest super agent and sets the API host URL.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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