tradovate

package
v0.0.0-...-ea1cebd Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2023 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GetOrderHistoryPath = "/v5/order/history"
	TradovateBaseURL    = "https://demo.tradovateapi.com/v1"
)
View Source
const (
	AUTHORIZE         = "authorize"
	CANCEL_CHART      = "md/cancelchart"
	CONNECT_WEBSOCKET = "/websocket"
	FIND_CONTRACT     = "contract/find"
	GET_ACCESS_TOKEN  = "/auth/accesstokenrequest"
	GET_CHART         = "md/getchart"
	UNSUBSCRIBE_QOUTE = "md/unsubscribeQuote"
	GET_ORDERS        = "order/list"
	GET_FILLED_ORDERS = "fill/list"
	GET_EXCHANGE_LIST = "exchange/list"
)

Variables

This section is empty.

Functions

func AsyncListener

func AsyncListener(c *websocket.Conn, out chan Message, onConnect func(m Message), onDisconnect func(m Message), onEvent func(m Message))

func Listener

func Listener(c *Client)

func SubscribeToPositions

func SubscribeToPositions(ctx context.Context, wsClient *bybit.WebSocketClient, lg *zap.Logger, category bybit.CategoryV5) (<-chan exchanges.PositionEvent, error)

func SubscribeToPrices

func SubscribeToPrices(ctx context.Context, wsClient *bybit.WebSocketClient, lg *zap.Logger, symbol string) (<-chan exchanges.PriceEvent, error)

func SubscribeToPricesInverse

func SubscribeToPricesInverse(ctx context.Context, wsClient *bybit.WebSocketClient, lg *zap.Logger, symbol string) (<-chan exchanges.PriceEvent, error)

func SubscribeToPricesLinear

func SubscribeToPricesLinear(ctx context.Context, wsClient *bybit.WebSocketClient, lg *zap.Logger, symbol string) (<-chan exchanges.PriceEvent, error)

Types

type AsyncClient

type AsyncClient struct {
	AppName    string
	AppVersion string

	HttpHost       string
	WebsocketHost  string
	MarketDataHost string

	Username string
	Password string
	ClientId string
	ApiKey   string
	DeviceId string

	WebsocketConnected  bool
	WebsocketAuthorized bool
	WebsocketConnection *websocket.Conn

	MarketDataConnected  bool
	MarketDataAuthorized bool
	MarketDataConnection *websocket.Conn

	Events chan Message

	Connected bool

	AccessToken     string
	TokenExpiration time.Time

	HeartbeatTicker       *time.Ticker
	LastHeartbeatResponse time.Time

	PenaltyTicket string

	RequestPool   map[int64]RequestMetadata
	LastRequestId int64

	MarketData map[string][]Tick
}

func NewAsyncClient

func NewAsyncClient(
	environment string, appName string, appVersion string,
	username string, password string, clientId string, apiKey string) *AsyncClient

func (*AsyncClient) Connect

func (c *AsyncClient) Connect() (err error)

func (*AsyncClient) CreateWebsocket

func (c *AsyncClient) CreateWebsocket(url string, events chan Message) (*websocket.Conn, error)

func (*AsyncClient) FindContract

func (c *AsyncClient) FindContract(name string) (int64, error)

func (*AsyncClient) SendAsync

func (c *AsyncClient) SendAsync(socketId string, endpoint string, queryParams string, body string) (id int64, err error)

func (*AsyncClient) SendAuthorization

func (c *AsyncClient) SendAuthorization(socketId string, accessToken string) error

func (*AsyncClient) SendPriceSubscription

func (c *AsyncClient) SendPriceSubscription(symbol string) error

type AuthorizationResponse

type AuthorizationResponse struct {
	Id         int64 `json:"i"`
	StatusCode int   `json:"s"`
}

type Chart

type Chart struct {
}

type ChartDescription

type ChartDescription struct {
	// Tick, DailyBar, MinuteBar, Custom, DOM
	UnderlyingType string `json:"underlyingType,omitempty"`
	ElementSize    int    `json:"elementSize,omitempty"`
	// Volume, Range, UnderlyingUnits, Renko, MomentumRange, PointAndFigure, OFARange
	ElementSizeUnit string `json:"elementSizeUnit,omitempty"`
	WithHistogram   bool   `json:"withHistogram,omitempty"`
}

type ChartRequest

type ChartRequest struct {
	Symbol           string           `json:"symbol"`
	ChartDescription ChartDescription `json:"chartDescription"`
	TimeRange        TimeRange        `json:"timeRange"`
}

type Client

type Client struct {
	AppName    string
	AppVersion string

	HttpHost      string
	WebsocketHost string
	Username      string
	Password      string
	ClientId      string
	ApiKey        string
	DeviceId      string

	ConnectionMutex sync.Mutex
	Connection      *websocket.Conn
	Connected       bool

	AccessToken     string
	TokenExpiration time.Time

	HeartbeatTicker       *time.Ticker
	LastHeartbeatResponse time.Time

	PenaltyTicket string

	RequestPool   map[int64]chan Message
	LastRequestId int64

	MarketData map[string][]Tick
}

func NewClient

func NewClient(
	environment string, appName string, appVersion string,
	username string, password string, clientId string, apiKey string) *Client

func (*Client) CancelHistoricalTickData

func (c *Client) CancelHistoricalTickData(id int) error

func (*Client) ConnectWebsocket

func (c *Client) ConnectWebsocket() (err error)

func (*Client) FindContract

func (c *Client) FindContract(name string) (Contract, error)

func (*Client) GetAccessToken

func (c *Client) GetAccessToken() error

func (*Client) GetExchanges

func (c *Client) GetExchanges() error

func (*Client) GetFilledOrders

func (c *Client) GetFilledOrders() error

func (*Client) GetHistoricalTickData

func (c *Client) GetHistoricalTickData(symbol string, start time.Time, end time.Time) (Subscription, error)

func (*Client) GetOrders

func (c *Client) GetOrders() error

func (*Client) Send

func (c *Client) Send(endpoint string, queryParams string, body string, timeout int) (*Message, error)

func (*Client) SendAsync

func (c *Client) SendAsync(endpoint string, queryParams string, body string) (int64, error)

func (*Client) SendAuthorization

func (c *Client) SendAuthorization() error

func (*Client) UnsubscribeRealtimeData

func (c *Client) UnsubscribeRealtimeData(id int) error

type Connection

type Connection struct {
	Connected  bool
	Connection *websocket.Conn
}

type Contract

type Contract struct {
	Id                 int64   `json:"id"`
	Name               string  `json:"name"`
	ContractMaturityId int64   `json:"contractMaturityId"`
	Status             string  `json:"status"`
	ProviderTickSize   float64 `json:"providerTickSize"`
}

type Message

type Message struct {
	Id        int64           `json:"i,omitempty"`
	Status    int             `json:"s,omitempty"`
	EventType string          `json:"e,omitempty"`
	Data      json.RawMessage `json:"d,omitempty"`
}

type OrderHistoryResponse

type OrderHistoryResponse struct {
	OrderId     string `json:"orderId"`
	OrderLinkId string `json:"orderLinkId"`
	Symbol      string `json:"symbol"`
	Side        string `json:"side"`
	OrderStatus string `json:"orderStatus"`
	CreatedTime string `json:"createdTime"`
	UpdatedTime string `json:"updatedTime"`
}

type RateLimitError

type RateLimitError struct {
	PenaltyTicket     string
	PenaltyTime       int64
	PenaltyExpiration time.Time
	PenaltyCaptcha    bool
}

func (*RateLimitError) Error

func (e *RateLimitError) Error() string

type RequestMetadata

type RequestMetadata struct {
	Endpoint string
	SocketId string
}

type ResultResponse

type ResultResponse struct {
	NextPageCursor string                 `json:"nextPageCursor"`
	Category       string                 `json:"category"`
	List           []OrderHistoryResponse `json:"list"`
}

type Subscription

type Subscription struct {
	Mode         string `json:"mode"`
	HistoricalId int    `json:"historicalId"`
	RealtimeId   int    `json:"realtimeId"`
}

type SymbolFilter

type SymbolFilter struct {
	LotSizeFilter struct {
		BasePrecision  string `json:"basePrecision"`
		QuotePrecision string `json:"quotePrecision"`
		MaxOrderQty    string `json:"maxOrderQty"`
		MinOrderQty    string `json:"minOrderQty"`
		MinOrderAmt    string `json:"minOrderAmt"`
		MaxOrderAmt    string `json:"maxOrderAmt"`
	} `json:"lotSizeFilter"`
	PriceFilter struct {
		TickSize string `json:"tickSize"`
	} `json:"priceFilter"`
}

type Tick

type Tick struct {
	SubscriptionId string    `json:"id"`
	Source         string    `json:"source"`
	Time           time.Time `json:"time"`
	Price          float64   `json:"price"`
	Bid            float64   `json:"bid"`
	Ask            float64   `json:"ask"`
	AskSize        int       `json:"ask_size"`
	BidSize        int       `json:"bid_size"`
}

type Time

type Time struct {
	time.Time
}

func (*Time) MarshalJSON

func (ct *Time) MarshalJSON() ([]byte, error)

func (*Time) UnmarshalJSON

func (ct *Time) UnmarshalJSON(b []byte) (err error)

type TimeRange

type TimeRange struct {
	ClosestTimestamp Time `json:"closestTimestamp,omitempty"`
	ClosestTickId    int  `json:"closestTickId,omitempty"`
	AsFarAsTimestamp Time `json:"asFarAsTimestamp,omitempty"`
	AsMuchAsElement  int  `json:"asMuchAsElement,omitempty"`
}

type TradovateResponse

type TradovateResponse struct {
	RetCode int            `json:"retCode"`
	RetMsg  string         `json:"retMsg"`
	Result  ResultResponse `json:"result"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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