liquid

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 20 Imported by: 0

README

go-liquid

Liquid by Quoine API version2

Description

go-liquid is a go client library for Liquid by Quoine API.

Installation

$ go get -u github.com/go-numb/go-liquid

Usage

package main

import (
 "fmt"
 "github.com/go-numb/go-liquid"
)


func main() {
	client := liquid.New("<tokenID number>", "<secretkey>", nil)

	fiat, err := client.GetFiatAccounts()
	if err != nil {
	    fmt.Println(err)
	}

	fmt.Printf("%v\n", fiat)

	doSomething()
}

Usage for websocket(pusher)

package main

import (
	"fmt"
	"github.com/go-numb/go-liquid"
)


func Method(t *testing.T) {
	done := make(chan struct{})

	// for recive response data
	realtime := NewConnect()
	// Connect is reading channels in for loop
	go realtime.Connect([]string{PUSHERchEXECUTION, PUSHERchASK, PUSHERchBID}, []string{BTCJPY, ETHJPY})

	// use result data
	// data in struct
	for {
		select {
		case result := <-realtime.Results:
			fmt.Printf("result: %+v\n", result)
		}
	}

	<-done
}

Author

@_numbP

License

MIT

Documentation

Index

Constants

View Source
const (
	BASEURL = "https://api.liquid.com"
	VERSION = "2"

	FUNDJPY = "JPY"
	FUNDUSD = "USD"

	LIMIT  = "limit"
	MARKET = "market"
	BUY    = "buy"
	SELL   = "sell"

	NETOUT       = "netout"
	ONEDIRECTION = "one_direction"
	TWODIRECTION = "two_direction"

	APILIMIT = 300 // par 5minutes
)
View Source
const (
	PUSHERAPPNAME           = ""
	PUSHERKEY               = "LIQUID"
	PUSHERTAPHOST           = "tap.liquid.com"
	PUSHERchEXECUTION       = "executions_cash_%s"
	PUSHERchDETAILEXECUTION = "execution_details_cash_%s"
	PUSHERchUSEREXECUTION   = "user_executions_cash_%s"
	PUSHERchASK             = "price_ladders_cash_%s_sell"
	PUSHERchBID             = "price_ladders_cash_%s_buy"
	PUSHERCREATED           = "created"
	PUSHERUPDATE            = "updated"

	BTCJPY  = "btcjpy"
	BTCUSD  = "btcusd"
	ETHJPY  = "ethjpy"
	ETHUSD  = "ethusd"
	XRPJPY  = "xrpjpy"
	XRPUSD  = "xrpusd"
	QASHJPY = "qashjpy"
)
View Source
const (
	PRODUCT5_BTCJPY int
)

Variables

This section is empty.

Functions

func ToPriceString

func ToPriceString(price float64) string

ToPriceString is float to string price.00001

func ToQtyString

func ToQtyString(size float64) string

ToQtyString is float to string size.001

Types

type Account

type Account struct {
	ID                       int       `json:"id"`
	Currency                 string    `json:"currency"`
	CurrencySymbol           string    `json:"currency_symbol"`
	Balance                  float64   `json:"balance,string"`
	PusherChannel            string    `json:"pusher_channel"`
	LowestOfferInterestRate  float64   `json:"lowest_offer_interest_rate,string"`
	HighestOfferInterestRate float64   `json:"highest_offer_interest_rate,string"`
	ExchangeRate             big.Float `json:"exchange_rate,string"`
	CurrencyType             string    `json:"currency_type"`
}

type AccountBalance

type AccountBalance struct {
	Currency string `json:"currency"`
	Balance  string `json:"balance"`
}

type AccountBalanceV2 added in v1.0.3

type AccountBalanceV2 struct {
	CryptoAccounts []struct {
		ID                       int         `json:"id,omitempty"`
		Currency                 string      `json:"currency,omitempty"`
		Balance                  string      `json:"balance,omitempty"`
		ReservedBalance          string      `json:"reserved_balance,omitempty"`
		PusherChannel            string      `json:"pusher_channel,omitempty"`
		LowestOfferInterestRate  interface{} `json:"lowest_offer_interest_rate,omitempty"`
		HighestOfferInterestRate interface{} `json:"highest_offer_interest_rate,omitempty"`
		Address                  interface{} `json:"address,omitempty"`
		CurrencySymbol           string      `json:"currency_symbol,omitempty"`
		MinimumWithdraw          interface{} `json:"minimum_withdraw,omitempty"`
		CurrencyType             string      `json:"currency_type,omitempty"`
	} `json:"crypto_accounts,omitempty"`
	FiatAccounts []struct {
		ID                       int         `json:"id,omitempty"`
		Currency                 string      `json:"currency,omitempty"`
		Balance                  string      `json:"balance,omitempty"`
		ReservedBalance          string      `json:"reserved_balance,omitempty"`
		PusherChannel            string      `json:"pusher_channel,omitempty"`
		LowestOfferInterestRate  interface{} `json:"lowest_offer_interest_rate,omitempty"`
		HighestOfferInterestRate interface{} `json:"highest_offer_interest_rate,omitempty"`
		CurrencySymbol           string      `json:"currency_symbol,omitempty"`
		SendToBtcAddress         interface{} `json:"send_to_btc_address,omitempty"`
		ExchangeRate             string      `json:"exchange_rate,omitempty"`
		CurrencyType             string      `json:"currency_type,omitempty"`
	} `json:"fiat_accounts,omitempty"`
}

type Books

type Books [][]json.Number

type Client

type Client struct {
	URL         *url.URL
	TokenNumber string
	Secret      string
	HTTPClient  *http.Client

	Logger *log.Logger
}

func New

func New(tokenNum string, secret string, logger *log.Logger) (*Client, error)

func (*Client) CancelOrder

func (c *Client) CancelOrder(orderID int) (Order, error)

func (*Client) CloseAllTrade

func (c *Client) CloseAllTrade(side string) ([]Trade, error)

func (*Client) CloseLoanBid

func (c *Client) CloseLoanBid(loanBidID int) (LoanBid, error)

func (*Client) CloseTrade

func (c *Client) CloseTrade(tradeID int, closedQuantity float64) (Trade, error)

func (*Client) CreateFiatAccount

func (c *Client) CreateFiatAccount(currency string) (Account, error)

func (*Client) CreateLoanBid

func (c *Client) CreateLoanBid(quantity, currency, rate string) (LoanBid, error)

func (*Client) CreateOrder

func (c *Client) CreateOrder(o *RequestOrder) (Order, error)

orderType, side, quantity, price, priceRange string, productID int

func (*Client) EditLiveOrder

func (c *Client) EditLiveOrder(id int, e *EditOrderParams) (Order, error)

func (c *Client) EditLiveOrder(orderID int, quantity, price string) (Order, error) {

func (*Client) GetATradingAccount

func (c *Client) GetATradingAccount(tradingAccountID int) (TradingAccount, error)

func (*Client) GetAllAccountBalances

func (c *Client) GetAllAccountBalances() ([]AccountBalance, error)

func (*Client) GetAllAccountBalancesV2 added in v1.0.3

func (c *Client) GetAllAccountBalancesV2() (AccountBalanceV2, error)

func (*Client) GetCryptoAccounts

func (c *Client) GetCryptoAccounts() ([]CryptoAccount, error)

func (*Client) GetExecutions

func (c *Client) GetExecutions(productID int, limit int, page int) (Executions, error)

func (*Client) GetExecutionsByTimestamp

func (c *Client) GetExecutionsByTimestamp(
	productID int,
	limit int,
	timestamp int) ([]ExecutionsModels, error)

func (*Client) GetFiatAccounts

func (c *Client) GetFiatAccounts() ([]Account, error)

func (*Client) GetInterestRates

func (c *Client) GetInterestRates(currency string) (InterestRates, error)

func (*Client) GetLoanBids

func (c *Client) GetLoanBids(currency string) (LoanBids, error)

func (*Client) GetLoans

func (c *Client) GetLoans(currency string) (Loans, error)

func (*Client) GetOrder

func (c *Client) GetOrder(orderID int) (Order, error)

func (*Client) GetOrderBook

func (c *Client) GetOrderBook(productID int, full bool) (Depth, error)

func (*Client) GetOrderByClientID

func (c *Client) GetOrderByClientID(clientID string) (Order, error)

func (*Client) GetOrderTrades

func (c *Client) GetOrderTrades(orderID int) ([]Trade, error)

func (*Client) GetOrders

func (c *Client) GetOrders(filters OrdersFilter) (Order, error)

func (*Client) GetOwnExecutions

func (c *Client) GetOwnExecutions(productID int) (Executions, error)

func (*Client) GetProduct

func (c *Client) GetProduct(productID int) (Product, error)

func (*Client) GetProducts

func (c *Client) GetProducts() ([]Product, error)

func (*Client) GetTrades

func (c *Client) GetTrades(fundingCurrency, status string) (Trades, error)

func (*Client) GetTradesLoans

func (c *Client) GetTradesLoans(tradeID int) ([]Loan, error)

func (*Client) GetTradingAccounts

func (c *Client) GetTradingAccounts() ([]TradingAccount, error)

func (*Client) UpdateALoan

func (c *Client) UpdateALoan(loanID int, fundReloaned bool) (Loan, error)

func (*Client) UpdateLeverageLevel

func (c *Client) UpdateLeverageLevel(tradeAccountID, leverageLevel int) (TradingAccount, error)

func (*Client) UpdateTrade

func (c *Client) UpdateTrade(tradeID, stopLoss, takeProfit int) (Trade, error)

type CryptoAccount

type CryptoAccount struct {
	ID                       int     `json:"id"`
	Balance                  string  `json:"balance"`
	Address                  string  `json:"address"`
	Currency                 string  `json:"currency"`
	CurrencySymbol           string  `json:"currency_symbol"`
	PusherChannel            string  `json:"pusher_channel"`
	MinimumWithdraw          float64 `json:"minimum_withdraw"`
	LowestOfferInterestRate  string  `json:"lowest_offer_interest_rate"`
	HighestOfferInterestRate string  `json:"highest_offer_interest_rate"`
	CurrencyType             string  `json:"currency_type"`
}

type Depth

type Depth struct {
	BuyPriceLevels  Books `json:"buy_price_levels"`
	SellPriceLevels Books `json:"sell_price_levels"`
}

func (*Depth) GetBuyDepthFloat64

func (p *Depth) GetBuyDepthFloat64() [][]float64

func (*Depth) GetSellDepthFloat64

func (p *Depth) GetSellDepthFloat64() [][]float64

func (*Depth) SortBuyDepthByPrice

func (p *Depth) SortBuyDepthByPrice(order string) [][]float64

func (*Depth) SortBuyDepthByQuontity

func (p *Depth) SortBuyDepthByQuontity() [][]float64

func (*Depth) SortSellDepthByPrice

func (p *Depth) SortSellDepthByPrice(order string) [][]float64

func (*Depth) SortSellDepthByQuontity

func (p *Depth) SortSellDepthByQuontity() [][]float64

type EditOrderParams

type EditOrderParams struct {
	Quantity string `json:"quantity"`
	Price    string `json:"price"`
}

type Executions

type Executions struct {
	Models      []ExecutionsModels `json:"models"`
	CurrentPage int                `json:"current_page"`
	TotalPages  int                `json:"total_pages"`
}

type ExecutionsModels

type ExecutionsModels struct {
	ID        int     `json:"id"`
	Quantity  float64 `json:"quantity,string"`
	Price     float64 `json:"price,string"`
	TakerSide string  `json:"taker_side"`
	MySide    string  `json:"my_side"`
	CreatedAt int64   `json:"created_at"`
}

type InterestRates

type InterestRates struct {
	Bids [][]string `json:"bids"`
	Asks [][]string `json:"asks"`
}

type Limit

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

Limit is managed API Limit

func NewLimit

func NewLimit(isPrivate bool) *Limit

func (*Limit) Check

func (p *Limit) Check() error

Check is api limit

func (*Limit) Remain

func (p *Limit) Remain() int

Remain is remain number of API limit

func (*Limit) ResetAPI

func (p *Limit) ResetAPI()

ResetAPI is resets api limit at every 5minutes

type Loan

type Loan struct {
	ID           int    `json:"id"`
	Quantity     string `json:"quantity"`
	Rate         string `json:"rate"`
	CreatedAt    int64  `json:"created_at"`
	LenderID     int    `json:"lender_id"`
	BorrowerID   int    `json:"borrower_id"`
	Status       string `json:"status"`
	Currency     string `json:"currency"`
	FundReloaned bool   `json:"fund_reloaned"`
}

type LoanBid

type LoanBid struct {
	ID             int     `json:"id"`
	BidaskType     string  `json:"bidask_type"`
	Quantity       float64 `json:"quantity,string"`
	Currency       string  `json:"currency"`
	Side           string  `json:"side"`
	FilledQuantity float64 `json:"filled_quantity,string"`
	Status         string  `json:"status"`
	Rate           float64 `json:"rate,string"`
	UserID         int     `json:"user_id"`
}

type LoanBids

type LoanBids struct {
	Models      []LoanBid `json:"models"`
	CurrentPage int       `json:"current_page"`
	TotalPages  int       `json:"total_pages"`
}

type Loans

type Loans struct {
	Models      []*Loan `json:"models"`
	CurrentPage int     `json:"current_page"`
	TotalPages  int     `json:"total_pages"`
}

type Order

type Order struct {
	ID                        int64           `json:"id,omitempty"`
	OrderType                 string          `json:"order_type,omitempty"`
	Quantity                  decimal.Decimal `json:"quantity,omitempty"`
	DiscQuantity              decimal.Decimal `json:"disc_quantity,omitempty"`
	IcebergTotalQuantity      decimal.Decimal `json:"iceberg_total_quantity,omitempty"`
	Side                      string          `json:"side,omitempty"`
	FilledQuantity            decimal.Decimal `json:"filled_quantity,omitempty"`
	Price                     decimal.Decimal `json:"price,omitempty"`
	CreatedAt                 int             `json:"created_at,omitempty"`
	UpdatedAt                 int             `json:"updated_at,omitempty"`
	Status                    string          `json:"status,omitempty"`
	LeverageLevel             int             `json:"leverage_level,omitempty"`
	SourceExchange            interface{}     `json:"source_exchange,omitempty"`
	ProductID                 int             `json:"product_id,omitempty"`
	MarginType                interface{}     `json:"margin_type,omitempty"`
	TakeProfit                interface{}     `json:"take_profit,omitempty"`
	StopLoss                  interface{}     `json:"stop_loss,omitempty"`
	TradingType               string          `json:"trading_type,omitempty"`
	ProductCode               string          `json:"product_code,omitempty"`
	FundingCurrency           string          `json:"funding_currency,omitempty"`
	CryptoAccountID           interface{}     `json:"crypto_account_id,omitempty"`
	CurrencyPairCode          string          `json:"currency_pair_code,omitempty"`
	AveragePrice              decimal.Decimal `json:"average_price,omitempty"`
	Target                    string          `json:"target,omitempty"`
	OrderFee                  decimal.Decimal `json:"order_fee,omitempty"`
	SourceAction              string          `json:"source_action,omitempty"`
	UnwoundTradeID            interface{}     `json:"unwound_trade_id,omitempty"`
	TradeID                   interface{}     `json:"trade_id,omitempty"`
	ClientOrderID             string          `json:"client_order_id,omitempty"`
	Settings                  interface{}     `json:"settings,omitempty"`
	TrailingStopType          interface{}     `json:"trailing_stop_type,omitempty"`
	TrailingStopValue         interface{}     `json:"trailing_stop_value,omitempty"`
	StopTriggeredTime         interface{}     `json:"stop_triggered_time,omitempty"`
	MarginUsed                decimal.Decimal `json:"margin_used,omitempty"`
	MarginInterest            decimal.Decimal `json:"margin_interest,omitempty"`
	UnwoundTradeLeverageLevel interface{}     `json:"unwound_trade_leverage_level,omitempty"`
}

type OrderExecutions

type OrderExecutions []struct {
	ID        int     `json:"id"`
	Quantity  float64 `json:"quantity,string"`
	Price     float64 `json:"price,string"`
	TakerSide string  `json:"taker_side"`
	MySide    string  `json:"my_side"`
	CreatedAt int64   `json:"created_at"`
}

type OrderParams

type OrderParams struct {
	OrderType  string `json:"order_type"` // limit, market or market_with_range
	ProductID  int    `json:"product_id"`
	Side       string `json:"side"`
	Quantity   string `json:"quantity"`
	Price      string `json:"price,omitempty"`
	PriceRange string `json:"price_range,omitempty"` // order type optional
	// Margin trade
	LeverageLevel   int    `json:"leverage_level,omitempty"`
	FundingCurrency string `json:"funding_currency,omitempty"`
	OrderDirection  string `json:"order_direction,omitempty"`
	// CFD Optionals
	TradingType string `json:"trading_type,omitempty"` // margin or cfd, only available if leverage_level > 1
	MarginType  string `json:"margin_type,omitempty"`  // cross or isolated, only available if leverage_level > 1, default is cross

	// ClientID
	ClientOrderID string `json:"client_order_id,omitempty"`
}

type Orders

type Orders struct {
	Models      []Order `json:"models"`
	CurrentPage int     `json:"current_page"`
	TotalPages  int     `json:"total_pages"`
}

type OrdersFilter

type OrdersFilter struct {
	ProductID       string `json:"product_id,omitempty"`
	WithDetails     string `json:"with_details,omitempty"`
	Status          string `json:"status,omitempty"`
	FundingCurrency string `json:"funding_currency,omitempty"`

	// 下記Doc非公開フィルター
	// WebAPI: page=1&limit=24&currency_pair_code=BTCJPY&status=live&trading_type=cfd
	Page             string `json:"page,omitempty"`
	Limit            string `json:"limit,omitempty"`
	CurrencyPairCode string `json:"currency_pair_code,omitempty"`
	TradingType      string `json:"trading_type,omitempty"`
}

type Product

type Product struct {
	ID                  string  `json:"id"`
	ProductType         string  `json:"product_type"`
	Code                string  `json:"code"`
	Name                string  `json:"name"`
	MarketAsk           float64 `json:"market_ask,string"`
	MarketBid           float64 `json:"market_bid,string"`
	Indicator           int     `json:"indicator"`
	Currency            string  `json:"currency"`
	CurrencyPairCode    string  `json:"currency_pair_code"`
	Symbol              string  `json:"symbol"`
	FiatMinimumWithdraw float64 `json:"fiat_minimum_withdraw,string"`
	PusherChannel       string  `json:"pusher_channel"`
	TakerFee            float64 `json:"taker_fee,string"`
	MakerFee            float64 `json:"maker_fee,string"`
	LowMarketBid        float64 `json:"low_market_bid,string"`
	HighMarketAsk       float64 `json:"high_market_ask,string"`
	Volume24H           float64 `json:"volume_24h,string"`
	LastPrice24H        float64 `json:"last_price_24h,string"`
	LastTradedPrice     float64 `json:"last_traded_price,string"`
	LastTradedQuantity  float64 `json:"last_traded_quantity,string"`
	QuotedCurrency      string  `json:"quoted_currency"`
	BaseCurrency        string  `json:"base_currency"`
	ExchangeRate        float64 `json:"exchange_rate,string"`
}

type PusherBooks

type PusherBooks struct {
	IsAsk bool
	Books Books
}

PusherBooks for Pusher

type PusherExecution

type PusherExecution struct {
	CreatedAt int64   `json:"created_at"`
	ID        int     `json:"id"`
	Price     float64 `json:"price,string"`
	Quantity  float64 `json:"quantity,string"`
	TakerSide string  `json:"taker_side"`

	Delay time.Duration
}

PusherExecution for Pusher

type PusherExecutionMe

type PusherExecutionMe struct {
	ID        int   `json:"id"`
	OrderID   int   `json:"order_id"`
	CreatedAt int64 `json:"created_at"`

	Quantity      float64 `json:"quantity,string"`
	Price         float64 `json:"price,string"`
	TakerSide     string  `json:"taker_side"`
	MySide        string  `json:"my_side"`
	ClientOrderID string  `json:"client_order_id"`

	Delay time.Duration
}

PusherExecution for Pusher

type Realtime

type Realtime struct {
	Results chan interface{}
}

func NewConnect

func NewConnect() *Realtime

NewConnect is gets notif in results

func (*Realtime) Connect

func (p *Realtime) Connect(channels, products []string)

Connect is connected pusher for liquid websocket

type RequestOrder

type RequestOrder struct {
	Order OrderParams `json:"order"`
}

type Trade

type Trade struct {
	ID               int     `json:"id"`
	CurrencyPairCode string  `json:"currency_pair_code"`
	Status           string  `json:"status"`
	Side             string  `json:"side"`
	MarginUsed       float64 `json:"margin_used,string"`
	OpenQuantity     float64 `json:"open_quantity,string"`
	CloseQuantity    float64 `json:"close_quantity,string"`
	Quantity         float64 `json:"quantity,string"`
	LeverageLevel    int     `json:"leverage_level"`
	ProductCode      string  `json:"product_code"`
	ProductID        int     `json:"product_id"`
	OpenPrice        float64 `json:"open_price,string"`
	ClosePrice       float64 `json:"close_price,string"`
	TraderID         int     `json:"trader_id"`
	OpenPnl          float64 `json:"open_pnl,string"`
	ClosePnl         float64 `json:"close_pnl,string"`
	Pnl              float64 `json:"pnl,string"`
	StopLoss         float64 `json:"stop_loss,string"`
	TakeProfit       float64 `json:"take_profit,string"`
	FundingCurrency  string  `json:"funding_currency"`
	CreatedAt        int64   `json:"created_at"`
	UpdatedAt        int64   `json:"updated_at"`
	CloseFee         float64 `json:"close_fee,string"`
	TotalInterest    float64 `json:"total_interest,string"`
	DailyInterest    float64 `json:"daily_interest,string"`
}

type Trades

type Trades struct {
	CurrentPage int     `json:"current_page"`
	TotalPages  int     `json:"total_pages"`
	Models      []Trade `json:"models"`
}

type TradingAccount

type TradingAccount struct {
	ID               int         `json:"id"`
	LeverageLevel    int         `json:"leverage_level"`
	MaxLeverageLevel int         `json:"max_leverage_level"`
	Pnl              json.Number `json:"pnl"`
	Equity           json.Number `json:"equity"`
	Margin           json.Number `json:"margin"`
	FreeMargin       json.Number `json:"free_margin"`
	TraderID         int         `json:"trader_id"`
	Status           string      `json:"status"`
	ProductCode      string      `json:"product_code"`
	CurrencyPairCode string      `json:"currency_pair_code"`
	Position         json.Number `json:"position"`
	Balance          json.Number `json:"balance"`
	CreatedAt        int64       `json:"created_at"`
	UpdatedAt        int64       `json:"updated_at"`
	PusherChannel    string      `json:"pusher_channel"`
	MarginPercent    json.Number `json:"margin_percent"`
	ProductID        int         `json:"product_id"`
	FundingCurrency  string      `json:"funding_currency"`
}

Jump to

Keyboard shortcuts

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