wsclient

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PUBLIC_PATH  = "/public"
	PRIVATE_PATH = "/private"

	SUB_UNSUB_SUCCESS = "success"
	SUB_UNSUB_ERROR   = "error"
)

Variables

View Source
var (
	WebsocketTimeout = time.Second * 60

	WebsocketKeepalive = false
)
View Source
var ErrNotLoggedIn = errors.New("not logged in")

Not logged in error

Functions

This section is empty.

Types

type Base

type Base string
const (
	MAINET  Base = "wss://api.tanx.fi"
	TESTNET Base = "wss://api-testnet.tanx.fi"
)

type Config

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

type ErrHandler

type ErrHandler func(err error)

type ErrJSONUnmarshal

type ErrJSONUnmarshal struct {
	Msg string
	Err error
}

json unmarshaling error

func (*ErrJSONUnmarshal) Error

func (e *ErrJSONUnmarshal) Error() string

type ErrSubUnsub

type ErrSubUnsub struct {
	Msg string
	Err error
}

Subscribe Unsubscribe erros

func (*ErrSubUnsub) Error

func (e *ErrSubUnsub) Error() string

type ErrWsReadMessage

type ErrWsReadMessage struct {
	Msg string
	Err error
}

websocket read message error

func (*ErrWsReadMessage) Error

func (e *ErrWsReadMessage) Error() string

type EventHandler

type EventHandler func(message []byte)

type KlineEvent

type KlineEvent map[string][]float64
{
  "btcusdc.kline-5m": [1659024300, 23935.01, 23935.01, 23935.01, 23935.01, 0]
}

type KlineEventHandler

type KlineEventHandler func(event *KlineEvent)

type KlinePeriod

type KlinePeriod string
const (
	PERIOD_1M  KlinePeriod = "1m"
	PERIOD_5M  KlinePeriod = "5m"
	PERIOD_15M KlinePeriod = "15m"
	PERIOD_30M KlinePeriod = "30m"
	PERIOD_1H  KlinePeriod = "1h"
	PERIOD_2H  KlinePeriod = "2h"
	PERIOD_4H  KlinePeriod = "4h"
	PERIOD_6H  KlinePeriod = "6h"
	PERIOD_12H KlinePeriod = "12h"
	PERIOD_1D  KlinePeriod = "1d"
	PERIOD_3D  KlinePeriod = "3d"
	PERIOD_1W  KlinePeriod = "1w"
)

type OrderbookData

type OrderbookData struct {
	Asks     []string `json:"asks"`
	Bids     []string `json:"bids"`
	Sequence int64    `json:"sequence"`
}

type OrderbookEvent

type OrderbookEvent map[string]OrderbookData

Response for ask

{
	"btcusdc.ob-inc": {
	"asks": ["23707.65", "0.034"],
	"sequence": 393494
	}
}

Response for bid

{
  "btcusdc.ob-inc": {
    "asks": ["23707.65", "0.034"],
    "sequence": 393494
  }
}

type OrderbookEventHandler

type OrderbookEventHandler func(event *OrderbookEvent)

type PrivateEvent

type PrivateEvent struct {
	Trade PrivateTrade `json:"trade"`
	Order PrivateOrder `json:"order"`
}

responses for trade

{
  "trade": {
    "amount": "0.001",
    "created_at": 1659024869,
    "id": 448640,
    "market": "btcusdc",
    "order_id": 8840859,
    "price": "23829.22",
    "side": "buy",
    "taker_type": "buy",
    "total": "23.82922"
  }
}

responses for order

{
  "order": {
    "at": 1659024868,
    "avg_price": "23829.22",
    "created_at": 1659024868,
    "executed_volume": "0.001",
    "id": 8840859,
    "kind": "bid",
    "market": "btcusdc",
    "ord_type": "limit",
    "origin_volume": "0.001",
    "price": "24000.0",
    "remaining_volume": "0.0",
    "side": "buy",
    "state": "done",
    "trades_count": 1,
    "updated_at": 1659024869
  }
}

type PrivateEventHandler

type PrivateEventHandler func(event *PrivateEvent)

type PrivateOrder

type PrivateOrder struct {
	At              int64  `json:"at"`
	AvgPrice        string `json:"avg_price"`
	CreatedAt       int64  `json:"created_at"`
	ExecutedVolume  string `json:"executed_volume"`
	ID              int64  `json:"id"`
	Kind            string `json:"kind"`
	Market          string `json:"market"`
	OrdType         string `json:"ord_type"`
	OriginVolume    string `json:"origin_volume"`
	Price           string `json:"price"`
	RemainingVolume string `json:"remaining_volume"`
	Side            string `json:"side"`
	State           string `json:"state"`
	TradesCount     int64  `json:"trades_count"`
	UpdatedAt       int64  `json:"updated_at"`
}

type PrivateTrade

type PrivateTrade struct {
	Trade
	Market  string `json:"market"`
	OrderID int64  `json:"order_id"`
	Total   string `json:"total"`
}

type SubUnsub

type SubUnsub string
const (
	SUBSCRIBE   SubUnsub = "subscribe"
	UNSUBSCRIBE SubUnsub = "unsubscribe"
)

type SubUnsubEvent

type SubUnsubEvent struct {
	Success Success `json:"success"`
}

type SubUnsubEventHandler

type SubUnsubEventHandler func(event *SubUnsubEvent)

type SubUnsubRequest

type SubUnsubRequest struct {
	Event   SubUnsub `json:"event"`
	Streams []string `json:"streams"`
}

func SubUnsubKlineTopics

func SubUnsubKlineTopics(subUnsub SubUnsub, symbol map[string]KlinePeriod) SubUnsubRequest

helper function to form subscribe or unsubscribe request for kline topics

{
  "event": "subscribe",
  "streams": ["btcusdc.kline-5m"]
}

func SubUnsubOrderbookTopics

func SubUnsubOrderbookTopics(subUnsub SubUnsub, symbol []string) SubUnsubRequest

helper function to form subscribe or unsubscribe request for orderbook topics

{
  "event": "subscribe",
  "streams": ["btcusdc.ob-inc"]
}

func SubUnsubPrivateTopics

func SubUnsubPrivateTopics(subUnsub SubUnsub, streams []string) SubUnsubRequest

helper function to form subscribe or unsubscribe request for private topics

{ "event": "subscribe", "streams": ["trade", "order"] }

func SubUnsubTradeTopics

func SubUnsubTradeTopics(subUnsub SubUnsub, symbol []string) SubUnsubRequest

helper function to form subscribe or unsubscribe request for trade topics

{
  "event": "subscribe",
  "streams": ["btcusdc.trades"]
}

type Success

type Success struct {
	Message string   `json:"message"`
	Streams []string `json:"streams"`
}

type Trade

type Trade struct {
	Amount    string `json:"amount"`
	Date      int64  `json:"date"`
	Price     string `json:"price"`
	TakerType string `json:"taker_type"`
	Tid       int64  `json:"tid"`
}

type TradeEvent

type TradeEvent map[string]Trades
{
  "btcusdc.trades": {
    "trades": [
      {
        "amount": "0.001",
        "date": 1659023778,
        "price": "23935.01",
        "taker_type": "buy",
        "tid": 448639
      }
    ]
  }
}

type TradeEventHandler

type TradeEventHandler func(event *TradeEvent)

type Trades

type Trades struct {
	Trades []Trade `json:"trades"`
}

type Wsclient

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

func New

func New(baseURL Base) *Wsclient

func (*Wsclient) Kline

func (c *Wsclient) Kline(symbol map[string]KlinePeriod, klineEventHandler KlineEventHandler, subUnsubEventHandler SubUnsubEventHandler, errHandler ErrHandler) (doneCh, stopCh chan struct{}, subUnsubCh chan SubUnsubRequest, err error)

connects you to kline stream

func (*Wsclient) Orderbook

func (c *Wsclient) Orderbook(symbol []string, orderbookEventHandler OrderbookEventHandler, subUnsubEventHandler SubUnsubEventHandler, errHandler ErrHandler) (doneCh, stopCh chan struct{}, subUnsubCh chan SubUnsubRequest, err error)

connects you to orderbook stream

func (*Wsclient) PrivateTrade

func (c *Wsclient) PrivateTrade(symbol []string, privateEventHandler PrivateEventHandler, subUnsubEventHandler SubUnsubEventHandler, errHandler ErrHandler) (doneCh, stopCh chan struct{}, subUnsubCh chan SubUnsubRequest, err error)

subscribes to Trade data for authenticated user

func (*Wsclient) SetJwt

func (c *Wsclient) SetJwt(jwtToken string, refreshToken string)

func (*Wsclient) Trade

func (c *Wsclient) Trade(symbol []string, tradeEventHandler TradeEventHandler, subUnsubEventHandler SubUnsubEventHandler, errHandler ErrHandler) (doneCh, stopCh chan struct{}, subUnsubCh chan SubUnsubRequest, err error)

connects you to trade stream

Jump to

Keyboard shortcuts

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