wazirx

package module
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2020 License: MIT Imports: 12 Imported by: 0

README ¶

Go-WazirX

itsksaurabh Go Report Card GoDoc Built with Mage MIT License


Go-WazirX is a Go client library for accessing the WazirX's Public Rest API.

This project has been recommended by the founders of WazirX cryptocurrency exchange themselves. You can check here.

API Documentation

You can read the API server documentation here.

Installation

Make sure you have set the environment variable $GOPATH

export GOPATH="path/to/your/go/folder"

Obtain the latest version of the Go-Wazirx library with:

go get github.com/itsksaurabh/go-wazirx

Then, add the following to your Go project:

import (
	"github.com/itsksaurabh/go-wazirx"
)

Usage

Package provides a client for accessing different endpoints of the API. Create a new instance of Client, then use the various methods on the client to access different parts of the API.

For demonstration:

package main

import (
	"context"
	"fmt"
	"log"
	
	"github.com/itsksaurabh/go-wazirx"
)

func main() {
        // client for accessing different endpoints of the API
	client := wazirx.Client{}
	ctx := context.Background()

	data, err := client.MarketStatus(ctx)
	if err != nil {
		log.Fatal("request failed:", err)
	}
	fmt.Println(data)
}

Notes:

Error Handling

All errors generated at runtime will be returned to the calling client method. Any API request for which WazirX returns an error encoded in a JSON response will be parsed and returned by the client method as a Golang error struct. Lastly, it is important to note that for HTTP requests, if the response code returned is not '200 OK', an error will be returned to the client method detailing the response code that was received.

Testing

In order to run the tests for this library, you will first need to install Mage - A Make/rake-like dev tool using Go. You can install the dependency with the following command:

Using GOPATH

go get -u -d github.com/magefile/mage
cd $GOPATH/src/github.com/magefile/mage
go run bootstrap.go

Using Go Modules

git clone https://github.com/magefile/mage
cd mage
go run bootstrap.go

The mage binary will be created in your $GOPATH/bin directory. You may also install a binary release from Mage's releases page.

Then run all tests by executing the following in your command line:

$ mage -v Test

Updating Test Data

You can update the test data inside ./testdata/ by enabling the following flag inside the file ./wazirx_test.go and then perform testing. By default the flag is set to false.

var (
	updateTestData = flag.Bool(
		"update",
		true,
		"if set then update testdata else use saved testdata for testing.",
	)
)

Contributing

I welcome pull requests, bug fixes and issue reports. Before proposing a change, please discuss your change by raising an issue.

Maintainer 😎

Kumar Saurabh

License

MIT © Kumar Saurabh

Documentation ¶

Overview ¶

Package wazirx provides a client for using the Wazirx's Public Rest API. You can read the API server documentation at https://github.com/WazirX/wazirx-api

Usage:

create a new instance of Client, then use the various methods on the client to access different parts of the API. For demonstration:

  package main
  import (
	"context"
	"fmt"
	"log"

   	"github.com/itsksaurabh/go-wazirx"
 )

  func main() {
	client := wazirx.Client{}
	ctx := context.Background()

	data, err := client.MarketStatus(ctx)
	if err != nil {
		log.Fatal("request failed:", err)
	}
	fmt.Println(data)
  }

Notes: * Using the [https://godoc.org/context](https://godoc.org/context) package for passing context. * Look at tests(*_test.go) files for more sample usage.

Index ¶

Constants ¶

View Source
const (
	// DefaultBaseURL is the default server URL.
	DefaultBaseURL = "https://api.wazirx.com"
)

Variables ¶

This section is empty.

Functions ¶

func WithCtx ¶

func WithCtx(ctx context.Context, req *http.Request) *http.Request

WithCtx applies 'ctx' to the the http.Request and returns *http.Request The provided ctx and req must be non-nil

Types ¶

type Asset ¶

type Asset struct {
	// asset code
	Type string `json:"type"`
	// Display name of asset
	Name string `json:"name"`
	// Denotes whether deposit is enabled or disabled
	Deposit string `json:"deposit"`
	// Denotes whether withdrawal is enabled or disabled
	Withdrawal  string `json:"withdrawal"`
	ListingType string `json:"listingType"`
	Category    string `json:"category"`
	// Withdrawal fee of asset
	WithdrawFee float64 `json:"withdrawFee,omitempty"`
	// Minimum withdrawal amount in a single transaction
	MinWithdrawAmount float64 `json:"minWithdrawAmount,omitempty"`
	// Maximum withdrawal amount in a single transaction
	MaxWithdrawAmount float64 `json:"maxWithdrawAmount,omitempty"`
	// This is the min Deposit amount that will be accepted as deposit
	MinDepositAmount float64 `json:"minDepositAmount,omitempty"`
	// Is the min number of block height needed to confirm a block chain deposit transaction.
	Confirmations int `json:"confirmations,omitempty"`
}

Asset holds asset related data

type Client ¶

type Client struct {
	// HTTPClient is a reusable http client instance.
	HTTP *http.Client
	// BaseURL is the REST endpoints URL of the api server
	BaseURL *url.URL
}

Client for accessing different endpoints of the API

func (Client) Do ¶

func (c Client) Do(req *http.Request, target interface{}) error

Do sends the http.Request and unmarshalls the JSON response into 'target'

func (Client) MarketDepth ¶

func (c Client) MarketDepth(ctx context.Context, market string) (data MarketDepth, err error)

MarketDepth returs orderbook of any market. Pass any market to get the desired order book.

func (Client) MarketStatus ¶

func (c Client) MarketStatus(ctx context.Context) (data MarketStatus, err error)

MarketStatus returs overview of markets and assets

func (Client) MarketTicker ¶

func (c Client) MarketTicker(ctx context.Context) (data map[string]TickerData, err error)

MarketTicker returs the latest market heart-beat for all the markets for the last 24hrs.

func (Client) MarketTrade ¶

func (c Client) MarketTrade(ctx context.Context, market string) (data []MarketTrade, err error)

MarketTrade returs trade history of a market. Pass any market to get the desired trade history.

type ErrAPI ¶

type ErrAPI struct {
	// Response from the request which returned error.
	Response *http.Response
}

ErrAPI is returned by API calls when the response status code isn't 200.

func (ErrAPI) Error ¶

func (err ErrAPI) Error() (errStr string)

Error implements the error interface.

type Fee ¶

type Fee struct {
	Bid MakerTaker `json:"bid"`
	Ask MakerTaker `json:"ask"`
}

Fee holds bid and ask order's maker-taker fee percentage

func (*Fee) UnmarshalJSON ¶

func (f *Fee) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. Since `Fee` is returned as an map so it converts it into struct for better access

type MakerTaker ¶

type MakerTaker struct {
	Maker float64 `json:"maker"`
	Taker float64 `json:"taker"`
}

MakerTaker holds order's maker-taker

type Market ¶

type Market struct {
	// Ticker code of base asset
	BaseMarket string `json:"baseMarket"`
	// Ticker code of quote asset
	QuoteMarket string `json:"quoteMarket"`
	// Minimum buy amount of base asset
	MinBuyAmount float64 `json:"minBuyAmount,omitempty"`
	// Minumum sell amount of base asset
	MinSellAmount float64 `json:"minSellAmount,omitempty"`
	// Maximum precision of base asset, this the decimal point.
	BasePrecision int `json:"basePrecision,omitempty"`
	// Maximum precision of quote asset
	QuotePrecision int `json:"quotePrecision,omitempty"`
	// This defines the current state of the market. This can be active or suspended
	Status string `json:"status"`
	// JSON Object consists of bid and ask order's maker-taker fee percentage
	Fee Fee `json:"fee,omitempty"`
	// 24 hrs lowest price of base asset
	Low float64 `json:"low,omitempty"`
	// 24 hrs highest price of base asset
	High float64 `json:"high,omitempty"`
	// Last traded price in current market
	Last float64 `json:"last,omitempty"`
	// This defines the type of market, currently we have SPOT and P2P
	Type string `json:"type"`
	// Market Open price 24hrs ago
	Open float64 `json:"open,omitempty"`
	// Last 24hrs traded volume
	Volume float64 `json:"volume,omitempty"`
	// Top ask order price
	Sell float64 `json:"sell,omitempty"`
	// Top bid order price
	Buy                float64   `json:"buy,omitempty"`
	At                 time.Time `json:"at,omitempty"`
	MaxBuyAmount       float64   `json:"maxBuyAmount,omitempty"`
	MinBuyVolume       float64   `json:"minBuyVolume,omitempty"`
	MaxBuyVolume       float64   `json:"maxBuyVolume,omitempty"`
	FeePercentOnProfit float64   `json:"feePercentOnProfit,omitempty"`
}

Market holds market related data

func (*Market) UnmarshalJSON ¶ added in v1.1.1

func (m *Market) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. coverts some string type numeric to numeric type coverts Timestamp from `int` to unix timestamp

type MarketDepth ¶

type MarketDepth struct {
	Timestamp time.Time `json:"timestamp"`
	// list order's asks
	Asks []PriceVolume `json:"asks"`
	// list order's bids
	Bids []PriceVolume `json:"bids"`
}

MarketDepth holds orderbook data of a perticular market

func (*MarketDepth) UnmarshalJSON ¶

func (d *MarketDepth) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. converts slices into struct for better access and coverts Timestamp from `int` to unix timestamp

type MarketStatus ¶

type MarketStatus struct {
	Markets []Market `json:"markets"`
	Assets  []Asset  `json:"assets"`
}

MarketStatus holds the response from endpoint /api/v2/market-status

type MarketTrade ¶

type MarketTrade struct {
	ID        int64       `json:"id"`
	Price     float64     `json:"price"`
	Volume    float64     `json:"volume"`
	Funds     float64     `json:"funds"`
	Market    string      `json:"market"`
	CreatedAt time.Time   `json:"created_at"`
	Side      interface{} `json:"side"`
}

MarketTrade holds trade history of a perticular market

func (*MarketTrade) UnmarshalJSON ¶ added in v1.1.2

func (t *MarketTrade) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. It coverts some string type numeric to numeric types.

type PriceVolume ¶

type PriceVolume struct {
	PRICE  float64
	VOLUME float64
}

PriceVolume holds price and volume

type TickerData ¶

type TickerData struct {
	// ticker code of base market
	BaseUnit string `json:"base_unit"`
	// ticker code of quote asset
	QuoteUnit string `json:"quote_unit"`
	// 24 hrs lowest price of base asset
	Low float64 `json:"low"`
	// 24 hrs highest price of base asset
	High float64 `json:"high"`
	// Last traded price in current market
	Last float64 `json:"last"`
	Type string  `json:"type"`
	// Market Open price 24hrs ago
	Open interface{} `json:"open"`
	// Last 24hrs traded volume
	Volume float64 `json:"volume"`
	// Top ask order price
	Sell float64 `json:"sell"`
	// Top bid order price
	Buy float64 `json:"buy"`
	// Timestamp when ticker information is fetched
	At time.Time `json:"at"`
	// Display text of market
	Name string `json:"name"`
}

TickerData holds active market data with all ticker related values

func (*TickerData) UnmarshalJSON ¶ added in v1.1.1

func (t *TickerData) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. It coverts some string type numeric to numeric type and coverts Timestamp from `int` to unix timestamp

Jump to

Keyboard shortcuts

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