idex

package module
v0.0.0-...-0d79f00 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2018 License: MIT Imports: 9 Imported by: 2

README

TODO

  • Contract-backed trade functions:
    • order
    • trade
    • cancel
    • withdraw

API Docs

https://github.com/AuroraDAO/idex-api-docs

REST Example

func Ticker(mkt string) {
    i := idex.New()
    t, _ := i.API.Ticker("ETH_AUC")
    fmt.Printf("ticker: %+v\n", t)
}

Websocket Example

func ConsumeIdex(ctx context.Context) {
	i := idex.New()
	if err := i.Socket.Connect(); err != nil {
		log.Panic(err)
	}
	defer i.Socket.Conn.Close()

	response := make(chan idex.SocketResponse)
	go i.Socket.Monitor(response)

	for {
		select {
		case r := <-response:
			if r.PushCancel != nil {
				fmt.Printf("got a cancel: %+v\n", r.PushCancel)
			}
			if r.TradeInserted != nil {
				fmt.Printf("got a trade: %+v\n", r.TradeInserted)
			}
			if r.OrderInserted != nil {
				fmt.Printf("got an order: %+v\n", r.OrderInserted)
			}
			if r.Error != nil {
				fmt.Printf("got an error: %+v\n", r.Error)
			}
		case <-ctx.Done():
			err := i.Socket.Conn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
			if err != nil {
				log.Println("Error writing close message:", err)
				return
			}

			<-time.After(time.Second)
			return
		}
	}
}

License

MIT

Documentation

Index

Constants

View Source
const (
	APIURL = "https://api.idex.market"
	WSURL  = "wss://v1.idex.market"
)

IDEX rest and websocket urls

Variables

This section is empty.

Functions

func UnmarshalErrorOnType

func UnmarshalErrorOnType(err error, t string) bool

UnmarshalErrorOnType is true when the error was a json.UnmarshalTypeError on type t

Types

type API

type API struct {
	URL string
}

API for requests

func (*API) Balances

func (a *API) Balances(address string) (bs map[string]string, err error)

Balances returns available balances

func (*API) CompleteBalances

func (a *API) CompleteBalances(address string) (bs map[string]*Balance, err error)

CompleteBalances returns available balances with balance in orders

func (*API) ContractAddress

func (a *API) ContractAddress() (address string, err error)

ContractAddress returns the IDEX contract address

func (*API) Currencies

func (a *API) Currencies() (cs map[string]*Currency, err error)

Currencies returns all supported currencies

func (*API) DepositsWithdrawals

func (a *API) DepositsWithdrawals(address string, start, end int) (ds []*Deposit, ws []*Withdrawal, err error)

DepositsWithdrawals returns the user's deposits and withdrawals

func (*API) NextNonce

func (a *API) NextNonce(address string) (nonce int, err error)

NextNonce returns the next available nonce

func (*API) OpenOrders

func (a *API) OpenOrders(market, address string) (os []*OpenOrder, err error)

OpenOrders all open orders for market and/or user address

func (*API) OrderBook

func (a *API) OrderBook(market string) (ob *OrderBook, err error)

OrderBook for a market

func (*API) OrderTrades

func (a *API) OrderTrades(hash string) (ts []*Trade, err error)

OrderTrades returns all trades involved in the order hash

func (*API) Post

func (a *API) Post(endpoint, payload string) ([]byte, error)

Post returns the result of a POST to the endpoint with the payload

func (*API) Ticker

func (a *API) Ticker(market string) (t *Ticker, err error)

Ticker for the market

func (*API) Tickers

func (a *API) Tickers() (t map[string]*Ticker, err error)

Tickers for all markets

func (*API) TradeHistoryMarket

func (a *API) TradeHistoryMarket(market, address string, start, end int) (ts []*Trade, err error)

TradeHistoryMarket trade history for a market, filterable by user and timestamps API limited to 200 trades

func (*API) TradeHistoryUser

func (a *API) TradeHistoryUser(address string, start, end int) (ts map[string][]*Trade, err error)

TradeHistoryUser trade history for a user across all markets, filterable by timestamps API limited to 200 trades

func (*API) Volume24

func (a *API) Volume24() (v *Volume, err error)

Volume24 returns 24-hour volume for all markets

type Balance

type Balance struct {
	Available string `json:"available"`
	OnOrders  string `json:"onOrders"`
}

Balance of token available and in open orders

type Currency

type Currency struct {
	Name     string `json:"name"`
	Decimals int    `json:"decimals"`
	Address  string `json:"address"`
}

Currency holds details about supported currencies

type Deposit

type Deposit struct {
	DepositNumber   int    `json:"depositNumber"`
	Currency        string `json:"currency"`
	Amount          string `json:"amount"`
	Timestamp       int    `json:"timestamp"`
	TransactionHash string `json:"transactionHash"`
}

Deposit holds information about a user's deposits

type Idex

type Idex struct {
	API    *API
	Socket *Socket
}

Idex service

func New

func New() *Idex

New instance of an Idex

type Method

type Method struct {
	Method string `json:"method"`
}

Method name of websocket event

type OpenOrder

type OpenOrder struct {
	Timestamp   int     `json:"timestamp"`
	Price       string  `json:"price"`
	Amount      string  `json:"amount"`
	Total       string  `json:"total"`
	OrderHash   string  `json:"orderHash"`
	Market      string  `json:"market"`
	Type        string  `json:"type"`
	OrderNumber int     `json:"orderNumber"`
	Params      *Params `json:"params"`
}

OpenOrder for a market or user

type Order

type Order struct {
	Price     string  `json:"price"`
	Amount    string  `json:"amount"`
	Total     string  `json:"total"`
	OrderHash string  `json:"orderHash"`
	Params    *Params `json:"params"`
}

Order held in OrderBook

type OrderBook

type OrderBook struct {
	Bids []Order `json:"bids"`
	Asks []Order `json:"asks"`
}

OrderBook holds bid and ask orders for a market

type OrderInserted

type OrderInserted struct {
	Complete        bool   `json:"complete"`
	ID              int    `json:"id"`
	TokenBuy        string `json:"tokenBuy"`
	AmountBuy       string `json:"amountBuy"`
	TokenSell       string `json:"tokenSell"`
	AmountSell      string `json:"amountSell"`
	Expires         int    `json:"expires"`
	Nonce           int    `json:"nonce"`
	User            string `json:"user"`
	V               int    `json:"v"`
	R               string `json:"r"`
	S               string `json:"s"`
	Hash            string `json:"hash"`
	FeeDiscount     string `json:"feeDiscount"`
	RewardsMultiple string `json:"rewardsMultiple"`
	UpdatedAt       string `json:"updatedAt"`
	CreatedAt       string `json:"createdAt"`
}

OrderInserted event

func (*OrderInserted) UnmarshalJSON

func (oi *OrderInserted) UnmarshalJSON(b []byte) error

UnmarshalJSON custom for OrderInserted to handle V as string or int

type Params

type Params struct {
	TokenBuy      string `json:"tokenBuy"`
	BuySymbol     string `json:"buySymbol"`
	BuyPrecision  int    `json:"buyPrecision"`
	AmountBuy     string `json:"amountBuy"`
	TokenSell     string `json:"tokenSell"`
	SellSymbol    string `json:"sellSymbol"`
	SellPrecision int    `json:"sellPrecision"`
	AmountSell    string `json:"amountSell"`
	Expires       int    `json:"expires"`
	Nonce         int    `json:"nonce"`
	User          string `json:"user"`
}

Params of an Order

type PushCancel

type PushCancel struct {
	ID        int    `json:"id"`
	Hash      string `json:"hash"`
	User      string `json:"user"`
	V         int    `json:"v"`
	R         string `json:"r"`
	S         string `json:"s"`
	UpdatedAt string `json:"updatedAt"`
	CreatedAt string `json:"createdAt"`
}

PushCancel event

func (*PushCancel) UnmarshalJSON

func (pc *PushCancel) UnmarshalJSON(b []byte) error

UnmarshalJSON custom for PushCancel to handle V as string or int

type Socket

type Socket struct {
	Conn *websocket.Conn
	URL  string
}

Socket wraps the websocket connection

func (*Socket) Connect

func (s *Socket) Connect() error

Connect to websocket

func (*Socket) Monitor

func (s *Socket) Monitor(resp chan SocketResponse)

Monitor the websocket for messages

type SocketResponse

type SocketResponse struct {
	OrderInserted *OrderInserted
	TradeInserted *TradeInserted
	PushCancel    *PushCancel
	Error         error
}

SocketResponse holds messages to pass back from the websocket

type Ticker

type Ticker struct {
	Last          string `json:"last"`
	High          string `json:"high"`
	Low           string `json:"low"`
	LowestAsk     string `json:"lowestAsk"`
	HighestBid    string `json:"highestBid"`
	PercentChange string `json:"percentChange"`
	BaseVolume    string `json:"baseVolume"`
	QuoteVolume   string `json:"quoteVolume"`
}

Ticker data

type Trade

type Trade struct {
	Date            string `json:"date"`
	Amount          string `json:"amount"`
	Type            string `json:"type"`
	Total           string `json:"total"`
	Price           string `json:"price"`
	OrderHash       string `json:"orderHash"`
	UUID            string `json:"uuid"`
	BuyerFee        string `json:"buyerFee"`
	SellerFee       string `json:"sellerFee"`
	GasFee          string `json:"gasFee"`
	Timestamp       int    `json:"timestamp"`
	Maker           string `json:"maker"`
	Taker           string `json:"taker"`
	TransactionHash string `json:"transactionHash"`
	USDValue        string `json:"usdValue"`
}

Trade holds details about a trade

type TradeInserted

type TradeInserted struct {
	ID              int    `json:"id"`
	Price           string `json:"price"`
	AmountPrecision string `json:"amountPrecision"`
	TotalPrecision  string `json:"totalPrecision"`
	Date            string `json:"date"`
	Timestamp       int    `json:"timestamp"`
	SellerFee       string `json:"sellerFee"`
	BuyerFee        string `json:"buyerFee"`
	Type            string `json:"type"`
	TokenBuy        string `json:"tokenBuy"`
	AmountBuy       string `json:"amountBuy"`
	TokenSell       string `json:"tokenSell"`
	AmountSell      string `json:"amountSell"`
	FeeMake         string `json:"feeMake"`
	FeeTake         string `json:"feeTake"`
	GasFee          string `json:"gasFee"`
	Buy             string `json:"buy"`
	V               int    `json:"v"`
	R               string `json:"r"`
	S               string `json:"s"`
	User            string `json:"user"`
	Sell            string `json:"sell"`
	Hash            string `json:"hash"`
	Nonce           int    `json:"nonce"`
	Amount          string `json:"amount"`
	USDValue        string `json:"usdValue"`
	GasFeeAdjusted  string `json:"gasFeeAdjusted"`
	UUID            string `json:"uuid"`
	UpdatedAt       string `json:"updatedAt"`
	CreatedAt       string `json:"createdAt"`
}

TradeInserted event

func (*TradeInserted) UnmarshalJSON

func (ti *TradeInserted) UnmarshalJSON(b []byte) error

UnmarshalJSON custom for TradeInserted to handle V as string or int

type Volume

type Volume struct {
	Markets  map[string]map[string]string
	TotalETH string
}

Volume maps markets to ETH and TOKEN amounts, with total eth volume

func (*Volume) UnmarshalJSON

func (v *Volume) UnmarshalJSON(b []byte) error

UnmarshalJSON custom for Volume

type Withdrawal

type Withdrawal struct {
	WithdrawalNumber int    `json:"depositNumber"`
	Currency         string `json:"currency"`
	Amount           string `json:"amount"`
	Timestamp        int    `json:"timestamp"`
	TransactionHash  string `json:"transactionHash"`
	Status           string `json:"status"`
}

Withdrawal holds information about a user's withdrawals

Jump to

Keyboard shortcuts

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