UNPKG

@bcswaper/apis

Version:

bcswaper apis

93 lines (92 loc) 3.86 kB
import { OrderSide } from "@dydxprotocol/v4-client-js"; import { SubTypes } from "../clientContext"; import { Candle, CandleResolution, ClientParams, Orderbook } from "../../swapContext"; export declare class dydxClient { private clientParams; private indexerClient?; private validatorClient?; private compositeClient?; private localWallet?; private subaccount; private socketClient?; private accountHandler; private candlesHandler; private marketsHandler; private orderbookHandler; private tradesHandler; private running; /** * Configuration for the dYdX Indexer API. This configuration specifies the endpoints * for the Indexer API and WebSocket connections. */ private mainnetIndexerConfig; /** * Configuration for the dYdX Validator API. This configuration includes the endpoint * for the Validator API and settings related to the blockchain network, such as * denominations and decimals for various tokens. */ private mainnetValidatorConfig; private mainnetNetwork; constructor(clientParams: ClientParams); initialize(): Promise<void>; /** * Creates a Socket Client for real-time WebSocket communication with the dYdX API. * Example Usage: * const onOpen = () => console.log('WebSocket opened.'); * const onClose = () => console.log('WebSocket closed'); * const onMessage = (message) => console.log('Message received:', message); * const socketClient = createSocketClient(onOpen, onClose, onMessage); * * @param onOpen - Callback function invoked when the WebSocket connection is opened. * @param onClose - Callback function invoked when the WebSocket connection is closed. * @param onMessage - Callback function invoked when a message is received from the WebSocket. * @returns The SocketClient instance. */ createSocketClient(): void; subscribe(subTypes: SubTypes, callback: any): void; subscribeCandle(resolution: any, callback: (candle: Candle, resolution: CandleResolution) => void): void; private getClientId; /** * Calculates the 'good until' block height for short-term orders. * @returns A Promise that resolves to the block height. */ private calculateGoodTilBlock; getPrice(): number; getOrderbook(): Orderbook; getPosition(): number; /** * Places a market order. (Short Term) * @param symbol - The symbol for the order. * @param side - The side of the order (buy or sell). * @param price - The price for the order. * @param size - The size of the order. * @returns A Promise that resolves to the order confirmation status. */ marketOrder(side: OrderSide, price: number, size: number): Promise<void>; /** * Places a limit order. (Long Term) * @param symbol - The symbol for the order. * @param side - The side of the order (buy or sell). * @param price - The price for the order. * @param size - The size of the order. * @param goodTilTime - The time until which the order remains valid. * @returns A Promise that resolves to the limit order data. */ limitOrder(side: OrderSide, price: number, size: number, goodTillTime: number): Promise<void>; /** * Cancels an order. * @param id - The ID of the order to cancel. * @param symbol - The symbol for the order. * @param goodTillTime - The time until which the order was valid. * @returns A Promise that resolves to the order cancellation confirmation status. */ cancelOrderLongTerm(id: number, goodTillTime: number): Promise<void>; destroy(): void; } export declare enum ChannelTypes { Subaccounts = "v4_subaccounts", Markets = "v4_markets", Orderbook = "v4_orderbook", Candles = "v4_candles", Trades = "v4_trades" }