indodax

package module
v0.0.0-...-c015790 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2020 License: Apache-2.0 Imports: 12 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 (Comming Soon)

Example

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

go get github.com/firdasafridi/go-indodax

Public Endpoint

import (
    "fmt"
    "github.com/firdasafridi/go-indodax"
)

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

Private Endpoint

import (
    "fmt"
    "github.com/firdasafridi/go-indodax"
)

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

Notes

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

Documentation

Overview

Package indodax provide a library for accesing 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")
)

Functions

func SetDebug

func SetDebug(active bool) string

Types

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 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() (allOpenOrders map[string][]OpenOrders, err error)

This method gives the list of current open orders (buy and sell) all pair.

func (*Client) CancelOrderBuy

func (cl *Client) CancelOrderBuy(
	pairName string,
	orderId int64,
) (cancelOrder *CancelOrder, err error)

This method is for canceling an existing open buy order.

func (*Client) CancelOrderSell

func (cl *Client) CancelOrderSell(
	pairName string,
	orderId int64,
) (cancelOrder *CancelOrder, err error)

This method is for canceling an existing open sell order.

func (*Client) GetInfo

func (cl *Client) GetInfo() (usrInfo *UserInfo, err error)

This method gives user balances, user wallet, user id, username, profile picture and server's timestamp.

func (*Client) GetListTrades

func (cl *Client) GetListTrades(pairName string) (
	listTrade []*ListTrade, err error,
)

GetListTrades containts the historical trade of an individual pair.

func (*Client) GetOrder

func (cl *Client) GetOrder(
	pairName string,
	orderId int64,
) (getOrder *GetOrder, err error)

Use getOrder to get specific order details.

func (*Client) GetOrderBook

func (cl *Client) GetOrderBook(pairName string) (orderBook *OrderBook, err error)

GetOrderBook containts the order book buy and sell of an individual pair.

func (*Client) GetSummaries

func (cl *Client) GetSummaries() (summaries *Summary, err error)

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

func (*Client) GetTicker

func (cl *Client) GetTicker(pairName string) (ticker *Ticker, err error)

GetTicker containts the price summary like volume, last price, open buy, open sell of an individual pair.

func (*Client) OpenOrders

func (cl *Client) OpenOrders(pairName string) (openOrders []OpenOrders, err error)

This method gives the list of current open orders (buy and sell) by pair.

func (*Client) OrderHistory

func (cl *Client) OrderHistory(
	pairName string,
	count, from int64,
) (openOrders []OrderHistory, err error)

This method gives the list of order history (buy and sell).

func (*Client) TestAuthentication

func (cl *Client) TestAuthentication() (err error)

TestAuthenticate is function to test connection the current client's using token and secret keys.

func (*Client) TradeBuy

func (cl *Client) TradeBuy(
	pairName string,
	price, amount float64,
) (trade *Trade, err error)

This method is for opening a new buy order

func (*Client) TradeHitory

func (cl *Client) TradeHitory(
	pairName string,
	count, startTradeID, endTradeID int64,
	sortOrder string,
	sinceTime *time.Time,
	endTime *time.Time,
) (openOrders []TradeHistory, err error)

This method gives information about transaction in buying and selling history

func (*Client) TradeSell

func (cl *Client) TradeSell(
	pairName string,
	price, amount float64,
) (trade *Trade, err error)

This method is for opening a new sell order

func (*Client) TransHistory

func (cl *Client) TransHistory() (transHistory *TransHistory, err error)

This method gives 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
}

Get Order containt 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
}

List Trade containt 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
}

Open Orders containt 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 OrderHistory

type OrderHistory struct {
	ID           int64
	Type         string
	Price        float64
	SubmitTime   time.Time
	FinishTime   time.Time
	Status       string
	OrderAmount  float64
	RemainAmount float64
	AssetName    string
}

Order History containt all order book from user

func (*OrderHistory) UnmarshalJSON

func (orderHistory *OrderHistory) UnmarshalJSON(b []byte) (err error)

type Summary

type Summary struct {
	Tickers   map[string]*Ticker
	Prices24h map[string]float64
	Prices7d  map[string]float64
}

Summary containts 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 containts 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 containt status of order placed by user like recive 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
}

Trade History containt 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
}

Transaction History containt 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
}

User Info containt balance info, wallet address, user id, profile picture, username, and email of user.

func (*UserInfo) UnmarshalJSON

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

Jump to

Keyboard shortcuts

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