rest

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2022 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	API_BASE = "https://api.blockchain.com/v3/exchange" // BCEX API endpoint
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIError

type APIError struct {
	Status  int
	Message string
}

APIError return the api error

func (APIError) Error

func (e APIError) Error() string

Error return the error message

type Balance

type Balance struct {
	Currency       string  `json:"currency"`
	Balance        float64 `json:"balance"`
	Available      float64 `json:"available"`
	BalanceLocal   float64 `json:"balance_local"`
	AvailableLocal float64 `json:"available_local"`
	Rate           float64 `json:"rate"`
}

type BalanceMap

type BalanceMap struct {
	Primary []Balance `json:"primary"`
}

type BaseOrder

type BaseOrder struct {
	// Reference field provided by client. Cannot exceed 20 characters, only alphanumeric characters are allowed.
	ClOrdId string  `json:"clOrdId"`
	OrdType OrdType `json:"ordType"`
	// Blockchain symbol identifier
	Symbol string `json:"symbol"`
	Side   Side   `json:"side"`
	// The order size in the terms of the base currency
	OrderQty    float64     `json:"orderQty"`
	TimeInForce TimeInForce `json:"timeInForce,omitempty"`
	// The limit price for the order
	Price float64 `json:"price,omitempty"`
	// expiry date in the format YYYYMMDD
	ExpireDate int32 `json:"expireDate,omitempty"`
	// The minimum quantity required for an IOC fill
	MinQty float64 `json:"minQty,omitempty"`
	// The limit price for the order
	StopPx float64 `json:"stopPx,omitempty"`
}

BaseOrder struct for BaseOrder

type Client

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

func NewClient

func NewClient(apiKey, apiSecret string) (c *Client)

NewClient return a new HTTP client

func NewClientWithCustomHttpConfig

func NewClientWithCustomHttpConfig(apiKey, apiSecret string, httpClient *http.Client) (c *Client)

NewClientWithCustomHttpConfig returns a new HTTP client using the predefined http client

func NewClientWithCustomTimeout

func NewClientWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) (c *Client)

NewClient returns a new HTTP client with custom timeout

func (*Client) CreateOrder

func (client *Client) CreateOrder(requestOrder BaseOrder) (order OrderSummary, err error)

CreateOrder Add an order

  • @param baseOrder Trade

@return OrderSummary

func (*Client) DeleteAllOrders

func (client *Client) DeleteAllOrders(options *DeleteAllOrdersOpts) (err error)

DeleteAllOrders Delete all open orders (of a symbol, if specified)

  • @param ctx _context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
  • @param optional nil or *DeleteAllOrdersOpts - Optional Parameters:
  • @param "Symbol" (optional.String) -

func (*Client) DeleteOrderById

func (client *Client) DeleteOrderById(orderId int64) error

DeleteOrderById cancel a specific order

  • @param orderId Order ID

@return OrderSummary

func (*Client) GetAllTicker

func (client *Client) GetAllTicker() (tickers Tickers, err error)

GetAllTicker is used to get the current ticker values for all markets.

func (*Client) GetBalances

func (client *Client) GetBalances() (balances BalanceMap, err error)

GetBalances is used to retrieve all balances from your account

func (*Client) GetFees

func (client *Client) GetFees() (fees Fees, err error)

GetFees is used to retrieve the fees from your account

func (*Client) GetFills

func (client *Client) GetFills(options *GetFillsOpts) (fills []OrderSummary, err error)

GetFills Get a list of filled orders Returns filled orders, including partial fills. Returns at most 100 results, use timestamp to paginate for further results

  • @param nil or *GetFillsOpts - Parameters:
  • @param "Symbol" (string) - Only return results for this symbol
  • @param "From" (int64) - Epoch timestamp in ms
  • @param "To" (optional.Int64) - Epoch timestamp in ms
  • @param "Limit" (optional.Int32) - Maximum amount of results to return in a single call. If omitted, 100 results are returned by default.

@return []OrderSummary

func (*Client) GetL2Orderbook

func (client *Client) GetL2Orderbook(market string) (orderbook OrderBook, err error)

GetL2Orderbook is used to get the current level 2 order book for a market.

func (*Client) GetL3Orderbook

func (client *Client) GetL3Orderbook(market string) (orderbook OrderBook, err error)

GetL3Orderbook is used to get the current level 2 order book for a market.

func (*Client) GetOrderById

func (client *Client) GetOrderById(orderId int64) (order OrderSummary, err error)

GetOrderById Get a specific order

  • @param orderId Order ID

@return OrderSummary

func (*Client) GetOrders

func (client *Client) GetOrders(options *GetOrdersOpts) (orders []OrderSummary, err error)

GetOrders Get a list orders Returns live and historic orders, defaulting to live orders. Returns at most 100 results, use timestamp to paginate for further results

  • @param nil or *GetOrdersOpts - Optional Parameters:
  • @param "Symbol" (string) - Only return results for this symbol
  • @param "From" (int64) - Epoch timestamp in ms
  • @param "To" (int64) - Epoch timestamp in ms
  • @param "Status" (interface of OrderStatus) - Order Status
  • @param "Limit" (int32) - Maximum amount of results to return in a single call. If omitted, 100 results are returned by default.

@return []OrderSummary

func (*Client) GetSymbol

func (client *Client) GetSymbol(market string) (symbol Symbol, err error)

GetSymbol is used to get the current symbol data for a market.

func (*Client) GetSymbols

func (client *Client) GetSymbols() (symbols []Symbol, err error)

GetSymbols is used to get the open and available trading markets along with other meta data.

func (*Client) GetTicker

func (client *Client) GetTicker(market string) (ticker Ticker, err error)

GetTicker is used to get the current ticker values for a market.

func (*Client) GetTrades

func (client *Client) GetTrades(options *GetTradesOpts) (trades []Trade, err error)

GetTrades used to retrieve your trade history. * @param nil or *GetTradesOpts - Optional Parameters: * @param "Symbol" (string) - Only return results for this symbol * @param "From" (int64) - Epoch timestamp in ms * @param "To" (int64) - Epoch timestamp in ms * @param "Limit" (int32) - Maximum amount of results to return in a single call. If omitted, 100 results are returned by default.

type DeleteAllOrdersOpts

type DeleteAllOrdersOpts struct {
	Symbol string
}

DeleteAllOrdersOpts Optional parameters for the method 'DeleteAllOrders'

type Fees

type Fees struct {
	MakerRate   float64 `json:"makerRate"`
	TakerRate   float64 `json:"takerRate"`
	VolumeInUSD float64 `json:"volumeInUSD"`
}

type GetFillsOpts

type GetFillsOpts struct {
	Symbol string
	From   int64
	To     int64
	Limit  int32
}

GetFillsOpts Optional parameters for the method 'GetFills'

type GetOrdersOpts

type GetOrdersOpts struct {
	Symbol string
	From   int64
	To     int64
	Status interface{}
	Limit  int32
}

GetOrdersOpts Optional parameters for the method 'GetOrders'

type GetTradesOpts

type GetTradesOpts struct {
	Symbol string
	From   int64
	To     int64
	Limit  int32
}

GetTradesOpts Optional parameters for the method 'GetTrades'

type OrdType

type OrdType string

OrdType the model 'OrdType'

const (
	MARKET    OrdType = "MARKET"
	LIMIT     OrdType = "LIMIT"
	STOP      OrdType = "STOP"
	STOPLIMIT OrdType = "STOPLIMIT"
)

List of ordType

type OrderBook

type OrderBook struct {
	// Blockchain symbol identifier
	Symbol string           `json:"symbol,omitempty"`
	Bids   []OrderBookEntry `json:"bids,omitempty"`
	Asks   []OrderBookEntry `json:"asks,omitempty"`
}

type OrderBookEntry

type OrderBookEntry struct {
	Px  float64 `json:"px,omitempty"`
	Qty float64 `json:"qty,omitempty"`
	// Either the quantity of orders on this price level for L2, or the individual order id for L3
	Num int64 `json:"num,omitempty"`
}

type OrderStatus

type OrderStatus string

OrderStatus the model 'OrderStatus'

const (
	OPEN        OrderStatus = "OPEN"
	REJECTED    OrderStatus = "REJECTED"
	CANCELED    OrderStatus = "CANCELED"
	FILLED      OrderStatus = "FILLED"
	PART_FILLED OrderStatus = "PART_FILLED"
	EXPIRED     OrderStatus = "EXPIRED"
)

List of OrderStatus

type OrderSummary

type OrderSummary struct {
	// The unique order id assigned by the exchange
	ExOrdId int64 `json:"exOrdId,omitempty"`
	// Reference field provided by client. Cannot exceed 20 characters, only alphanumeric characters are allowed.
	ClOrdId   string      `json:"clOrdId"`
	OrdType   OrdType     `json:"ordType"`
	OrdStatus OrderStatus `json:"ordStatus"`
	Side      Side        `json:"side"`
	// The limit price for the order
	Price float64 `json:"price,omitempty"`
	// The reason for rejecting the order, if applicable
	Text string `json:"text,omitempty"`
	// Blockchain symbol identifier
	Symbol string `json:"symbol"`
	// The executed quantity for the order's last fill
	LastShares float64 `json:"lastShares,omitempty"`
	// The executed price for the last fill
	LastPx float64 `json:"lastPx,omitempty"`
	// For Open and Partially Filled orders this is the remaining quantity open for execution. For Canceled and Expired orders this is the quantity than was still open before cancellation/expiration. For Rejected order this is equal to orderQty. For other states this is always zero.
	LeavesQty float64 `json:"leavesQty,omitempty"`
	// The quantity of the order which has been filled
	CumQty float64 `json:"cumQty,omitempty"`
	// Calculated the Volume Weighted Average Price of all fills for this order
	AvgPx float64 `json:"avgPx,omitempty"`
	// Time in ms since 01/01/1970 (epoch)
	Timestamp int64 `json:"timestamp,omitempty"`
}

OrderSummary struct for OrderSummary

type Side

type Side string

Side \"buy\" for Buy, \"sell\" for Sell

const (
	BUY  Side = "BUY"
	SELL Side = "SELL"
)

List of side

type Symbol

type Symbol struct {
	// Blockchain symbol identifier
	BaseCurrency string `json:"base_currency,omitempty"`
	// The number of decimals the currency can be split in
	BaseCurrencyScale int32 `json:"base_currency_scale,omitempty"`
	// Blockchain symbol identifier
	CounterCurrency string `json:"counter_currency,omitempty"`
	// The number of decimals the currency can be split in
	CounterCurrencyScale int32 `json:"counter_currency_scale,omitempty"`
	// The price of the instrument must be a multiple of min_price_increment * (10^-min_price_increment_scale)
	MinPriceIncrement      int64 `json:"min_price_increment,omitempty"`
	MinPriceIncrementScale int32 `json:"min_price_increment_scale,omitempty"`
	// The minimum quantity for an order for this instrument must be min_order_size*(10^-min_order_size_scale)
	MinOrderSize      int64 `json:"min_order_size,omitempty"`
	MinOrderSizeScale int32 `json:"min_order_size_scale,omitempty"`
	// The maximum quantity for an order for this instrument is max_order_size*(10^-max_order_size_scale). If this equal to zero, there is no limit
	MaxOrderSize      int64 `json:"max_order_size,omitempty"`
	MaxOrderSizeScale int32 `json:"max_order_size_scale,omitempty"`
	LotSize           int64 `json:"lot_size,omitempty"`
	LotSizeScale      int32 `json:"lot_size_scale,omitempty"`
	// Symbol status; open, close, suspend, halt, halt-freeze.
	Status string `json:"status,omitempty"`
	Id     int64  `json:"id,omitempty"`
	// If the symbol is halted and will open on an auction, this will be the opening price.
	AuctionPrice float64 `json:"auction_price,omitempty"`
	// Opening size
	AuctionSize float64 `json:"auction_size,omitempty"`
	// Opening time in HHMM format
	AuctionTime string `json:"auction_time,omitempty"`
	// Auction imbalance. If > 0 then there will be buy orders left over at the auction price. If < 0 then there will be sell orders left over at the auction price.
	Imbalance float64 `json:"imbalance,omitempty"`
}

Symbol represents data of a Currency Pair on a market.

type Ticker

type Ticker struct {
	Symbol         string  `json:"symbol,omitempty"`
	Price24h       float64 `json:"price_24h,omitempty"`
	Volume24h      float64 `json:"volume_24h,omitempty"`
	LastTradePrice float64 `json:"last_trade_price,omitempty"`
}

Ticker represents a Ticker from hitbtc API.

type Tickers

type Tickers []Ticker

Tickers rapresents a set of a valid Tickers struct

type TimeInForce

type TimeInForce string

TimeInForce \"GTC\" for Good Till Cancel, \"IOC\" for Immediate or Cancel, \"FOK\" for Fill or Kill, \"GTD\" Good Till Date

const (
	GTC TimeInForce = "GTC"
	IOC TimeInForce = "IOC"
	FOK TimeInForce = "FOK"
	GTD TimeInForce = "GTD"
)

List of TimeInForce

type Trade

type Trade struct {
	Id            uint64    `json:"id"`
	OrderId       uint64    `json:"orderId"`
	ClientOrderId string    `json:"clientOrderId"`
	Symbol        string    `json:"symbol"`
	Type          string    `json:"side"`
	Price         float64   `json:"price,string"`
	Quantity      float64   `json:"quantity,string"`
	Fee           float64   `json:"fee,string"`
	Timestamp     time.Time `json:"timestamp"`
}

Trade represents a single trade made by a user.

Jump to

Keyboard shortcuts

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