indodax

package module
v0.0.0-...-66ea23e Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 17 Imported by: 0

README

GO-Indodax - A Library trading platform Indodax using Go Language

Description

Welcome to Indodax golang library. These library outline exchange functionality, market details, and APIs.

APIs are separated into two categories: private and public. Private APIs require authentication and provide access to placing orders and other account information. Public APIs provide market data.

Features

Public Endpoint

  • Ticker
  • Depth (Order Book)
  • Trades (Trade History)

Private Endpoint

  • Get Information User
  • Withdraw/Deposit History
  • Trading History
  • Order History
  • Open Orders
  • Trade
  • Withdraw (Coming Soon) ``

Example

To start use the library you can get the repository first:

go get github.com/edward-yakop/go-indodax

Public Endpoint

package test

import (
	"context"
    "fmt"
    "github.com/edward-yakop/go-indodax"
)

func main() {
    cl, err := indodax.NewClient(
		"",
		"",
	)
	ticker, err := cl.GetTicker(context.Background(), "ten_idr")
	if err != nil {
		fmt.Println(err)
	}
    fmt.Printf("Ticker %v\n",ticker)
}

Private Endpoint

package test

import (
    "context"
    "fmt"
    "github.com/edward-yakop/go-indodax"
)

func main() {
    cl, err := indodax.NewClient(
		"key", 
		"secret", 
	)
	tradeBuy, err := cl.TradeBuy(context.Background(), "usdt_idr", 12000, 50000)
	if err != nil {
		fmt.Println(err)
	}
    fmt.Printf("TradeBuy %v\n",tradeBuy)
}

Notes

  • For bug report you can refer to this
  • For feature request you can refer to this

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

View Source
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

View Source
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")
)
View Source
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 SetDebug

func SetDebug(active bool) string

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 AuthenticationResponseResult

type AuthenticationResponseResult struct {
	Client  string `json:"client"`
	Version string `json:"version"`
	Expires bool   `json:"expires"`
	Ttl     int    `json:"ttl"`
}

type BasicResponse

type BasicResponse struct {
	Id int `json:"id"`
}

type CancelOrder

type CancelOrder struct {
	OrderID  int64
	Type     string
	PairName string
	Balance  map[string]float64
}

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

func NewClient(key, secret string) (cl *Client, err error)

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

func (cl *Client) GetInfo(ctx context.Context) (usrInfo *UserInfo, err error)

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) GetPairs

func (cl *Client) GetPairs(ctx context.Context) (pairs *Pairs, err error)

GetPairs provides available pairs on exchange

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

func (cl *Client) GetSummaries(ctx context.Context) (summaries *Summary, err error)

GetSummaries contains the price summary like volume, last price, open buy, open sell of all pair.

func (*Client) GetTicker

func (cl *Client) GetTicker(ctx context.Context, pairName string) (ticker *Ticker, err error)

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

func (cl *Client) TestAuthentication(ctx context.Context) (err error)

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 ErrHandler

type ErrHandler func(err error)

ErrHandler handles errors

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

func (getOrder *GetOrder) UnmarshalJSON(b []byte) (err error)

type ListTrade

type ListTrade struct {
	ID     int64
	Type   string
	Date   time.Time
	Amount float64
	Price  float64
}

ListTrade contains all match order from user

func (*ListTrade) UnmarshalJSON

func (listTrade *ListTrade) UnmarshalJSON(b []byte) (err error)

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

type Order struct {
	Amount float64
	Price  float64
}

Order contains the number of amount asset and price of open order

func (*Order) UnmarshalJSON

func (order *Order) UnmarshalJSON(b []byte) (err error)

type OrderBook

type OrderBook struct {
	Buys  []*Order `json:"buy"`
	Sells []*Order `json:"sell"`
}

OrderBook contains the data from order open buy(bid) and sell(ask).

type OrderBookEntry

type OrderBookEntry struct {
	BaseVolume  float64 `json:"base_volume"`
	QuoteVolume float64 `json:"quote_volume"`
	Price       float64 `json:"price"`
}

type OrderBookEvent

type OrderBookEvent struct {
	Pair string           `json:"pair"`
	Ask  []OrderBookEntry `json:"ask"`
	Bid  []OrderBookEntry `json:"bid"`
}

type OrderBookSymbol

type OrderBookSymbol struct {
	Base  string
	Quote string
}

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"`
	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

type Pairs struct {
	Pairs map[string]Pair
}

func (*Pairs) UnmarshalJSON

func (ps *Pairs) UnmarshalJSON(b []byte) (err error)

type PriceIncrements

type PriceIncrements struct {
	Entries map[string]float64
}

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

func (sum *Summary) UnmarshalJSON(b []byte) (err error)

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

func (trade *Trade) UnmarshalJSON(b []byte) (err error)

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

func (UserInfo *UserInfo) UnmarshalJSON(b []byte) (err error)

type WsConfig

type WsConfig struct {
	Endpoint string
}

WsConfig webservice configuration

type WsHandler

type WsHandler func(message []byte)

WsHandler handle raw websocket message

type WsOrderBookEventHandler

type WsOrderBookEventHandler func(event *OrderBookEvent)

type WsRequestHandler

type WsRequestHandler func(conn *websocket.Conn) error

Jump to

Keyboard shortcuts

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