livecoin

package module
v0.0.0-...-2a2b92e Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: MIT Imports: 15 Imported by: 0

README

go-livecoin

go-livecoin is an implementation of the livecoin API (public and private) in Golang.

This version implement V1.1 livecoin API and the new HMAC authentification.

Import

import "github.com/Tomiyou/go-livecoin"

Usage

In order to use the client with go's default http client settings you can do:

package main

import (
	"fmt"
	"github.com/Tomiyou/go-livecoin"
)

const (
	API_KEY    = "YOUR_API_KEY"
	API_SECRET = "YOUR_API_SECRET"
)

func main() {
	// livecoin client
	livecoin := livecoin.New(API_KEY, API_SECRET)

	// Get balances
	balances, err := livecoin.GetBalances()
	fmt.Println(err, balances)
}

In order to use custom settings for the http client do:

package main

import (
	"fmt"
	"net/http"
	"time"
	"github.com/Tomiyou/go-livecoin"
)

const (
	API_KEY    = "YOUR_API_KEY"
	API_SECRET = "YOUR_API_SECRET"
)

func main() {
	httpClient := &http.Client{
		Timeout: time.Second * 10,
	}

	// livecoin client
	bc := livecoin.NewWithCustomHttpClient(conf.livecoin.ApiKey, conf.livecoin.ApiSecret, httpClient)

	// Get balances
	balances, err := livecoin.GetBalances()
	fmt.Println(err, balances)
}

See "Examples" folder for more... examples

Documentation

Overview

Package Livecoin is an implementation of the Livecoin API in Golang.

Index

Constants

View Source
const (
	API_BASE = "https://api.livecoin.net" // Livecoin API endpoint
)

Variables

This section is empty.

Functions

func NewClient

func NewClient(apiKey, apiSecret string) (c *client)

NewClient return a new Livecoin HTTP client

func NewClientWithCustomHttpConfig

func NewClientWithCustomHttpConfig(apiKey, apiSecret string, httpClient *http.Client) (c *client)

NewClientWithCustomHttpConfig returns a new Livecoin HTTP client using the predefined http client

func NewClientWithCustomTimeout

func NewClientWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) (c *client)

NewClient returns a new Livecoin HTTP client with custom timeout

Types

type Balance

type Balance struct {
	Type     string          `json:"type"`
	Currency string          `json:"currency"`
	Value    decimal.Decimal `json:"value"`
}

type CancelledOrder

type CancelledOrder struct {
	Success       bool            `json:"success"`
	Cancelled     bool            `json:"cancelled"`
	Exception     string          `json:"exception"`
	Quantity      decimal.Decimal `json:"quantity"`
	TradeQuantity decimal.Decimal `json:"tradeQuantity"`
}

type DepositAddress

type DepositAddress struct {
	Currency string `json:"currency"`
	UserID   int    `json:"userId"`
	UserName string `json:"userName"`
	Wallet   string `json:"wallet"`
}

type Livecoin

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

livecoin represent a livecoin client

func New

func New(apiKey, apiSecret string) *Livecoin

New returns an instantiated livecoin struct

func NewWithCustomHttpClient

func NewWithCustomHttpClient(apiKey, apiSecret string, httpClient *http.Client) *Livecoin

NewWithCustomHttpClient returns an instantiated livecoin struct with custom http client

func NewWithCustomTimeout

func NewWithCustomTimeout(apiKey, apiSecret string, timeout time.Duration) *Livecoin

NewWithCustomTimeout returns an instantiated livecoin struct with custom timeout

func (*Livecoin) BuyLimit

func (b *Livecoin) BuyLimit(market string, quantity, rate decimal.Decimal) (order NewOrder, err error)

BuyLimit is used to place a buy order (limit) for particular currency pair.

func (*Livecoin) BuyMarket

func (b *Livecoin) BuyMarket(market string, quantity decimal.Decimal) (order NewOrder, err error)

BuyMarket is used to place a buy order (market) of specified amount for particular currency pair.

func (*Livecoin) CancelOrder

func (b *Livecoin) CancelOrder(market, orderId string) (cancelledOrder CancelledOrder, err error)

CancelOrder is used to cancel an order. NOTE: market orders CANNOT be cancelled

func (*Livecoin) GetAllOrderBook

func (b *Livecoin) GetAllOrderBook() (allOrderbook map[string]Orderbook, err error)

GetAllOrderBook is used to retrieve the orderbook for every currency pair.

func (*Livecoin) GetBalance

func (b *Livecoin) GetBalance(currency string) (balance Balance, err error)

Getbalance is used to retrieve the balance from your account for a specific currency. currency: a string literal for the currency (ex: LTC)

func (*Livecoin) GetBalances

func (b *Livecoin) GetBalances() (balances []Balance, err error)

GetBalances is used to retrieve all balances from your account

func (*Livecoin) GetDepositAddress

func (b *Livecoin) GetDepositAddress(currency string) (address DepositAddress, err error)

GetDepositAddress is used to get the deposit address for a specific currency

func (*Livecoin) GetOrder

func (b *Livecoin) GetOrder(orderId string) (orderInfo OrderInfo, err error)

GetOrder is used to retrieve order information by its ID.

func (*Livecoin) GetOrderBook

func (b *Livecoin) GetOrderBook(currency string) (orderbook Orderbook, err error)

GetOrderBook is used to retrieve the orderbook for specified currency pair

func (*Livecoin) GetRestrictions

func (b *Livecoin) GetRestrictions() (restrictions Restrictions, err error)

GetRestrictions is used to retrieve the restrictions of all currency pairs

func (*Livecoin) GetTrades

func (b *Livecoin) GetTrades(currencyPair string) (trades []Trade, err error)

GetTrades used to retrieve your trade history. market string literal for the market (ie. BTC/LTC). If set to "all", will return for all market

func (*Livecoin) GetTransactions

func (b *Livecoin) GetTransactions(start uint64, end uint64) (transactions []Transaction, err error)

GetTransactions is used to retrieve your withdrawal and deposit history "Start" and "end" are given in UNIX timestamp format in miliseconds and used to specify the date range for the data returned.

func (*Livecoin) SellLimit

func (b *Livecoin) SellLimit(market string, quantity, rate decimal.Decimal) (order NewOrder, err error)

SellLimit is used to place a sell order (limit) for a specified currency pair.

func (*Livecoin) SellMarket

func (b *Livecoin) SellMarket(market string, quantity decimal.Decimal) (order NewOrder, err error)

SellMarket is used to place a sell order (market) for specified amount of selected currency pair.

func (*Livecoin) SetDebug

func (c *Livecoin) SetDebug(enable bool)

set enable/disable http request/response dump

func (*Livecoin) Withdraw

func (b *Livecoin) Withdraw(wallet, currency string, quantity decimal.Decimal) (withdrawal Withdrawal, err error)

Withdraw is used to place a sell order (limit) for a specified currency pair.

type NewOrder

type NewOrder struct {
	Success bool   `json:"success"`
	Added   bool   `json:"added"`
	OrderId uint64 `json:"orderId"`
}

type OrderInfo

type OrderInfo struct {
	Id                uint64          `json:"id"`
	ClientId          uint64          `json:"client_id"`
	Status            string          `json:"status"`
	TickerPair        string          `json:"symbol"`
	Price             decimal.Decimal `json:"price"`
	Quantity          decimal.Decimal `json:"quantity"`
	RemainingQuantity decimal.Decimal `json:"remaining_quantity"`
	Blocked           decimal.Decimal `json:"blocked"`
	BlockedRemain     decimal.Decimal `json:"blocked_remain"`
	CommissionRate    decimal.Decimal `json:"commission_rate"`
	Trades            interface{}     `json:"trades"`
}

type Orderbook

type Orderbook struct {
	Asks      []OrderbookPair `json:"asks"`
	Bids      []OrderbookPair `json:"bids"`
	Timestamp int64           `json:"timestamp"`
}

type OrderbookPair

type OrderbookPair struct {
	Price     decimal.Decimal
	Quantity  decimal.Decimal
	Timestamp int64
}

func (*OrderbookPair) UnmarshalJSON

func (p *OrderbookPair) UnmarshalJSON(buf []byte) error

type Restriction

type Restriction struct {
	CurrencyPair     string          `json:"currencyPair"`
	MinLimitQuantity decimal.Decimal `json:"minLimitQuantity"`
	PriceScale       int             `json:"priceScale"`
}

type Restrictions

type Restrictions struct {
	Success      bool            `json:"success"`
	MinBtcVolume decimal.Decimal `json:"minBtcVolume"`
	Restrictions []Restriction   `json:"restrictions"`
}

type Trade

type Trade struct {
	Id            uint64          `json:"id"`
	ClientOrderId uint64          `json:"clientorderid"`
	Type          string          `json:"type"`
	Symbol        string          `json:"symbol"`
	Date          time.Time       `json:"datetime"`
	Price         decimal.Decimal `json:"price"`
	Quantity      decimal.Decimal `json:"quantity"`
	Commission    decimal.Decimal `json:"commission"`
}

func (*Trade) UnmarshalJSON

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

type Transaction

type Transaction struct {
	Id            string          `json:"id"`
	Type          string          `json:"type"`
	Date          time.Time       `json:"date"`
	Amount        decimal.Decimal `json:"amount"`
	Fee           decimal.Decimal `json:"fee"`
	FixedCurrency string          `json:"fixedCurrency"`
	TaxCurrency   string          `json:"taxCurrency"`
	External      string          `json:"external"`
	ExternalKey   string          `json:"externalKey"`
	Login         string          `json:"login"`
}

func (*Transaction) UnmarshalJSON

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

type Withdrawal

type Withdrawal struct {
	Fault                interface{}     `json:"fault"`
	UserId               int64           `json:"userId"`
	UserName             string          `json:"userName"`
	Id                   int64           `json:"id"`
	State                string          `json:"state"`
	CreateDate           int64           `json:"createDate"`
	LastModifyDate       int64           `json:"lastModifyDate"`
	VerificationType     string          `json:"verificationType"`
	VerificationData     interface{}     `json:"verificationData"`
	Comment              interface{}     `json:"comment"`
	Description          string          `json:"description"`
	Amount               decimal.Decimal `json:"amount"`
	Currency             string          `json:"currency"`
	AccountTo            string          `json:"accountTo"`
	AcceptDate           interface{}     `json:"acceptDate"`
	ValueDate            interface{}     `json:"valueDate"`
	DocDate              int64           `json:"docDate"`
	DocNumber            int64           `json:"docNumber"`
	CorrespondentDetails interface{}     `json:"correspondentDetails"`
	AccountFrom          string          `json:"accountFrom"`
	Outcome              bool            `json:"outcome"`
	External             interface{}     `json:"external"`
	ExternalKey          string          `json:"externalKey"`
	ExternalSystemId     int             `json:"externalSystemId"`
	ExternalServiceId    interface{}     `json:"externalServiceId"`
	Wallet               string          `json:"wallet"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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