Documentation ¶
Overview ¶
Package indodax provide a library for accessing Indodax API (see https://indodax.com/downloads/BITCOINCOID-API-DOCUMENTATION.pdf for HTTP API documentation).
Indodax provide public and private APIs. The public APIs can be accessed directly by creating new client with empty token and secret parameters. The private APIs can only be accessed by using token and secret keys (API credential).
An API credential can be retrieved manually by logging in into your Indodax Exchange account (https://indodax.com/market) and open the "Trade API" menu section or https://indodax.com/trade_api.
Please keep these credentials safe and do not reveal to any external party.
Beside passing the token and secret to NewClient or Authenticate, this library also read token and secret values from environment variables "INDODAX_KEY" for token and "INDODAX_SECRET" for secret.
Index ¶
- Constants
- Variables
- func SetDebug(active bool) string
- func WsOrderBookServe(symbol OrderBookSymbol, handler WsOrderBookEventHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)
- type AuthenticationResponse
- type AuthenticationResponseResult
- type BasicResponse
- type CancelOrder
- type ChannelRequest
- type ChannelRequestParam
- type Client
- func (cl *Client) AllOpenOrders(ctx context.Context) (allOpenOrders map[string][]OpenOrders, err error)
- func (cl *Client) CancelOrderBuy(ctx context.Context, pairName string, orderId int64) (cancelOrder *CancelOrder, err error)
- func (cl *Client) CancelOrderSell(ctx context.Context, pairName string, orderId int64) (cancelOrder *CancelOrder, err error)
- func (cl *Client) GetInfo(ctx context.Context) (usrInfo *UserInfo, err error)
- func (cl *Client) GetListTrades(ctx context.Context, pairName string) (listTrade []*ListTrade, err error)
- func (cl *Client) GetOrder(ctx context.Context, pairName string, orderId int64) (getOrder *GetOrder, err error)
- func (cl *Client) GetOrderBook(ctx context.Context, pairName string) (orderBook *OrderBook, err error)
- func (cl *Client) GetPairs(ctx context.Context) (pairs *Pairs, err error)
- func (cl *Client) GetPriceIncrements(ctx context.Context) (priceIncrements *PriceIncrements, err error)
- func (cl *Client) GetSummaries(ctx context.Context) (summaries *Summary, err error)
- func (cl *Client) GetTicker(ctx context.Context, pairName string) (ticker *Ticker, err error)
- func (cl *Client) OpenOrders(ctx context.Context, pairName string) (openOrders []OpenOrders, err error)
- func (cl *Client) OrderHistory(ctx context.Context, pairName string, count, from int64) (openOrders []OrderHistory, err error)
- func (cl *Client) TestAuthentication(ctx context.Context) (err error)
- func (cl *Client) TradeBuy(ctx context.Context, pairName string, price, amount float64) (trade *Trade, err error)
- func (cl *Client) TradeHistory(ctx context.Context, pairName string, count, startTradeID, endTradeID int64, ...) (openOrders []TradeHistory, err error)
- func (cl *Client) TradeSell(ctx context.Context, pairName string, price, amount float64) (trade *Trade, err error)
- func (cl *Client) TransHistory(ctx context.Context) (transHistory *TransHistory, err error)
- type ErrHandler
- type GetOrder
- type ListTrade
- type OpenOrders
- type Order
- type OrderBook
- type OrderBookEntry
- type OrderBookEvent
- type OrderBookSymbol
- type OrderHistory
- type Pair
- type Pairs
- type PriceIncrements
- type Summary
- type Ticker
- type Trade
- type TradeHistory
- type TransDeposit
- type TransHistory
- type TransWithdraw
- type UserInfo
- type WsConfig
- type WsHandler
- type WsOrderBookEventHandler
- type WsRequestHandler
Constants ¶
const ( // UrlPublic is url to open data for public. It doesn't need an API key to call these methods. You can call // simple GET request or open it directly from the browser. UrlPublic = "https://indodax.com/api" // UrlPrivate : To use Private API first you need to obtain your API credentials by logging into your indodax.com // account and open https://indodax.com/trade_api. These credentials contain "API Key" and "Secret // Key". Please keep these credentials safe. UrlPrivate = "https://indodax.com/tapi" )
Variables ¶
var ( // ErrUnauthenticated define an error when user did not provide token // and secret keys when accessing private APIs. ErrUnauthenticated = fmt.Errorf("unauthenticated connection") // ErrInvalidPairName define an error if user call API with empty, // invalid or unknown pair's name. ErrInvalidPairName = fmt.Errorf("invalid or empty pair name") ErrInvalidOrderID = fmt.Errorf("empty order ID") ErrInvalidPrice = fmt.Errorf("empty price") ErrInvalidAmount = fmt.Errorf("empty amount") ErrInvalidAssetName = fmt.Errorf("empty asset name") )
var ( // WebsocketTimeout is an interval for sending ping/pong messages if WebsocketKeepalive is enabled WebsocketTimeout = time.Second * 60 // WebsocketKeepalive enables sending ping/pong messages to check the connection stability WebsocketKeepalive = false )
Functions ¶
func WsOrderBookServe ¶
func WsOrderBookServe(symbol OrderBookSymbol, handler WsOrderBookEventHandler, errHandler ErrHandler) (doneC, stopC chan struct{}, err error)
Types ¶
type AuthenticationResponse ¶
type AuthenticationResponse struct { BasicResponse Result AuthenticationResponseResult `json:"result"` }
type BasicResponse ¶
type BasicResponse struct {
Id int `json:"id"`
}
type CancelOrder ¶
CancelOrder contains a success response from calling a "cancelOrder" method.
func (*CancelOrder) UnmarshalJSON ¶
func (cancelOrder *CancelOrder) UnmarshalJSON(b []byte) (err error)
type ChannelRequest ¶
type ChannelRequest struct { Method int `json:"method"` Params ChannelRequestParam `json:"params"` // contains filtered or unexported fields }
type ChannelRequestParam ¶
type ChannelRequestParam struct {
Channel string `json:"channel"`
}
type Client ¶
type Client struct { Info *UserInfo // contains filtered or unexported fields }
Client represent common fields and environment Trading API
func NewClient ¶
NewClient create and initialize new Indodax client.
The token and secret parameters are used to authenticate the client when accessing private API.
By default, the key and secret is read from environment variables "INDODAX_KEY" and "INDODAX_SECRET", the parameters will override the default value, if its set. If both environment variables and the parameters are empty, the client can only access the public API.
func (*Client) AllOpenOrders ¶
func (cl *Client) AllOpenOrders(ctx context.Context) (allOpenOrders map[string][]OpenOrders, err error)
AllOpenOrders returns the list of current open orders (buy and sell) all pair.
func (*Client) CancelOrderBuy ¶
func (cl *Client) CancelOrderBuy( ctx context.Context, pairName string, orderId int64, ) (cancelOrder *CancelOrder, err error)
CancelOrderBuy cancels an existing open buy order.
func (*Client) CancelOrderSell ¶
func (cl *Client) CancelOrderSell( ctx context.Context, pairName string, orderId int64, ) (cancelOrder *CancelOrder, err error)
CancelOrderSell cancels an existing open sell order.
func (*Client) GetInfo ¶
GetInfo returns user balances, user wallet, user id, username, profile picture and server's timestamp.
func (*Client) GetListTrades ¶
func (cl *Client) GetListTrades(ctx context.Context, pairName string) ( listTrade []*ListTrade, err error, )
GetListTrades contains the historical trade of an individual pair.
func (*Client) GetOrder ¶
func (cl *Client) GetOrder( ctx context.Context, pairName string, orderId int64, ) (getOrder *GetOrder, err error)
GetOrder returns specific order details by pairName and orderId
func (*Client) GetOrderBook ¶
func (cl *Client) GetOrderBook(ctx context.Context, pairName string) (orderBook *OrderBook, err error)
GetOrderBook contains the order book buy and sell of an individual pair.
func (*Client) GetPriceIncrements ¶
func (cl *Client) GetPriceIncrements(ctx context.Context) (priceIncrements *PriceIncrements, err error)
GetPriceIncrements provide price increments of each pairs on exchange
func (*Client) GetSummaries ¶
GetSummaries contains the price summary like volume, last price, open buy, open sell of all pair.
func (*Client) GetTicker ¶
GetTicker contains the price summary like volume, last price, open buy, open sell of an individual pair.
func (*Client) OpenOrders ¶
func (cl *Client) OpenOrders(ctx context.Context, pairName string) (openOrders []OpenOrders, err error)
OpenOrders returns current open orders (buy and sell) by pair.
func (*Client) OrderHistory ¶
func (cl *Client) OrderHistory( ctx context.Context, pairName string, count, from int64, ) (openOrders []OrderHistory, err error)
OrderHistory returns the list of order history (buy and sell).
func (*Client) TestAuthentication ¶
TestAuthentication is function to test connection the current client's using token and secret keys.
func (*Client) TradeBuy ¶
func (cl *Client) TradeBuy( ctx context.Context, pairName string, price, amount float64, ) (trade *Trade, err error)
TradeBuy opens a new buy order
func (*Client) TradeHistory ¶
func (cl *Client) TradeHistory( ctx context.Context, pairName string, count, startTradeID, endTradeID int64, sortOrder string, sinceTime *time.Time, endTime *time.Time, ) (openOrders []TradeHistory, err error)
TradeHistory returns information about transaction in buying and selling history
func (*Client) TradeSell ¶
func (cl *Client) TradeSell( ctx context.Context, pairName string, price, amount float64, ) (trade *Trade, err error)
TradeSell opens a new sell order
func (*Client) TransHistory ¶
func (cl *Client) TransHistory(ctx context.Context) (transHistory *TransHistory, err error)
TransHistory returns list of deposits and withdrawals of all currencies
type GetOrder ¶
type GetOrder struct { OrderID int64 Price float64 Type string OrderAmount float64 RemainAmount float64 SubmitTime time.Time FinishTime time.Time Status string AssetName string }
GetOrder contains a status from order placed of user
func (*GetOrder) UnmarshalJSON ¶
type OpenOrders ¶
type OpenOrders struct { ID int64 SubmitTime time.Time Price float64 OrderAmount float64 RemainAmount float64 Type string AssetName string }
OpenOrders contains all order book from user
func (*OpenOrders) UnmarshalJSON ¶
func (openOrders *OpenOrders) UnmarshalJSON(b []byte) (err error)
type Order ¶
Order contains the number of amount asset and price of open order
func (*Order) UnmarshalJSON ¶
type OrderBookEntry ¶
type OrderBookEvent ¶
type OrderBookEvent struct { Pair string `json:"pair"` Ask []OrderBookEntry `json:"ask"` Bid []OrderBookEntry `json:"bid"` }
type OrderBookSymbol ¶
type OrderHistory ¶
type OrderHistory struct { ID int64 Type string Price float64 SubmitTime time.Time FinishTime time.Time Status string OrderAmount float64 RemainAmount float64 AssetName string }
OrderHistory contains all order book from user
func (*OrderHistory) UnmarshalJSON ¶
func (orderHistory *OrderHistory) UnmarshalJSON(b []byte) (err error)
type Pair ¶
type Pair struct { Id string `json:"id"` Symbol string `json:"symbol"` BaseCurrency string `json:"base_currency"` TradedCurrency string `json:"traded_currency"` TradedCurrencyUnit string `json:"traded_currency_unit"` Description string `json:"description"` TickerId string `json:"ticker_id"` VolumePrecision int `json:"volume_precision"` PricePrecision int `json:"price_precision"` PriceRound int `json:"price_round"` Pricescale int `json:"pricescale"` TradeMinBaseCurrency int `json:"trade_min_base_currency"` TradeMinTradedCurrency float64 `json:"trade_min_traded_currency"` HasMemo bool `json:"has_memo"` MemoName interface{} `json:"memo_name"` // It could be either string or bool TradeFeePercent float64 `json:"trade_fee_percent"` UrlLogo string `json:"url_logo"` UrlLogoPng string `json:"url_logo_png"` IsMaintenance int `json:"is_maintenance"` IsMarketSuspended int `json:"is_market_suspended"` CoingeckoId string `json:"coingecko_id"` CmcId interface{} `json:"cmc_id"` // It could either be int or bool }
type Pairs ¶
func (*Pairs) UnmarshalJSON ¶
type PriceIncrements ¶
func (*PriceIncrements) UnmarshalJSON ¶
func (is *PriceIncrements) UnmarshalJSON(b []byte) (err error)
type Summary ¶
type Summary struct { Tickers map[string]*Ticker Prices24h map[string]float64 Prices7d map[string]float64 }
Summary contains all tickers, prices24h, and prices 7d status of all pairs.
func (*Summary) UnmarshalJSON ¶
type Ticker ¶
type Ticker struct { PairName string High float64 Low float64 AssetVolume float64 BaseVolume float64 Last float64 Buy float64 Sell float64 }
Ticker contains High price 24h, Low price24h, Volume asset Volume Base, Last price, Open buy, and Open Sell
type Trade ¶
type Trade struct { Receive float64 ReceiveAssetName string Spend float64 SpendAssetName string Sold float64 SoldAssetName string Remain float64 RemainAssetName string Fee float64 OrderID int64 Balance map[string]float64 }
Trade contains status of order placed by user like receive asset, spend asset, sold asset, remain asset, fee, order id placed, and last balance after trade.
func (*Trade) UnmarshalJSON ¶
type TradeHistory ¶
type TradeHistory struct { TradeID int64 OrderID int64 Type string AssetName string Amount float64 Price float64 Fee float64 TradeTime time.Time }
TradeHistory contains trade id, order id, type of trade match(buy/sell), AssetName, amount, price, and fee.
func (*TradeHistory) UnmarshalJSON ¶
func (tradeHistory *TradeHistory) UnmarshalJSON(b []byte) (err error)
type TransDeposit ¶
type TransDeposit struct { Status string Type string Amount float64 Fee float64 SubmitTime time.Time SuccessTime time.Time ID int64 }
func (*TransDeposit) UnmarshalJSON ¶
func (transDeposit *TransDeposit) UnmarshalJSON(b []byte) (err error)
type TransHistory ¶
type TransHistory struct { Withdraw map[string][]TransWithdraw Deposit map[string][]TransDeposit }
TransHistory contains list of Deposit and withdraw.
type TransWithdraw ¶
type TransWithdraw struct { Status string Type string Amount float64 Fee float64 SubmitTime time.Time SuccessTime time.Time ID int64 }
func (*TransWithdraw) UnmarshalJSON ¶
func (transWithdraw *TransWithdraw) UnmarshalJSON(b []byte) (err error)
type UserInfo ¶
type UserInfo struct { Balance map[string]float64 BalanceHold map[string]float64 WalletAddress map[string]string UserId int ProfilePicture string UserName string ServerTime time.Time Email string }
UserInfo contains balance info, wallet address, user id, profile picture, username, and email of user.
func (*UserInfo) UnmarshalJSON ¶
type WsOrderBookEventHandler ¶
type WsOrderBookEventHandler func(event *OrderBookEvent)
type WsRequestHandler ¶
Source Files ¶
- cancel_trade.go
- client.go
- curl.go
- doc.go
- env.go
- get_order.go
- indodax.go
- list_trades.go
- open_orders.go
- order.go
- order_history.go
- orderbook.go
- pair.go
- price_increments.go
- private.go
- public.go
- summary.go
- ticker.go
- trade.go
- trades_history.go
- trans_history.go
- user_info.go
- websocket.go
- websocket_service.go