ws_client

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 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 Go100XWSClient

type Go100XWSClient 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
}

Go100XWSClient is the WebSocket client for interacting with 100x services.

func NewGo100XWSClient

func NewGo100XWSClient(config *Go100XWSClientConfiguration) (*Go100XWSClient, error)

NewGo100XWSClient creates a new `Go100XWSClient` instance based on the provided configuration. It initializes and returns a new client that connects to the 100x WebSocket API.

Parameters:

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

Returns:

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

func (*Go100XWSClient) AccountUpdates

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) ApproveSigner

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) ApproveUSDB

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

ApproveUSDB approves 100x to spend USDB on your behalf.

Parameters:

  • ctx: The context.Context for the Ethereum transaction.
  • amount: The amount of USDB 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 (*Go100XWSClient) CancelAllOpenOrders

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) CancelOrder

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) DepositUSDB

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

DepositUSDB sends USDB to 100x.

Parameters:

  • ctx: The context.Context for the Ethereum transaction.
  • amount: The amount of USDB 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 (*Go100XWSClient) GetPerpetualPosition

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) GetProduct

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

GetProduct sends a request to retrieve details for a specific product using the 100x 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 (*Go100XWSClient) GetSpotBalances

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) ListOpenOrders

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) ListProducts

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

ListProducts sends a request to retrieve the list of products available on the 100x 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 (*Go100XWSClient) Login

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) NewOrder

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) OrderBook

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) RevokeSigner

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) ServerTime

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

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

Parameters:

  • messageId: The unique identifier for the message.

Returns:

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

func (*Go100XWSClient) SessionStatus

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) SubAccountList

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) Subscribe24hrPriceChangeStatistics

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) SubscribeAggregateTrades

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) SubscribeKlineData

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) SubscribePartialBookDepth

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) SubscribeSingleTrades

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) Unsubscribe24hrPriceChangeStatistics

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) UnsubscribeAggregateTrades

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) UnsubscribeKlineData

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) UnsubscribePartialBookDepth

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) UnubscribeSingleTrades

func (go100XClient *Go100XWSClient) 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 (*Go100XWSClient) WaitTransaction

func (go100XClient *Go100XWSClient) 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 Go100XWSClientConfiguration

type Go100XWSClientConfiguration 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            // RpcUrl is the URL for the RPC server, e.g., `https://sepolia.blast.io` or `https://rpc.blastblockchain.com`.
	SubAccountId uint8             // SubAccountId is the ID of the subaccount to use.
}

Go100XWSClientConfiguration represents configuration settings for the 100x WebSocket client.

Jump to

Keyboard shortcuts

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