qsx

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2022 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserAccessDenied = errors.New("you do not have access to the requested resource")
	ErrNotFound         = errors.New("the requested resource not found")
	ErrTooManyRequests  = errors.New("you have exceeded throttle")
)
View Source
var SupportedExchanges = []Name{
	CoinbasePro,
}

SupportedExchanges is a list of all supported exchange connections

Functions

func EncodeURLValues

func EncodeURLValues(urlPath string, values url.Values) string

func Query

func Query(params []string) string

func SignSHA256HMAC

func SignSHA256HMAC(message string, secret string) (string, error)

SignSHA256HMAC creates a sha256 HMAC using the base64-decoded Secret key on the pre-hash string:

`timestamp + method + requestPath + body`

where + represents string concatenation, and then base64 encoding the output

Types

type Auth

type Auth struct {
	Key        string
	Passphrase string
	Secret     string
	Token      *oauth2.Token
}

Auth is the type for storing all authentication information for exchanges that support it Please take notice that not all fields are required for every exchange

func NewAuth

func NewAuth(key string, passphrase string, secret string) *Auth

NewAuth returns a pointer to a new Auth struct

type Candle

type Candle struct {
	Open   float64   `json:"open"`
	High   float64   `json:"high"`
	Low    float64   `json:"low"`
	Close  float64   `json:"close"`
	Volume float64   `json:"volume"`
	Time   time.Time `json:"time"`
}

Candle is the main type to represent candlestick data

type Client

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

func New

func New(httpClient *http.Client, options Options, rateLimiter *rate.Limiter) *Client

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, path string, payload interface{}, v interface{}) error

func (*Client) Get

func (c *Client) Get(ctx context.Context, path string, v interface{}) error

func (*Client) Post

func (c *Client) Post(ctx context.Context, path string, payload interface{}, v interface{}) error

func (*Client) Put

func (c *Client) Put(ctx context.Context, path string, payload interface{}, v interface{}) error

type Config

type Config struct {
	*Auth
	Sandbox bool
}

type Dialer

type Dialer struct {
	URL string
}

func (*Dialer) Dial

func (w *Dialer) Dial() (*websocket.Conn, error)

Dial returns a websocket connection

type Exchange

type Exchange struct {

	// Name is the unique name of the exchange/marketplace
	Name Name

	// Crypto is a boolean to check if the exchange has cryptocurrency support
	Crypto bool

	// Auth is for authentication information (keys, tokens etc.)
	Auth *Auth

	// API is http(s) client connection and routes to the vendors' service
	API *Client

	// Websocket is the ws(s) client connection to the vendors' service
	Websocket Websocket
}

Exchange is the base type that all supported exchanges must include It implements common methods of the IExchange interface

func (*Exchange) GetName

func (base *Exchange) GetName() Name

GetName implements the IExchange interface, and returns the Exchange's Name

func (*Exchange) SupportsCrypto

func (base *Exchange) SupportsCrypto() bool

SupportsCrypto implements the IExchange interface, and returns if the exchange has cryptocurrency support

type HTTPClient

type HTTPClient interface {
	Get(ctx context.Context, path string, v interface{}) error
	Post(ctx context.Context, path string, payload interface{}, v interface{}) error
	Put(ctx context.Context, path string, payload interface{}, v interface{}) error
	Delete(ctx context.Context, path string, payload interface{}, v interface{}) error
}

type IExchange

type IExchange interface {

	// GetName returns the exchanges unique name
	GetName() Name

	// SupportsCrypto returns true if the exchange supports trading cryptocurrencies
	SupportsCrypto() bool

	// ListProducts returns and array of Product's
	// A Product is a market trading pair such as BTC-USD or stock such as AAPL
	ListProducts(ctx context.Context) ([]Product, error)

	// GetHistoricalCandles returns and array of Candle's in the normal format for candlestick data
	GetHistoricalCandles(ctx context.Context, productID string, granularity string) ([]Candle, error)

	// WatchFeed is the function to start watching a websocket feed for a specific product
	WatchFeed(shutdown chan struct{}, wg *sync.WaitGroup, product string, feed interface{}) (*orderbook.Orderbook, error)
}

IExchange is the interface which all supported exchanges must implement

type Name

type Name string

Name is the unique name of the exchange

const (
	CoinbasePro  Name = "coinbasepro"
	Binance      Name = "binance"
	YFinance     Name = "yfinance"
	TDAmeritrade Name = "tdameritrade"
)

type Options

type Options struct {
	ApiURL  string
	Verbose bool
}

type Product

type Product struct {
	ID string `json:"id"`

	// BaseCurrency is the base in the pair of currencies that comprise the Product
	BaseCurrency string `json:"base_currency"`

	// QuoteCurrency
	QuoteCurrency string `json:"quote_currency"`

	// BaseMinSize defines the minimum order size
	BaseMinSize string `json:"base_min_size"`

	// BaseMaxSize defines the maximum order size
	BaseMaxSize string `json:"base_max_size"`

	// QuoteIncrement
	QuoteIncrement string `json:"quote_increment"`

	// BaseIncrement specifies the minimum increment for the BaseCurrency
	BaseIncrement string `json:"base_increment"`

	// DisplayName
	DisplayName string `json:"display_name"`

	// MinMarketFunds defines the minimum funds allowed
	MinMarketFunds string `json:"min_market_funds"`

	// MaxMarketFunds defines the maximum funds allowed
	MaxMarketFunds string `json:"max_market_funds"`

	// MarginEnabled
	MarginEnabled bool `json:"margin_enabled"`

	// PostOnly indicates whether only maker orders can be placed. No orders will be matched when post_only mode is active.
	PostOnly bool `json:"post_only"`

	// LimitOnly indicates whether this product only accepts limit orders.
	LimitOnly bool `json:"limit_only"`

	// CancelOnly indicates whether this product only accepts cancel requests for orders.
	CancelOnly bool `json:"cancel_only"`

	// Status
	Status string `json:"status"`

	// StatusMessage provides any extra information regarding the status, if available
	StatusMessage string `json:"status_message"`

	// AuctionMode
	AuctionMode bool `json:"auction_mode"`
}

Product Only a maximum of one of trading_disabled, cancel_only, post_only, limit_only can be true at once. If none are true, the product is trading normally. !! When limit_only is true, matching can occur if a limit order crosses the book. !! Product ID will not change once assigned to a Product but all other fields are subject to change.

type RequestError

type RequestError struct {
}

type Websocket

type Websocket interface {
	Dial() (*websocket.Conn, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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