ws_client

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2024 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RyskV2WSClient

type RyskV2WSClient struct {
	SubAccountId     int64            // SubAccountId is the ID of the subaccount to use.
	RPCConnection    *websocket.Conn  // RPCConnection is the WebSocket connection for RPC operations.
	StreamConnection *websocket.Conn  // StreamConnection is the WebSocket connection for streaming operations.
	EthClient        types.IEthClient // EthClient is the Ethereum client interface.
	// contains filtered or unexported fields
}

RyskV2WSClient is the WebSocket client for interacting with Rysk V2 services.

func NewRyskV2WSClient

func NewRyskV2WSClient(config *RyskV2WSClientConfiguration) (*RyskV2WSClient, error)

NewRyskV2WSClient creates a new `RyskV2WSClient` instance based on the provided configuration. It initializes and returns a new client that connects to the Rysk V2 WebSocket API.

Parameters:

  • config: A pointer to a `RyskV2WSClientConfiguration` struct that contains configuration parameters such as environment (`types.Environment`), private key (`string`), RPC URL (`string`), and subaccount ID (`uint8`).

Returns:

  • *RyskV2WSClient: A pointer to the initialized `RyskV2WSClient` instance.
  • error: An error if the client initialization fails.

func (*RyskV2WSClient) AccountUpdates

func (go100XClient *RyskV2WSClient) AccountUpdates(messageId string) error

AccountUpdates returns immediate order updates on placement, execution, cancellation, up to date spot balances and perp positions pushed out every 5s.

Parameters:

  • messageId: A unique identifier for the message.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) ApproveSigner

func (go100XClient *RyskV2WSClient) ApproveSigner(messageId string, params *types.ApproveRevokeSignerRequest) error

ApproveSigner approves a signer for a sub-account.

Parameters:

  • messageId: The unique identifier for the message.
  • params: Approval parameters including the signer details.

Returns:

  • error: An error if the approval process fails.

func (*RyskV2WSClient) ApproveUSDC

func (go100XClient *RyskV2WSClient) ApproveUSDC(ctx context.Context, amount *big.Int) (*geth_types.Transaction, error)

ApproveUSDC approves Rysk V2 to spend USDC on your behalf.

Parameters:

  • ctx: The context.Context for the Ethereum transaction.
  • amount: The amount of USDC tokens to approve, specified as a *big.Int.

Returns:

  • A pointer to a geth_types.Transaction representing the Ethereum transaction.
  • An error if the Ethereum transaction fails or encounters an issue.

func (*RyskV2WSClient) CancelAllOpenOrders

func (go100XClient *RyskV2WSClient) CancelAllOpenOrders(messageId string, product *types.Product) error

CancelAllOpenOrders cancels all active orders on a product for the `SubAccount`.

Parameters:

  • messageId: The unique identifier for the message.
  • product: The product for which all active orders should be canceled.

Returns:

  • error: An error if the operation fails.

Returns number of deleted orders.

func (*RyskV2WSClient) CancelOrder

func (go100XClient *RyskV2WSClient) CancelOrder(messageId string, params *types.CancelOrderRequest) error

CancelOrder cancels an active order on the `SubAccount`.

Parameters:

  • messageId: The unique identifier for the message.
  • params: A struct containing parameters to specify the order to be canceled.

Returns:

  • error: An error if the operation fails.

func (*RyskV2WSClient) DepositUSDC

func (go100XClient *RyskV2WSClient) DepositUSDC(ctx context.Context, amount *big.Int) (*geth_types.Transaction, error)

DepositUSDC sends USDC to Rysk V2.

Parameters:

  • ctx: The context.Context for the Ethereum transaction.
  • amount: The amount of USDC tokens to deposit, specified as a *big.Int.

Returns:

  • A pointer to a geth_types.Transaction representing the Ethereum transaction.
  • An error if the Ethereum transaction fails or encounters an issue.

func (*RyskV2WSClient) GetPerpetualPosition

func (go100XClient *RyskV2WSClient) GetPerpetualPosition(messageId string, products []*types.Product) error

GetPerpetualPosition returns perpetual position for sub account id.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products for which to retrieve perpetual positions.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) GetProduct

func (go100XClient *RyskV2WSClient) GetProduct(messageId string, product *types.Product) error

GetProduct sends a request to retrieve details for a specific product using the Rysk V2 WebSocket API.

Parameters:

  • messageId: The unique identifier for the message.
  • product: A pointer to the product details structure (types.Product) where the retrieved data will be stored.

Returns:

  • error: An error if the request to fetch the product details fails.

func (*RyskV2WSClient) GetSpotBalances

func (go100XClient *RyskV2WSClient) GetSpotBalances(messageId string, assets []string) error

GetSpotBalances returns spot balances for sub account id.

Parameters:

  • messageId: A unique identifier for the message.
  • assets: A slice of strings representing the assets for which to retrieve spot balances.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) ListOpenOrders

func (go100XClient *RyskV2WSClient) ListOpenOrders(messageId string, params *types.ListOrdersRequest) error

ListOpenOrders returns all open orders on the `SubAccount` per product.

Parameters:

  • messageId: The unique identifier for the message.
  • params: A struct containing parameters to specify the product and additional filtering criteria for the orders.

Returns:

  • error: An error if the operation fails.

func (*RyskV2WSClient) ListProducts

func (go100XClient *RyskV2WSClient) ListProducts(messageId string) error

ListProducts sends a request to retrieve the list of products available on the Rysk V2 WebSocket API. It subscribes to the `LIST_PRODUCTS` message identifier to fetch the products.

Parameters:

  • messageId: The unique identifier for the message.

Returns:

  • error: An error if the request to fetch the products fails.

func (*RyskV2WSClient) Login

func (go100XClient *RyskV2WSClient) Login(messageId string) error

Login performs authentication for the WebSocket connection. Authentication using signature is required to create and cancel orders, deposit and withdraw.

Parameters:

  • messageId: The unique identifier for the message.

Returns:

  • error: An error if the authentication fails.

func (*RyskV2WSClient) NewOrder

func (go100XClient *RyskV2WSClient) NewOrder(messageId string, params *types.NewOrderRequest) error

NewOrder creates a new order on the SubAccount.

Parameters:

  • messageId: The unique identifier for the message.
  • params: A struct containing details for the new order, such as product symbol, order type, quantity, price, etc.

Returns:

  • error: An error if the operation fails.

func (*RyskV2WSClient) OrderBook

func (go100XClient *RyskV2WSClient) OrderBook(messageId string, params *types.OrderBookRequest) error

OrderBook returns bids and asks for a market.

It retrieves the order book data for the specified market based on the provided parameters. The order book includes bids and asks, which represent buy and sell orders respectively.

Parameters:

  • messageId: A unique identifier for the message.
  • params: An OrderBookRequest struct pointer containing parameters such as market ID.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) RevokeSigner

func (go100XClient *RyskV2WSClient) RevokeSigner(messageId string, params *types.ApproveRevokeSignerRequest) error

RevokeSigner revokes a signer for a sub-account.

Parameters:

  • messageId: The unique identifier for the message.
  • params: Revocation parameters including the signer details.

Returns:

  • error: An error if the revocation process fails.

func (*RyskV2WSClient) ServerTime

func (go100XClient *RyskV2WSClient) ServerTime(messageId string) error

ServerTime sends a request to test connectivity and retrieve the current server time using the Rysk V2 WebSocket API.

Parameters:

  • messageId: The unique identifier for the message.

Returns:

  • error: An error if the request to fetch the server time fails.

func (*RyskV2WSClient) SessionStatus

func (go100XClient *RyskV2WSClient) SessionStatus(messageId string) error

SessionStatus checks the active session and returns the address currently authenticated.

Parameters:

  • messageId: The unique identifier for the message.

Returns:

  • error: An error if the session status retrieval fails.

func (*RyskV2WSClient) SubAccountList

func (go100XClient *RyskV2WSClient) SubAccountList(messageId string) error

SubAccountList retrieves a list of all sub-accounts associated with the authenticated account.

Parameters:

  • messageId: The unique identifier for the message.

Returns:

  • error: An error if the sub-account list retrieval fails.

func (*RyskV2WSClient) Subscribe24hrPriceChangeStatistics

func (go100XClient *RyskV2WSClient) Subscribe24hrPriceChangeStatistics(messageId string, products []*types.Product) error

Subscribe24hrPriceChangeStatistics subscribes to 24hr rolling window mini-ticker statistics. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Pushed out every 5s.

Parameters: - messageId: A unique identifier for the message. - products: A slice of Product pointers representing the products to subscribe to for 24hr rolling window mini-ticker statistics.

Returns: - error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) SubscribeAggregateTrades

func (go100XClient *RyskV2WSClient) SubscribeAggregateTrades(messageId string, products []*types.Product) error

SubscribeAggregateTrades subscribes to aggregate trade (aggTrade) that represents one or more individual trades. Trades that fill at the same time, from the same taker order.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products to subscribe to for aggregate trades.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) SubscribeKlineData

func (go100XClient *RyskV2WSClient) SubscribeKlineData(messageId string, products []*types.Product, intervals []types.Interval) error

SubscribeKlineData subscribes to Kline/Candlestick Stream that push updates to the current klines/candlestick every second.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products to subscribe to for Kline/Candlestick data.
  • intervals: A slice of Interval values representing the time intervals for the Kline/Candlestick data.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) SubscribePartialBookDepth

func (go100XClient *RyskV2WSClient) SubscribePartialBookDepth(messageId string, products []*types.Product, limits []types.Limit, granularities []int64) error

SubscribePartialBookDepth subscribes to top {limit} bids and asks, pushed every second. Prices are rounded by 1e{granularity}.

Parameters: - messageId: A unique identifier for the message. - products: A slice of Product pointers representing the products to subscribe to for partial book depth. - limits: A slice of Limit values representing the depth limits for the book. - granularities: A slice of int64 values representing the price rounding granularity.

Returns: - error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) SubscribeSingleTrades

func (go100XClient *RyskV2WSClient) SubscribeSingleTrades(messageId string, products []*types.Product) error

SubscribeSingleTrades subscribes to Trade Streams that push raw trade information; each trade has a unique buyer and seller.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products to subscribe to for single trades.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) Unsubscribe24hrPriceChangeStatistics

func (go100XClient *RyskV2WSClient) Unsubscribe24hrPriceChangeStatistics(messageId string, products []*types.Product) error

Unsubscribe24hrPriceChangeStatistics unsubscribes from 24hr rolling window mini-ticker statistics. These are NOT the statistics of the UTC day, but a 24hr rolling window for the previous 24hrs. Pushed out every 5s.

Parameters: - messageId: A unique identifier for the message. - products: A slice of Product pointers representing the products to unsubscribe from for 24hr rolling window mini-ticker statistics.

Returns: - error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) UnsubscribeAggregateTrades

func (go100XClient *RyskV2WSClient) UnsubscribeAggregateTrades(messageId string, products []*types.Product) error

UnsubscribeAggregateTrades unsubscribes from aggregate trade (aggTrade) that represents one or more individual trades. Trades that fill at the same time, from the same taker order.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products to unsubscribe from for aggregate trades.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) UnsubscribeKlineData

func (go100XClient *RyskV2WSClient) UnsubscribeKlineData(messageId string, products []*types.Product, intervals []types.Interval) error

UnsubscribeKlineData unsubscribes from Kline/Candlestick Stream that pushes updates to the current klines/candlestick every second.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products to unsubscribe from for Kline/Candlestick data.
  • intervals: A slice of Interval values representing the time intervals for the Kline/Candlestick data.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) UnsubscribePartialBookDepth

func (go100XClient *RyskV2WSClient) UnsubscribePartialBookDepth(messageId string, products []*types.Product, limits []types.Limit, granularities []int64) error

UnsubscribePartialBookDepth unsubscribes from top {limit} bids and asks, pushed every second. Prices are rounded by 1e{granularity}.

Parameters: - messageId: A unique identifier for the message. - products: A slice of Product pointers representing the products to unsubscribe from for partial book depth. - limits: A slice of Limit values representing the depth limits for the book. - granularities: A slice of int64 values representing the price rounding granularity.

Returns: - error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) UnubscribeSingleTrades

func (go100XClient *RyskV2WSClient) UnubscribeSingleTrades(messageId string, products []*types.Product) error

UnsubscribeSingleTrades unsubscribes from Trade Streams that push raw trade information; each trade has a unique buyer and seller.

Parameters:

  • messageId: A unique identifier for the message.
  • products: A slice of Product pointers representing the products to unsubscribe from for single trades.

Returns:

  • error: An error if the operation fails, nil otherwise.

func (*RyskV2WSClient) WaitTransaction

func (go100XClient *RyskV2WSClient) WaitTransaction(ctx context.Context, transaction *geth_types.Transaction) (*geth_types.Receipt, error)

WaitTransaction waits for a transaction to be mined and returns its receipt.

Parameters:

  • ctx: The context.Context for the Ethereum transaction.
  • transaction: The Ethereum transaction (*geth_types.Transaction) to monitor.

Returns:

  • A pointer to a geth_types.Receipt containing the transaction receipt once the transaction is mined.
  • An error if the transaction fails to be mined or encounters an issue.

type RyskV2WSClientConfiguration

type RyskV2WSClientConfiguration struct {
	Env          types.Environment // Env specifies the environment: `constants.ENVIRONMENT_TESTNET` or `constants.ENVIRONMENT_MAINNET`.
	PrivateKey   string            // PrivateKey is the account private key with or without `0x` prefix.
	RpcUrl       string            // RPC URL of the Ethereum client.
	SubAccountId uint8             // SubAccountId is the ID of the subaccount to use.
}

RyskV2WSClientConfiguration represents configuration settings for the Rysk V2 WebSocket client.

Jump to

Keyboard shortcuts

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