TokensApi

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

README

TokensApi

Build Status forthebadge forthebadge

An (unoffical) library in Go(lang) to use the API of the cryptocurrency exchange Tokens

Warning: this library is provided as-is, contributors are not liable for any kind of damages including, but not limited to, financial loss!

I tried to learn golang by doing. Therefore there might be some ugly parts inside the code. However it follows some idiomatic patterns (like returning err object).

Example

package test

import (
    api "github.com/fiksn/TokensApi"
    entities "github.com/fiksn/TokensApi/entities"
)

resp, err := api.GetTicker("btcusdt", api.Day)

Before you are able to call private methods, you need to invoke:

err := api.Init("./credentials")

and provide a JSON file like credentials.example with your API credentials.

Then you can do for instance:

balance, err := api.GetBalance("usdt")

Hints

Try the PlaceOrderTyped() method to avoid problems with type-safety. Placing an order will not make it immediately available, expect to get "131 Invalid order id" back occasionally when querying for it.

Rate limits

Unofficial information: public requests are not intentionally rate-limited (they are cached anyway so more than 1 req/sec doesn't make sense), private ones are limited to 300 requests/minute and then (at least) 1 min firewall is applied.

Tipping

If you like it you can send some ether or abandoned kitties to 0xFF0da2B849aAbd5F37265190fFe1a64D4Febb52D ;)

I am also a fan of Bitcoin Lightning:

tippin.me

Documentation

Index

Constants

View Source
const (
	// Base URL for API calls
	TokensBaseUrl = "https://api.tokens.net"
	// Percentage fee for takers
	TakerFeePercent = 0.2
	// Percentage fee for makers
	MakerFeePercent = 0
)
View Source
const (
	Day = iota
	Hour
)
View Source
const (
	Min1 = iota
	Min5
	Min10
	Min30
	Day1
)
View Source
const (
	Timeout = time.Duration(5 * time.Second)
)

Variables

View Source
var (
	Credentials  *CredentialsConfig
	NullHookFunc = func(code int, reason string) {}
	HookFunc     = NullHookFunc
)

Functions

func CancelAllOrders

func CancelAllOrders() error

*

  • Cancel all outstanding orders.

func CancelOrder

func CancelOrder(id uuid.UUID) (entities.Base, error)

*

  • Cancel an order by id.

func GetAllBalances

func GetAllBalances() (entities.AllBalanceResp, error)

* * Get all balances.

func GetAllCurrencies

func GetAllCurrencies() ([]string, error)

* * Get all supported currency codes. * See GetCurrencies()

func GetAllOrders

func GetAllOrders() (entities.OrdersResp, error)

*

  • Get all orders.

func GetAllOrdersFor

func GetAllOrdersFor(pair string) (entities.OrdersResp, error)

*

  • Get all orders for currency pair.

func GetAllTransactions

func GetAllTransactions() (entities.TransactionResp, error)

*

  • Get transactions. WARNING might take a while.

func GetBalance

func GetBalance(currency string) (entities.BalanceResp, error)

* * Get balance.

func GetBalances

func GetBalances(hideZero bool) map[string]*entities.BalanceResp

* * Get balances.

func GetCandles added in v0.0.2

func GetCandles(pair string, interval CandleInterval, from, to time.Time) (entities.CandlesResp, error)

*

  • Get candles.

func GetCurrencies added in v0.0.2

func GetCurrencies() (entities.CurrencyResp, error)

*

  • Get currencies (and some basic info).

func GetDepositAddress added in v0.0.2

func GetDepositAddress(currency string) (entities.DepositAddrResp, error)

*

  • Get deposit address for given currency (note you need API key of Main account)

func GetOrderBook

func GetOrderBook(pair string) (entities.OrderBookResp, error)

* * Get order book.

func GetOrderDetails

func GetOrderDetails(id uuid.UUID) (entities.OrderDetailsResp, error)

*

  • Get order details.

func GetTicker

func GetTicker(pair string, interval TickerInterval) (entities.TickerResp, error)

* * Get ticker for last day or hour.

func GetTrades

func GetTrades(pair string, interval TickerInterval) (entities.TradesResp, error)

* * List trades, which occured in last minute, hour or day.

func GetTradingPairs

func GetTradingPairs() (entities.TradingPairResp, error)

* * List all existing pairs.

func GetTransactions

func GetTransactions(page int) (entities.TransactionResp, error)

*

  • Get transactions. Page parameter starts from 1 and goes to max (which you get from TransactionResp.TotalPages)

func GetVotes

func GetVotes() (entities.VotesResp, error)

*

  • List all currencies participating in voting and number of votes for each currency.

func Init

func Init(configPath string) error

func InstallErrorHook

func InstallErrorHook(f ErrorHook)

func PlaceOrder

func PlaceOrder(
	pair string,
	side entities.OrderType,
	amount float64,
	amountDecimals int,
	price float64,
	priceDecimals int,
	takeProfitPrice float64,
	expireDate *time.Time) (entities.PlaceOrderResp, error)

*

  • Place an order.

func PlaceOrderTyped

func PlaceOrderTyped(
	pair *entities.TradingPair,
	side entities.OrderType,
	amount Amount,
	price Price,
	takeProfitPrice *Price,
	expireDate *time.Time) (entities.PlaceOrderResp, error)

*

  • Place an order in a type-safe manner to avoid (costly) mistakes.

func UninstallErrorHook

func UninstallErrorHook()

Types

type Amount

type Amount float64

type CandleInterval added in v0.0.2

type CandleInterval int

type CandleIntervalSpec added in v0.0.2

type CandleIntervalSpec struct {
	Interval string
	Number   int
}

type CredentialsConfig

type CredentialsConfig struct {
	APIKey    string `json:"key" description:"Api key."`
	APISecret string `json:"secret" description:"Api secret."`
}

type ErrorHook

type ErrorHook func(int, string)

type Price

type Price float64

type TickerInterval added in v0.0.2

type TickerInterval int

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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