websocket

package
v0.0.0-...-5a814c2 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2019 License: Apache-2.0 Imports: 8 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

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

Conn represents WebSocket connection to a Topic. Use Update() func to get server messages.

func (*Conn) Close

func (c *Conn) Close() (err error)

Close closes websocket connection and updates channel.

func (*Conn) Encrypt

func (c *Conn) Encrypt() bool

Encrypt returns if connection is encrypted (wss or ws).

func (*Conn) IsClosed

func (c *Conn) IsClosed() bool

IsClosed returns if connection is closed.

func (*Conn) PingInterval

func (c *Conn) PingInterval() int

PingInterval returns server ping interval.

func (*Conn) PingTimeout

func (c *Conn) PingTimeout() int

PingTimeout returns server ping timeout.

func (*Conn) Send

func (c *Conn) Send(tp Type, tc Topic, sym string) (r Response, err error)

Send sends actions to perform

func (*Conn) SetUpdates

func (c *Conn) SetUpdates(ch chan interface{})

SetUpdates sets parsed channel to be used when a update fire.

func (*Conn) Symbol

func (c *Conn) Symbol() string

Symbol returns current connected symbol.

func (*Conn) Updates

func (c *Conn) Updates() <-chan interface{}

Updates is the notification channel.

The types which can be sended through channel are: error, History, OrderBook and Market

func (*Conn) UserType

func (c *Conn) UserType() string

UserType returns connection user type.

type History

type History struct {
	Symbol    string  `json:"-"`
	Id        string  `json:"oid"`
	Price     float64 `json:"price"`
	Count     float64 `json:"count"`
	Time      int64   `json:"time"`
	VolValue  float64 `json:"volValue"`
	Direction string  `json:"direction"`
}

History is the type received from History subscription

type Market

type Market struct {
	CoinType      string  `json:"coinType"`
	Trading       bool    `json:"trading"`
	Symbol        string  `json:"symbol"`
	LastDealPrice float64 `json:"lastDealPrice"`
	Buy           float64 `json:"buy"`
	Sell          float64 `json:"sell"`
	Change        float64 `json:"change"`
	CoinTypePair  string  `json:"coinTypePair"`
	Sort          int     `json:"sort"`
	FeeRate       float64 `json:"feeRate"`
	VolValue      float64 `json:"volValue"`
	High          float64 `json:"high"`
	Datetime      int64   `json:"datetime"`
	Vol           float64 `json:"vol"`
	Low           float64 `json:"low"`
	ChangeRate    float64 `json:"changeRate"`
}

Market is the type received from Tick and Market subscription

type OrderBook

type OrderBook struct {
	Symbol string  `json:"-"`
	Volume float64 `json:"volume"`
	Price  float64 `json:"price"`
	Count  float64 `json:"count"`
	Action string  `json:"action"`
	Time   int64   `json:"time"`
	Type   string  `json:"type"`
}

OrderBook is the type received from Orderbook subscription

type Response

type Response struct {
	Id   string `json:"id"`
	Type string `json:"type"`
}

Response represents server response after sending data.

type Topic

type Topic byte

Topic represents topic in which user can perform Type actions.

const (
	TOrderBook Topic = iota
	THistory
	Tick
	TMarket
)

type Type

type Type string

Type represents actions that can be performed.

const (
	Subscribe   Type = "subscribe"
	Unsubscribe Type = "unsubscribe"
	Ping        Type = "ping"
	Close       Type = "close"
)

type WebSocket

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

WebSocket represents websocket connection handler.

func NewWS

func NewWS() (*WebSocket, error)

NewWS returns initilised websocket connection.

func (*WebSocket) SetUserType

func (ws *WebSocket) SetUserType(userType string)

SetUserType sets user type. Can be vip or normal.

By default userType is normal.

Use this function before calling Dial.

func (*WebSocket) Subscribe

func (ws *WebSocket) Subscribe(tc Topic, sym string) (c *Conn, err error)

Subscribe subscribes client to a topic.

Jump to

Keyboard shortcuts

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