quoter

package module
Version: v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

README

quoter

Go Reference golangci-lint Go Report Card License

Get real-time Cryptocurrency quotes via CoinMarketCap.

Get it
go get -u github.com/pinealctx/opensea-go
Use it
package main

import (
	"github.com/pinealctx/quoter"
	"log"
	"time"
)

func main() {
	var p, err = quoter.New()
	if err != nil {
		log.Fatalf("new.price.latest.error:%+v", err)
		return
	}
	for i := 0; i < 2; i++ {
		log.Printf("1ETH = %fUSD, 1ETH = %fCNY", p.Price(quoter.USD, quoter.ETH), p.Price(quoter.CNY, quoter.ETH))
		time.Sleep(time.Second * 5)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LatestData

type LatestData struct {
	ID     int      `json:"id"`
	Name   string   `json:"name"`
	Symbol string   `json:"symbol"`
	Slug   string   `json:"slug"`
	Quotes []*Quote `json:"quotes"`
}

type LatestResponse

type LatestResponse struct {
	Data   []*LatestData `json:"data"`
	Status *Status       `json:"status"`
}

type Message

type Message struct {
	Typ     int
	Content []byte
}

type Quote

type Quote struct {
	Name  int     `json:"name,string"`
	Price float64 `json:"price"`
}

type Quoter

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

func New

func New(symbols ...Symbol) (*Quoter, error)

func (*Quoter) Close

func (q *Quoter) Close()

func (*Quoter) Price

func (q *Quoter) Price(target, symbol Symbol) float64

type Socket

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

func NewSocket

func NewSocket(wsURL string, header http.Header) (*Socket, error)

func (*Socket) Close

func (s *Socket) Close() error

Close connection

func (*Socket) Message

func (s *Socket) Message() <-chan Message

func (*Socket) SendStr

func (s *Socket) SendStr(msg string) error

SendStr Send string message

func (*Socket) Wait

func (s *Socket) Wait() <-chan error

type Status

type Status struct {
	Timestamp    string `json:"timestamp"`
	ErrorCode    int    `json:"error_code,string"`
	ErrorMessage string `json:"error_message"`
}

type SubscribeRequest

type SubscribeRequest struct {
	Method string `json:"method"`
	ID     string `json:"id"`
	Data   struct {
		CryptoIDs []int `json:"cryptoIds"`
	} `json:"data"`
}

func NewSubscribeRequest

func NewSubscribeRequest(cryptoIDs []int) *SubscribeRequest

type SubscribeResponse

type SubscribeResponse struct {
	ID   string `json:"id"`
	Data struct {
		Timestamp int64 `json:"t"`
		CR        struct {
			ID    int     `json:"id"`
			Price float64 `json:"p"`
		} `json:"cr"`
	} `json:"d"`
	S string `json:"s"`
}

type Symbol

type Symbol string
const (
	BTC Symbol = "BTC"
	ETH Symbol = "ETH"
	USD Symbol = "USD"
	CNY Symbol = "CNY"
)

Jump to

Keyboard shortcuts

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