valr

package module
v0.0.0-...-730718a Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2021 License: MIT Imports: 16 Imported by: 0

README

VALR API

This Go package provides a wrapper for the VALR API.

Documentation

Please visit pkg.go.dev for the full package documentation.

Authentication

Please visit the API Keys page to generate an API key.

Installation

go get github.com/fritzkeyzer/valr-go
Example usage

A full working example of this library in action.

package main

import (
	"github.com/davecgh/go-spew/spew"
	"log"
	"github.com/fritzkeyzer/valr-go"
)

func main() {
	valrClient := valr.NewClient()
	//valrClient.SetDebug(true)
	//valrClient.SetAuth("<id>", "<secret>")
	err := valrClient.LoadAuthFile("env.yaml")
	if err != nil {
		log.Fatal(err)
	}

	res, err := valrClient.GetOrderBook("XRPZAR")
	if err != nil {
		log.Fatal(err)
	}

	spew.Dump(res)
}

Remember to substitute <id> and <secret> for your own Id and Secret. (Not recommended)

I recommend storing API Keys in a yaml file and using the LoadAuthFile function. For the above example env.yaml looks like this:

API_KEY: "abcdefghijklmnopABCDEFGHIJKLMNOP01234567890123456789012345678910"
API_SECRET: "abcdefghijklmnopABCDEFGHIJKLMNOP01234567890123456789012345678910"

Or exporting keys to environment variables, using a bash script:

$ export VALR_API_ID="<id>"
$ export VALR_API_SECRET="<secret>"

And then access them in Go like so:

import "os"

var API_KEY_ID string = os.Getenv("VALR_API_ID")
var API_KEY_SECRET string = os.Getenv("VALR_API_SECRET")

License

MIT

Documentation

Index

Constants

View Source
const Version = "0.0.01"

Variables

This section is empty.

Functions

func PrettyPrint

func PrettyPrint(jString string)

func PrettyPrintBytes

func PrettyPrintBytes(jBytes []byte) (string, error)

Types

type AccountBalance

type AccountBalance struct {
	Currency  string          `json:"currency"`
	Available decimal.Decimal `json:"available"`
	Reserved  decimal.Decimal `json:"reserved"`
	Total     decimal.Decimal `json:"total"`
	UpdatedAt time.Time       `json:"updatedAt"`
}

type ApiKey

type ApiKey struct {
	API_KEY    string `yaml:"API_KEY"`
	API_SECRET string `yaml:"API_SECRET"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient() *Client

func (*Client) GetBalances

func (cl *Client) GetBalances() ([]AccountBalance, error)

func (*Client) GetOrderBook

func (cl *Client) GetOrderBook(pair string) (GetOrderBookResponse, error)

func (*Client) GetPublicCurrencies

func (cl *Client) GetPublicCurrencies() ([]Currency, error)

Public

func (*Client) GetPublicOrderBook

func (cl *Client) GetPublicOrderBook(pair string) (GetOrderBookResponse, error)

Public

func (*Client) GetPublicOrderBookFull

func (cl *Client) GetPublicOrderBookFull(pair string) (GetOrderBookFullResponse, error)

Public

func (*Client) GetPublicOrderTypes

func (cl *Client) GetPublicOrderTypes() ([]OrderTypes, error)

Public

func (*Client) GetPublicPairs

func (cl *Client) GetPublicPairs() ([]CurrencyPair, error)

Public

func (*Client) GetTradeHistory

func (cl *Client) GetTradeHistory(pair string, skip int, limit int, startTime time.Time, stopTime time.Time) ([]TradeHistoryEntry, error)

func (*Client) LoadAuthFile

func (cl *Client) LoadAuthFile(filepath string) error

func (*Client) SendRequest

func (cl *Client) SendRequest(method string, path string) ([]byte, error)

func (*Client) SetAuth

func (cl *Client) SetAuth(apiKeyID, apiKeySecret string) error

func (*Client) SetBaseURL

func (cl *Client) SetBaseURL(baseURL string)

func (*Client) SetDebug

func (cl *Client) SetDebug(debug bool)

type Currency

type Currency struct {
	Symbol                  string    `json:"symbol"`
	IsActive                bool      `json:"isActive"`
	ShortName               string    `json:"shortName"`
	LongName                string    `json:"longName"`
	DecimalPlaces           quotedInt `json:"decimalPlaces" type:"integer"`
	WithdrawalDecimalPlaces quotedInt `json:"withdrawalDecimalPlaces"`
}

type CurrencyPair

type CurrencyPair struct {
	Symbol            string          `json:"symbol"`
	BaseCurrency      string          `json:"baseCurrency"`
	QuoteCurrency     string          `json:"quoteCurrency"`
	ShortName         string          `json:"shortName"`
	Active            bool            `json:"active"`
	MinBaseAmount     decimal.Decimal `json:"minBaseAmount"`
	MaxBaseAmount     decimal.Decimal `json:"maxBaseAmount"`
	MinQuoteAmount    decimal.Decimal `json:"minQuoteAmount"`
	MaxQuoteAmount    decimal.Decimal `json:"maxQuoteAmount"`
	TickSize          decimal.Decimal `json:"tickSize"`
	BaseDecimalPlaces quotedInt       `json:"baseDecimalPlaces"`
}

type GetOrderBookFullResponse

type GetOrderBookFullResponse struct {
	Asks      []OrderBookFullEntry `json:"Asks"`
	Bids      []OrderBookFullEntry `json:"Bids"`
	Timestamp time.Time            `json:"LastChange"`
}

type GetOrderBookResponse

type GetOrderBookResponse struct {
	Asks      []OrderBookEntry `json:"Asks"`
	Bids      []OrderBookEntry `json:"Bids"`
	Timestamp time.Time        `json:"LastChange"`
}

type OrderBookEntry

type OrderBookEntry struct {
	Side       string          `json:"side"`
	Quantity   decimal.Decimal `json:"quantity"`
	Price      decimal.Decimal `json:"price"`
	Pair       string          `json:"currencyPair"`
	OrderCount int             `json:"orderCount"`
}

type OrderBookFullEntry

type OrderBookFullEntry struct {
	Side            string          `json:"side"`
	Quantity        decimal.Decimal `json:"quantity"`
	Price           decimal.Decimal `json:"price"`
	Pair            string          `json:"currencyPair"`
	PositionAtPrice int             `json:"positionAtPrice"`
}

type OrderTypes

type OrderTypes struct {
	CurrencyPair string   `json:"currencyPair"`
	OrderTypes   []string `json:"orderTypes"`
}

type TradeHistoryEntry

type TradeHistoryEntry struct {
	Price        decimal.Decimal `json:"price"`
	Quantity     decimal.Decimal `json:"quantity"`
	CurrencyPair string          `json:"currencyPair"`
	TradedAt     time.Time       `json:"tradedAt"`
	TakerSide    string          `json:"takerSide"`
	SequenceId   int             `json:"sequenceId"`
	Id           string          `json:"id"`
	QuoteVolume  decimal.Decimal `json:"quoteVolume"`
}

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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