Documentation
¶
Index ¶
- Constants
- func New(apiKey string, secretKey string, opts ...ClientOption) (*client, error)
- type Account
- type AccountSummaryResponse
- type AccountSummaryResult
- type BookResponse
- type BookResult
- type CancelAllOrdersResponse
- type CancelOrderResponse
- type ClientOption
- type CommonAPI
- type CreateOrderRequest
- type CreateOrderResponse
- type CreateOrderResult
- type CryptoDotComExchange
- type DerivativesTransferAPI
- type Environment
- type ExecInst
- type GetOpenOrdersRequest
- type GetOpenOrdersResponse
- type GetOpenOrdersResult
- type GetOrderDetailResponse
- type GetOrderDetailResult
- type GetOrderHistoryRequest
- type GetOrderHistoryResponse
- type GetOrderHistoryResult
- type GetTradesRequest
- type GetTradesResponse
- type GetTradesResult
- type Instrument
- type InstrumentResult
- type InstrumentsResponse
- type LiquidityIndicator
- type MarginTradingAPI
- type Order
- type OrderSide
- type OrderStatus
- type OrderType
- type SingleTickerResponse
- type SingleTickerResult
- type SpotTradingAPI
- type SubAccountAPI
- type Ticker
- type TickerResponse
- type TickerResult
- type TimeInForce
- type Trade
- type Websocket
Constants ¶
const ( OrderSideBuy OrderSide = "BUY" OrderSideSell OrderSide = "SELL" OrderTypeLimit OrderType = "LIMIT" OrderTypeMarket OrderType = "MARKET" OrderTypeStopLoss OrderType = "STOP_LOSS" OrderTypeStopLimit OrderType = "STOP_LIMIT" OrderTypeTakeProfit OrderType = "TAKE_PROFIT" OrderTypeTakeProfitLimit OrderType = "TAKE_PROFIT_LIMIT" TimeInForceGoodTilCancelled TimeInForce = "GOOD_TILL_CANCEL" TimeInForceFillOrKill TimeInForce = "FILL_OR_KILL" TimeInForceImmediateOrCancel TimeInForce = "IMMEDIATE_OR_CANCEL" ExecInstPostOnly ExecInst = "POST_ONLY" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Account ¶
type Account struct { // Balance is the total balance (Available + Order + Stake). Balance float64 `json:"balance"` // Available is the available balance (e.g. not in orders, or locked, etc.). Available float64 `json:"available"` // Order is the balance locked in orders. Order float64 `json:"order"` // Stake is the balance locked for staking (typically only used for CRO). Stake float64 `json:"stake"` // Currency is the symbol for the currency (e.g. CRO). Currency string `json:"currency"` }
Account represents balance details of a specific token.
type AccountSummaryResponse ¶
type AccountSummaryResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result AccountSummaryResult `json:"result"` }
AccountSummaryResponse is the base response returned from the private/get-account-summary API.
type AccountSummaryResult ¶
type AccountSummaryResult struct { // Accounts is the returned account data. Accounts []Account `json:"accounts"` }
AccountSummaryResult is the result returned from the private/get-account-summary API.
type BookResponse ¶ added in v0.2.0
type BookResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result BookResult `json:"result"` }
BookResponse is the base response returned from the public/get-book API when no instrument is specified.
type BookResult ¶ added in v0.2.0
type BookResult struct { // Bids is an array of bids. // [0] = Price, [1] = Quantity, [2] = Number of Orders. Bids [][]float64 `json:"bids"` // Asks is an array of asks. // [0] = Price, [1] = Quantity, [2] = Number of Orders. Asks [][]float64 `json:"asks"` // Timestamp is the timestamp of the data. Timestamp time.Time `json:"t"` }
BookResult is the result returned from the public/get-book API.
type CancelAllOrdersResponse ¶
type CancelAllOrdersResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse }
CancelAllOrdersResponse is the base response returned from the private/cancel-all-orders API.
type CancelOrderResponse ¶
type CancelOrderResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse }
CancelOrderResponse is the base response returned from the private/cancel-order API.
type ClientOption ¶
type ClientOption func(*client) error
ClientOption represents optional configurations for the client.
func WithHTTPClient ¶
func WithHTTPClient(httpClient *http.Client) ClientOption
WithHTTPClient will allow the client to be initialised with a custom http client. Can be used to create custom timeouts, enable tracing, etc.
func WithProductionEnvironment ¶
func WithProductionEnvironment() ClientOption
WithProductionEnvironment will initialise the client to make requests against the production environment. This is the default setting.
func WithUATEnvironment ¶
func WithUATEnvironment() ClientOption
WithUATEnvironment will initialise the client to make requests against the UAT sandbox environment.
type CommonAPI ¶
type CommonAPI interface { // GetInstruments provides information on all supported instruments (e.g. BTC_USDT). // // Method: public/get-instruments GetInstruments(ctx context.Context) ([]Instrument, error) // GetBook fetches the public order book for a particular instrument and depth. // // Method: public/get-book GetBook(ctx context.Context, instrument string, depth int) (*BookResult, error) // GetTickers fetches the public tickers for an instrument (e.g. BTC_USDT). // // instrument can be left blank to retrieve tickers for ALL instruments. // // Method: public/get-ticker GetTickers(ctx context.Context, instrument string) ([]Ticker, error) }
CommonAPI is a Crypto.com Exchange client for Common API.
type CreateOrderRequest ¶
type CreateOrderRequest struct { // InstrumentName represents the currency pair to trade (e.g. ETH_CRO or BTC_USDT). InstrumentName string `json:"instrument_name"` // Side represents whether the order is buy or sell. Side OrderSide `json:"side"` // Type represents the type of order. Type OrderType `json:"type"` // Price determines the price of which the trade should be executed. // For LIMIT and STOP_LIMIT orders only. Price float64 `json:"price"` // Quantity is the quantity to be sold // For LIMIT, MARKET, STOP_LOSS, TAKE_PROFIT orders only. Quantity float64 `json:"quantity"` // Notional is the amount to spend. // For MARKET (BUY), STOP_LOSS (BUY), TAKE_PROFIT (BUY) orders only. Notional float64 `json:"notional"` // ClientOID is the optional Client order ID. ClientOID string `json:"client_oid"` // TimeInForce represents how long the order should be active before being cancelled. // (Limit Orders Only) Options are: // - GOOD_TILL_CANCEL (Default if unspecified) // - FILL_OR_KILL // - IMMEDIATE_OR_CANCEL TimeInForce TimeInForce `json:"time_in_force"` // (Limit Orders Only) Options are: // - POST_ONLY // - Or leave empty ExecInst ExecInst `json:"exec_inst"` // TriggerPrice is the price at which the order is triggered. // Used with STOP_LOSS, STOP_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders. TriggerPrice float64 `json:"trigger_price"` }
CreateOrderRequest is the request params sent for the private/create-order API. Mandatory parameters based on order type: ------------------+------+----------------------------------------- Type | Side | Additional Mandatory Parameters ------------------+------+----------------------------------------- LIMIT | Both | quantity, price MARKET | BUY | notional or quantity, mutually exclusive MARKET | SELL | quantity STOP_LIMIT | Both | price, quantity, trigger_price TAKE_PROFIT_LIMIT | Both | price, quantity, trigger_price STOP_LOSS | BUY | notional, trigger_price STOP_LOSS | SELL | quantity, trigger_price TAKE_PROFIT | BUY | notional, trigger_price TAKE_PROFIT | SELL | quantity, trigger_price ------------------+------+-----------------------------------------
type CreateOrderResponse ¶
type CreateOrderResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result CreateOrderResult `json:"result"` }
CreateOrderResponse is the base response returned from the private/create-order API.
type CreateOrderResult ¶
type CreateOrderResult struct { // OrderID is the newly created order ID. OrderID string `json:"order_id"` // ClientOID is the optional Client order ID (if provided in request). ClientOID string `json:"client_oid"` }
CreateOrderResult is the result returned from the private/create-order API.
type CryptoDotComExchange ¶
type CryptoDotComExchange interface { // UpdateConfig can be used to update the configuration of the client object. // (e.g. change api key, secret key, environment, etc). UpdateConfig(apiKey string, secretKey string, opts ...ClientOption) error CommonAPI SpotTradingAPI MarginTradingAPI DerivativesTransferAPI SubAccountAPI Websocket }
CryptoDotComExchange is a Crypto.com Exchange client for all available APIs.
type DerivativesTransferAPI ¶
type DerivativesTransferAPI interface { }
DerivativesTransferAPI is a Crypto.com Exchange client for Derivatives Transfer API.
type Environment ¶
type Environment string
Environment represents the environment against which calls are made.
const ( EnvironmentUATSandbox Environment = "uat_sandbox" EnvironmentProduction Environment = "production" )
type GetOpenOrdersRequest ¶
type GetOpenOrdersRequest struct { // InstrumentName represents the currency pair for the orders (e.g. ETH_CRO or BTC_USDT). // if InstrumentName is omitted, all instruments will be returned. InstrumentName string `json:"instrument_name"` // PageSize represents maximum number of orders returned (for pagination) // (Default: 20, Max: 200) // if PageSize is 0, it will be set as 20 by default. PageSize int `json:"page_size"` // Page represents the page number (for pagination) // (0-based) Page int `json:"page"` }
GetOpenOrdersRequest is the request params sent for the private/get-open-orders API.
type GetOpenOrdersResponse ¶
type GetOpenOrdersResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result GetOpenOrdersResult `json:"result"` }
GetOpenOrdersResponse is the base response returned from the private/get-open-orders API.
type GetOpenOrdersResult ¶
type GetOpenOrdersResult struct { // Count is the total count of orders. Count int `json:"order_id"` // OrderList is the array of open orders. OrderList []Order `json:"order_list"` }
GetOpenOrdersResult is the result returned from the private/get-open-orders API.
type GetOrderDetailResponse ¶
type GetOrderDetailResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result GetOrderDetailResult `json:"result"` }
GetOrderDetailResponse is the base response returned from the private/get-order-detail API.
type GetOrderDetailResult ¶
type GetOrderDetailResult struct { // TradeList is a list of trades for the order (if any). TradeList []Trade `json:"trade_list"` // OrderInfo is the detailed information about the order. OrderInfo Order `json:"order_info"` }
GetOrderDetailResult is the result returned from the private/get-order-detail API.
type GetOrderHistoryRequest ¶
type GetOrderHistoryRequest struct { // InstrumentName represents the currency pair for the orders (e.g. ETH_CRO or BTC_USDT). // if InstrumentName is omitted, all instruments will be returned. InstrumentName string `json:"instrument_name"` // Start is the start timestamp (milliseconds since the Unix epoch) // (Default: 24 hours ago) Start time.Time `json:"start_ts"` // End is the end timestamp (milliseconds since the Unix epoch) // (Default: now) End time.Time `json:"end_ts"` // PageSize represents maximum number of orders returned (for pagination) // (Default: 20, Max: 200) // if PageSize is 0, it will be set as 20 by default. PageSize int `json:"page_size"` // Page represents the page number (for pagination) // (0-based) Page int `json:"page"` }
GetOrderHistoryRequest is the request params sent for the private/get-order-history API.
The maximum duration between Start and End is 24 hours.
You will receive an INVALID_DATE_RANGE error if the difference exceeds the maximum duration.
For users looking to pull longer historical order data, users can create a loop to make a request for each 24-period from the desired start to end time.
type GetOrderHistoryResponse ¶
type GetOrderHistoryResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result GetOrderHistoryResult `json:"result"` }
GetOrderHistoryResponse is the base response returned from the private/get-order-history API.
type GetOrderHistoryResult ¶
type GetOrderHistoryResult struct { // OrderList is the array of orders. OrderList []Order `json:"order_list"` }
GetOrderHistoryResult is the result returned from the private/get-order-history API.
type GetTradesRequest ¶
type GetTradesRequest struct { // InstrumentName represents the currency pair for the trades (e.g. ETH_CRO or BTC_USDT). // if InstrumentName is omitted, all instruments will be returned. InstrumentName string `json:"instrument_name"` // Start is the start timestamp (milliseconds since the Unix epoch) // (Default: 24 hours ago) Start time.Time `json:"start_ts"` // End is the end timestamp (milliseconds since the Unix epoch) // (Default: now) End time.Time `json:"end_ts"` // PageSize represents maximum number of trades returned (for pagination) // (Default: 20, Max: 200) // if PageSize is 0, it will be set as 20 by default. PageSize int `json:"page_size"` // Page represents the page number (for pagination) // (0-based) Page int `json:"page"` }
GetTradesRequest is the request params sent for the private/get-trades API.
The maximum duration between Start and End is 24 hours.
You will receive an INVALID_DATE_RANGE error if the difference exceeds the maximum duration.
For users looking to pull longer historical trade data, users can create a loop to make a request for each 24-period from the desired start to end time.
type GetTradesResponse ¶
type GetTradesResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result GetTradesResult `json:"result"` }
GetTradesResponse is the base response returned from the private/get-trades API.
type GetTradesResult ¶
type GetTradesResult struct { // TradeList is the array of trades. TradeList []Trade `json:"trade_list"` }
GetTradesResult is the result returned from the private/get-trades API.
type Instrument ¶
type Instrument struct { // InstrumentName represents the name of the instrument (e.g. BTC_USDT). InstrumentName string `json:"instrument_name"` // QuoteCurrency represents the quote currency (e.g. USDT). QuoteCurrency string `json:"quote_currency"` // BaseCurrency represents the base currency (e.g. BTC). BaseCurrency string `json:"base_currency"` // PriceDecimals is the maximum decimal places for specifying price. PriceDecimals int `json:"price_decimals"` // QuantityDecimals is the maximum decimal places for specifying quantity. QuantityDecimals int `json:"quantity_decimals"` // MarginTradingEnabled represents whether margin trading is enabled for the instrument. MarginTradingEnabled bool `json:"margin_trading_enabled"` }
Instrument represents details of a specific currency pair
type InstrumentResult ¶
type InstrumentResult struct { // Instruments is a list of the returned instruments. Instruments []Instrument `json:"instruments"` }
InstrumentResult is the result returned from the public/get-instruments API.
type InstrumentsResponse ¶
type InstrumentsResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result InstrumentResult `json:"result"` }
InstrumentsResponse is the base response returned from the public/get-instruments API.
type LiquidityIndicator ¶
type LiquidityIndicator string
LiquidityIndicator represents liquidity indicator (MAKER or TAKER).
const ( LiquidityIndicatorMaker LiquidityIndicator = "MAKER" LiquidityIndicatorTaker LiquidityIndicator = "TAKER" )
type MarginTradingAPI ¶
type MarginTradingAPI interface { }
MarginTradingAPI is a Crypto.com Exchange client for Margin Trading API.
type Order ¶
type Order struct { // Status is the status of the order, can be ACTIVE, CANCELED, FILLED, REJECTED or EXPIRED. Status OrderStatus `json:"status"` // Reason is the reason code for rejected orders (see "Response and Reason Codes"). Reason string `json:"reason"` // Side represents whether the order is buy or sell. Side OrderSide `json:"side"` // Price is the price specified in the order. Price float64 `json:"price"` // Quantity is the quantity specified in the order. Quantity float64 `json:"quantity"` // OrderID is the unique identifier for the order. OrderID string `json:"order_id"` // ClientOID is the optional Client order ID (if provided in request when creating the order). ClientOID string `json:"client_oid"` // CreateTime is the order creation time. CreateTime time.Time `json:"create_time"` // UpdateTime is the order update time. UpdateTime time.Time `json:"update_time"` // Type represents the type of order. OrderType OrderType `json:"type"` // InstrumentName represents the currency pair to trade (e.g. ETH_CRO or BTC_USDT). InstrumentName string `json:"instrument_name"` // CumulativeQuantity is the cumulative-executed quantity (for partially filled orders). CumulativeQuantity float64 `json:"cumulative_quantity"` // CumulativeValue is the cumulative-executed value (for partially filled orders). CumulativeValue float64 `json:"cumulative_value"` // AvgPrice is the average filled price. If none is filled, 0 is returned. AvgPrice float64 `json:"avg_price"` // FeeCurrency is the currency used for the fees (e.g. CRO). FeeCurrency string `json:"fee_currency"` // TimeInForce represents how long the order should be active before being cancelled. // (Limit Orders Only) Options are: // - GOOD_TILL_CANCEL (Default if unspecified) // - FILL_OR_KILL // - IMMEDIATE_OR_CANCEL TimeInForce TimeInForce `json:"time_in_force"` // (Limit Orders Only) Options are: // - POST_ONLY // - Or leave empty ExecInst ExecInst `json:"exec_inst"` // TriggerPrice is the price at which the order is triggered. // Used with STOP_LOSS, STOP_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders. TriggerPrice float64 `json:"trigger_price"` }
Order represents the details of a specific order. Note: To detect a 'partial filled' status, look for status as ACTIVE and cumulative_quantity > 0.
type OrderStatus ¶
type OrderStatus string
OrderStatus is the current status of the order.
const ( OrderStatusActive OrderStatus = "ACTIVE" OrderStatusCancelled OrderStatus = "CANCELED" OrderStatusFilled OrderStatus = "FILLED" OrderStatusRejected OrderStatus = "REJECTED" OrderStatusExpired OrderStatus = "EXPIRED" )
type SingleTickerResponse ¶
type SingleTickerResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result SingleTickerResult `json:"result"` }
SingleTickerResponse is the base response returned from the public/get-ticker API when an instrument is specified.
type SingleTickerResult ¶
type SingleTickerResult struct { // Data is the returned ticker data for specified instrument. Data Ticker `json:"data"` }
SingleTickerResult is the result returned from the public/get-ticker API when an instrument is specified.
type SpotTradingAPI ¶
type SpotTradingAPI interface { // GetAccountSummary returns the account balance of a user for a particular token. // // currency can be left blank to retrieve balances for ALL tokens. // // Method: private/get-account-summary GetAccountSummary(ctx context.Context, currency string) ([]Account, error) // CreateOrder creates a new BUY or SELL order on the Exchange. // // This call is asynchronous, so the response is simply a confirmation of the request. // // The user.order subscription can be used to check when the order is successfully created. // // Method: private/create-order CreateOrder(ctx context.Context, req CreateOrderRequest) (*CreateOrderResult, error) // CancelOrder cancels an existing order on the Exchange. // // This call is asynchronous, so the response is simply a confirmation of the request. // // The user.order subscription can be used to check when the order is successfully cancelled. // // Method: private/cancel-order CancelOrder(ctx context.Context, instrumentName string, orderID string) error // CancelAllOrders cancels all orders for a particular instrument/pair. // // This call is asynchronous, so the response is simply a confirmation of the request. // // The user.order subscription can be used to check when the order is successfully cancelled. // // Method: private/cancel-all-orders CancelAllOrders(ctx context.Context, instrumentName string) error // GetOrderHistory gets the order history for a particular instrument. // // Pagination is handled using page size (Default: 20, Max: 200) & number (0-based). // If paging is used, enumerate each page (starting with 0) until an empty order_list array appears in the response. // // req.InstrumentName can be left blank to get open orders for all instruments. // // Method: private/get-order-history GetOrderHistory(ctx context.Context, req GetOrderHistoryRequest) ([]Order, error) // GetOpenOrders gets all open orders for a particular instrument. // // Pagination is handled using page size (Default: 20, Max: 200) & number (0-based). // // req.InstrumentName can be left blank to get open orders for all instruments. // // Method: private/get-open-orders GetOpenOrders(ctx context.Context, req GetOpenOrdersRequest) (*GetOpenOrdersResult, error) // GetOrderDetail gets details of an order for a particular order ID. // // Method: private/get-order-detail GetOrderDetail(ctx context.Context, orderID string) (*GetOrderDetailResult, error) // GetTrades gets all executed trades for a particular instrument. // // Pagination is handled using page size (Default: 20, Max: 200) & number (0-based). // If paging is used, enumerate each page (starting with 0) until an empty trade_list array appears in the response. // // req.InstrumentName can be left blank to get executed trades for all instruments. // // Method: private/get-trades GetTrades(ctx context.Context, req GetTradesRequest) ([]Trade, error) }
SpotTradingAPI is a Crypto.com Exchange client for Spot Trading API.
type SubAccountAPI ¶
type SubAccountAPI interface { }
SubAccountAPI is a Crypto.com Exchange client for Sub-account API.
type Ticker ¶
type Ticker struct { // Instrument is the instrument name (e.g. BTC_USDT, ETH_CRO, etc). Instrument string `json:"i"` // BidPrice is the current best bid price, 0 if there aren't any bids. BidPrice float64 `json:"b"` // AskPrice is the current best ask price, 0 if there aren't any asks. AskPrice float64 `json:"k"` // LatestTradePrice is the price of the latest trade, 0 if there weren't any trades. LatestTradePrice float64 `json:"a"` // Timestamp is the timestamp of the data. Timestamp time.Time `json:"t"` // Volume24H is the total 24h traded volume. Volume24H float64 `json:"v"` // PriceHigh24h is the price of the 24h highest trade, 0 if there weren't any trades. PriceHigh24h float64 `json:"h"` // PriceLow24h is the price of the 24h lowest trade, 0 if there weren't any trades. PriceLow24h float64 `json:"l"` // PriceChange24h is the 24-hour price change, 0 if there weren't any trades. PriceChange24h float64 `json:"c"` }
Ticker represents ticker details of a specific currency pair.
type TickerResponse ¶
type TickerResponse struct { // api.BaseResponse is the common response fields. api.BaseResponse // Result is the response attributes of the endpoint. Result TickerResult `json:"result"` }
TickerResponse is the base response returned from the public/get-ticker API. when no instrument is specified.
type TickerResult ¶
type TickerResult struct { // Data is the returned ticker data for all instruments. Data []Ticker `json:"data"` }
TickerResult is the result returned from the public/get-ticker API.
type TimeInForce ¶
type TimeInForce string
TimeInForce represents how long the order should be active before being cancelled.
type Trade ¶
type Trade struct { // Side represents whether the trade is buy or sell. Side OrderSide `json:"side"` // InstrumentName represents the currency pair to trade (e.g. ETH_CRO or BTC_USDT). InstrumentName string `json:"instrument_name"` // Fee is the trade fee. Fee float64 `json:"fee"` // TradeID is the unique identifier for the trade. TradeID string `json:"trade_id"` // CreateTime is the trade creation time. CreateTime time.Time `json:"create_time"` // TradedPrice is the executed trade price TradedPrice float64 `json:"traded_price"` // TradedQuantity is the executed trade quantity TradedQuantity float64 `json:"traded_quantity"` // FeeCurrency is the currency used for the fees (e.g. CRO). FeeCurrency string `json:"fee_currency"` // OrderID is the unique identifier for the order. OrderID string `json:"order_id"` // ClientOrderID is the client order id (if provided in request when creating the order). ClientOrderID string `json:"client_order_id"` // LiquidityIndicator is the liquidity indicator for the trade (MAKER/TAKER). LiquidityIndicator LiquidityIndicator `json:"liquidity_indicator"` }
Trade represents the details of a specific trade.