### Full VertexClient Initialization Example Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/create-a-vertex-client A comprehensive example combining dependency imports, Viem client creation, and `VertexClient` instantiation. This serves as a complete setup guide for interacting with the Vertex Protocol SDK, demonstrating the typical workflow. ```typescript import { createVertexClient } from '@vertex-protocol/client'; import { createPublicClient, createWalletClient, http } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { arbitrumSepolia } from 'viem/chains'; function main() { const walletClient = createWalletClient({ account: privateKeyToAccount('0x...'), chain: arbitrumSepolia, transport: http(), }); const publicClient = createPublicClient({ chain: arbitrumSepolia, transport: http(), }); const vertexClient = createVertexClient('arbitrumTestnet', { walletClient, publicClient, }); } main(); ``` -------------------------------- ### Install Vertex SDK Packages Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/getting-started Installs the Vertex Protocol client, Viem, and Bignumber.js packages using either Yarn or NPM. These are essential dependencies for using the SDK. ```sh yarn add @vertex-protocol/client viem bignumber.js ``` ```sh npm install @vertex-protocol/client viem bignumber.js ``` -------------------------------- ### Run Example Script Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/create-a-vertex-client Instructions on how to execute the TypeScript example script using `ts-node`. This command compiles and runs the TypeScript code, allowing verification of the VertexClient setup. ```shell ts-node test.ts ``` -------------------------------- ### Full Vertex Protocol Deposit and Withdraw Example Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/withdraw-funds Provides a comprehensive end-to-end example of depositing and withdrawing funds using the Vertex Protocol SDK. It covers minting mock tokens, approving allowances, executing deposits, and then withdrawing funds, logging key transaction states. Requires setup of Vertex client and mock tokens. ```typescript import { toFixedPoint } from '@vertex-protocol/utils'; import { getVertexClient, prettyPrintJson } from './common'; async function main() { const vertexClient = getVertexClient(); const { walletClient, publicClient } = vertexClient.context; // If you have access to `walletClient`, you can call `walletClient.account.address` // directly instead of reaching into `vertexClient.context` const address = walletClient!.account.address; const subaccountName = 'default'; // 10 USDC (6 decimals) const depositAmount = toFixedPoint(10, 6); // TESTNET ONLY - Mint yourself some tokens const mintTxHash = await vertexClient.spot._mintMockERC20({ amount: depositAmount, productId: 0, }); // Mint goes on-chain, so wait for confirmation await publicClient.waitForTransactionReceipt({ hash: mintTxHash, }); // Deposits require approval on the ERC20 token, this is on-chain as well const approveTxHash = await vertexClient.spot.approveAllowance({ amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: approveTxHash, }); // Now execute the deposit, which goes on-chain const depositTxHash = await vertexClient.spot.deposit({ // Your choice of name for the subaccount, this subaccount will be credited with the deposit balance subaccountName: 'default', amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: depositTxHash, }); await new Promise((resolve) => setTimeout(resolve, 10000)); // For on-chain state, you can use `getSubaccountSummary` - these should match up const subaccountData = await vertexClient.subaccount.getEngineSubaccountSummary({ subaccountOwner: address, subaccountName, }); prettyPrintJson('Subaccount Data After Deposit', subaccountData); // Now withdraw your funds, this goes to the off-chain engine // We're withdrawing less than 10 as there are withdrawal fees of 1 USDC const withdrawTx = await vertexClient.spot.withdraw({ amount: depositAmount - toFixedPoint(1, 6), productId: 0, subaccountName, }); prettyPrintJson('Withdraw Tx', withdrawTx); // Your new subaccount summary should have zero balances const subaccountDataAfterWithdraw = await vertexClient.subaccount.getEngineSubaccountSummary({ subaccountOwner: address, subaccountName, }); prettyPrintJson( 'Subaccount Data After Withdrawal', subaccountDataAfterWithdraw, ); } main(); ``` -------------------------------- ### Example Request Body Source: https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/product-snapshots An example JSON payload for querying product snapshots. ```JSON { "products": { "product_id": 3, "max_time": 1679728762, "limit": 1 } } ``` -------------------------------- ### Engine Client Usage Example Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/user-guide/engine-client Demonstrates how to import and use the Vertex Protocol client to access the engine client for offchain operations. This snippet shows the initial setup and a placeholder for calling an engine client method. ```typescript import { createVertexClient } from '@vertex-protocol/client'; const vertexClient = await createVertexClient('testnet', ...); const res = await vertexClient.context.engineClient.liquidateSubaccount(...) ``` -------------------------------- ### Place Order via Vertex SDK Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/user-guide/client/market/place-order Demonstrates how to initialize the Vertex client and call the 'placeOrder' method for executing trades. This example assumes you have the necessary setup for the Vertex client. ```typescript import { createVertexClient } from '@vertex-protocol/client'; const vertexClient = await createVertexClient('arbitrumTestnet', ...); const res = await vertexClient.market.placeOrder(...); ``` -------------------------------- ### Example Response Body Source: https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/product-snapshots An example JSON response structure for product snapshots. ```JSON { "products": [ { "product_id": 3, "submission_idx": "563014", "product": { "spot": { "product_id": 3, "oracle_price_x18": "1751488625000000050000", "risk": { "long_weight_initial_x18": "750000000000000000", "short_weight_initial_x18": "1250000000000000000", "long_weight_maintenance_x18": "800000000000000000", "short_weight_maintenance_x18": "1200000000000000000", "large_position_penalty_x18": "0" }, "config": { "token": "0xcc59686e3a32fb104c8ff84dd895676265efb8a6", "interest_inflection_util_x18": "800000000000000000", "interest_floor_x18": "10000000000000000", "interest_small_cap_x18": "40000000000000000", "interest_large_cap_x18": "1000000000000000000" }, "state": { "cumulative_deposits_multiplier_x18": "1003006222268375194", "cumulative_borrows_multiplier_x18": "1005686349789989371", "total_deposits_normalized": "101765274778392635900623", "total_borrows_normalized": "48739080269992866425685" }, "lp_state": { "supply": "902924999999999999774268", "quote": { "amount": "1026773958941457186836518", "last_cumulative_multiplier_x18": "1000000000612384372" }, "base": { "amount": "587811596408602623177", "last_cumulative_multiplier_x18": "1003006222268375194" } }, "book_info": { "size_increment": "10000000000000000", "price_increment_x18": "100000000000000000", "min_size": "100000000000000000", "collected_fees": "1546717023589573343471212", "lp_spread_x18": "3000000000000000" } } } } ], "txs": [ { "tx": { "update_price": { "product_id": 3, "price_x18": "1750710375000000000000" } }, "submission_idx": "563014", "timestamp": "1679728271" } ] } ``` -------------------------------- ### Vertex Typescript SDK Source: https://context7_llms Guide to using the Vertex Typescript SDK for interacting with the Vertex Protocol. Covers setup and usage for developers. ```APIDOC Vertex Typescript SDK: Welcome to the Vertex Typescript SDK. This guide will help you navigate the Typescript SDK to interact with Vertex Protocol. (Details on installation, basic usage, client initialization, and examples of common operations would be provided here.) ``` -------------------------------- ### Product Snapshot Response Example Source: https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/product-snapshots An example of the JSON response structure containing product snapshots, mapping product IDs to their respective snapshot data. ```json { "1": { "product_id": 1, "submission_idx": "459743", "product": { "spot": { "product_id": 1, "oracle_price_x18": "31582395488073320408472", "risk": { "long_weight_initial_x18": "900000000000000000", "short_weight_initial_x18": "1100000000000000000", "long_weight_maintenance_x18": "950000000000000000", "short_weight_maintenance_x18": "1050000000000000000", "large_position_penalty_x18": "0" }, "config": { "token": "0x5cc7c91690b2cbaee19a513473d73403e13fb431", "interest_inflection_util_x18": "800000000000000000", "interest_floor_x18": "10000000000000000", "interest_small_cap_x18": "40000000000000000", "interest_large_cap_x18": "1000000000000000000" }, "state": { "cumulative_deposits_multiplier_x18": "1005266691979081067", "cumulative_borrows_multiplier_x18": "1008464332498400342", "total_deposits_normalized": "3853380366798127292498", "total_borrows_normalized": "3171903194179038855701" }, "lp_state": { "supply": "485670917658672273450851", "quote": { "amount": "533498653674283527525638", "last_cumulative_multiplier_x18": "1000000000047911804" }, "base": { "amount": "16862535452736644443", "last_cumulative_multiplier_x18": "1005266691979081067" } }, "book_info": { "size_increment": "1000000000000000", "price_increment_x18": "1000000000000000000", "min_size": "10000000000000000", "collected_fees": "460839041331226808022323", "lp_spread_x18": "3000000000000000" } } } }, "2": { "product_id": 2, "submission_idx": "459842", "product": { "perp": { "product_id": 2, "oracle_price_x18": "31577635670035396763528", "risk": { "long_weight_initial_x18": "950000000000000000", "short_weight_initial_x18": "1050000000000000000", "long_weight_maintenance_x18": "970000000000000000", "short_weight_maintenance_x18": "1030000000000000000", "large_position_penalty_x18": "0" }, "state": { "cumulative_funding_long_x18": "134895011744110446566737", "cumulative_funding_short_x18": "134437616226076003830045", "available_settle": "3528089205596638824705152", "open_interest": "3341108000000000000000" }, "lp_state": { "supply": "264410712802085330000000", "last_cumulative_funding_x18": "134895011744110446566737", "cumulative_funding_per_lp_x18": "5521082805340854", "base": "9170000000000000000", "quote": "289310002802085330000000" }, "book_info": { "size_increment": "1000000000000000", "price_increment_x18": "1000000000000000000", "min_size": "10000000000000000", "collected_fees": "313231857879134266832804", "lp_spread_x18": "3000000000000000" } } } } } ``` -------------------------------- ### Get Product Snapshots Usage Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/user-guide/client/market/get-product-snapshots Demonstrates how to use the Vertex Protocol SDK to fetch historical product snapshots. It initializes the Vertex client and calls the getProductSnapshots method. ```typescript import { createVertexClient } from '@vertex-protocol/client'; const vertexClient = await createVertexClient('arbitrumTestnet', ...); const res = await vertexClient.market.getProductSnapshots(...); ``` -------------------------------- ### Orderbook Response Example Source: https://docs.vertexprotocol.com/developer-resources/api/v2/orderbook Example JSON response for the orderbook endpoint, illustrating the structure of bids and asks with price and quantity. ```json { "ticker_id": "ETH-PERP_USDC", "bids": [ [ 1612.3, 0.31 ], [ 1612.0, 0.93 ], [ 1611.5, 1.55 ], [ 1610.8, 2.17 ] ], "asks": [ [ 1612.9, 0.93 ], [ 1613.4, 1.55 ], [ 1614.1, 2.17 ] ], "timestamp": 1694375362016 } ``` -------------------------------- ### Get Candlesticks TypeScript Example Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/user-guide/client/market/get-candlesticks Demonstrates how to use the Vertex SDK to fetch historical candlesticks. It initializes the client and calls the `getCandlesticks` method. ```typescript import { createVertexClient } from '@vertex-protocol/client'; const vertexClient = await createVertexClient('arbitrumTestnet', ...); const res = await vertexClient.market.getCandlesticks(...); ``` -------------------------------- ### Vertex Assets API Response Example Source: https://docs.vertexprotocol.com/developer-resources/api/v2/assets Example JSON response structure for the GET /assets endpoint, illustrating the format of asset data returned by the Vertex API. ```JSON [ { "product_id": 0, "ticker_id": null, "market_type": null, "name": "USDC", "symbol": "USDC", "taker_fee": null, "maker_fee": null, "can_withdraw": true, "can_deposit": true }, { "product_id": 2, "ticker_id": "BTC-PERP_USDC", "market_type": "perp", "name": "Bitcoin Perp", "symbol": "BTC-PERP", "maker_fee": 0.0002, "taker_fee": 0, "can_withdraw": false, "can_deposit": false }, { "product_id": 1, "ticker_id": "BTC_USDC", "market_type": "spot", "name": "Bitcoin", "symbol": "BTC", "taker_fee": 0.0003, "maker_fee": 0, "can_withdraw": true, "can_deposit": true } ] ``` -------------------------------- ### Full Example Usage Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/query-markets-and-products Demonstrates the complete workflow of fetching market data, including all markets, latest prices, and liquidity, using the Vertex Protocol client. ```typescript import {getVertexClient, prettyPrintJson} from './common'; async function main() { const vertexClient = await getVertexClient(); const allMarkets = await vertexClient.market.getAllEngineMarkets(); prettyPrintJson('All Markets', allMarkets); const latestMarketPrice = await vertexClient.market.getLatestMarketPrice({ productId: 1, }); prettyPrintJson('Latest Market Price (Product ID 1)', latestMarketPrice); const marketLiquidity = await vertexClient.market.getMarketLiquidity({ productId: 1, // Per side of the book depth: 2, }); prettyPrintJson('Market Liquidity (Product ID 1)', marketLiquidity); } main(); ``` -------------------------------- ### Get Subaccount Token Rewards Example Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/user-guide/client/subaccount/get-subaccount-token-rewards Demonstrates how to retrieve all token rewards for a specific subaccount across different epochs using the Vertex SDK. It initializes the client and calls the `getSubaccountTokenRewards` method. ```typescript import { createVertexClient } from '@vertex-protocol/client'; const vertexClient = await createVertexClient('arbitrumTestnet', ...); const res = await vertexClient.subaccount.getSubaccountTokenRewards(...); ``` -------------------------------- ### Vertex Protocol Product Data Example Source: https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/all-products Example JSON response detailing a product's financial and risk parameters within the Vertex Protocol. Includes oracle price, risk weights, configuration, state, and liquidity pool data. ```json { "status": "success", "data": { "spot_products": [ { "product_id": 0, "oracle_price_x18": "1000000000000000000", "risk": { "long_weight_initial_x18": "1000000000000000000", "short_weight_initial_x18": "1000000000000000000", "long_weight_maintenance_x18": "1000000000000000000", "short_weight_maintenance_x18": "1000000000000000000", "large_position_penalty_x18": "0" }, "config": { "token": "0x179522635726710dd7d2035a81d856de4aa7836c", "interest_inflection_util_x18": "800000000000000000", "interest_floor_x18": "10000000000000000", "interest_small_cap_x18": "40000000000000000", "interest_large_cap_x18": "1000000000000000000" }, "state": { "cumulative_deposits_multiplier_x18": "1000000000277224322", "cumulative_borrows_multiplier_x18": "1000723856933478604", "total_deposits_normalized": "60000217694536241191595078762077", "total_borrows_normalized": "56233551820212408705694509" }, "lp_state": { "supply": "0", "quote": { "amount": "0", "last_cumulative_multiplier_x18": "0" }, "base": { "amount": "0", "last_cumulative_multiplier_x18": "0" } }, "book_info": { "size_increment": "0", "price_increment_x18": "0", "min_size": "0", "collected_fees": "0", "lp_spread_x18": "0" } }, { "product_id": 1, "oracle_price_x18": "24290291250000000000000", "risk": { "long_weight_initial_x18": "750000000000000000", "short_weight_initial_x18": "1250000000000000000", "long_weight_maintenance_x18": "800000000000000000", "short_weight_maintenance_x18": "1200000000000000000", "large_position_penalty_x18": "0" }, "config": { "token": "0x5cc7c91690b2cbaee19a513473d73403e13fb431", "interest_inflection_util_x18": "800000000000000000", "interest_floor_x18": "10000000000000000", "interest_small_cap_x18": "40000000000000000", "interest_large_cap_x18": "1000000000000000000" }, "state": { "cumulative_deposits_multiplier_x18": "1001287531051121621", "cumulative_borrows_multiplier_x18": "1002452185804358156", "total_deposits_normalized": "74673923223418751744441", "total_borrows_normalized": "1848347625293254803217" }, "lp_state": { "supply": "1304161502776469160512481", "quote": { "amount": "1534680334756385968136088", "last_cumulative_multiplier_x18": "1000000000277224322" }, "base": { "amount": "62440707403022069417", "last_cumulative_multiplier_x18": "1001287531051121621" } }, "book_info": { "size_increment": "1000000000000000", "price_increment_x18": "1000000000000000000", "min_size": "10000000000000000", "collected_fees": "5664024844019131439512577", "lp_spread_x18": "3000000000000000" } }, { "product_id": 3, "oracle_price_x18": "1681810000000000000000", "risk": { "long_weight_initial_x18": "750000000000000000", "short_weight_initial_x18": "1250000000000000000", "long_weight_maintenance_x18": "800000000000000000", "short_weight_maintenance_x18": "1200000000000000000", "large_position_penalty_x18": "0" }, "config": { "token": "0xcc59686e3a32fb104c8ff84dd895676265efb8a6", "interest_inflection_util_x18": "800000000000000000", "interest_floor_x18": "10000000000000000", "interest_small_cap_x18": "40000000000000000", "interest_large_cap_x18": "1000000000000000000" }, "state": { "cumulative_deposits_multiplier_x18": "1002663685545861807", "cumulative_borrows_multiplier_x18": "1004702476678588703", "total_deposits_normalized": "77394474553800029646558", "total_borrows_normalized": "31377958151684436040546" }, "lp_state": { "supply": "902924999999999999774268", "quote": { "amount": "984703323731060714614479", "last_cumulative_multiplier_x18": "1000000000277224322" }, "base": { "amount": "62440707403022069417", "last_cumulative_multiplier_x18": "1002663685545861807" } }, "book_info": { "size_increment": "1000000000000000", "price_increment_x18": "1000000000000000000", "min_size": "10000000000000000", "collected_fees": "5664024844019131439512577", "lp_spread_x18": "3000000000000000" } } ] } } ``` -------------------------------- ### Import Vertex SDK and Viem Dependencies Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/create-a-vertex-client Imports necessary modules from '@vertex-protocol/client' and 'viem' for creating Vertex and blockchain clients. Includes functions for wallet and public client creation, account derivation, and chain definitions. ```typescript import { createVertexClient } from '@vertex-protocol/client'; import { createPublicClient, createWalletClient, http } from 'viem'; import { privateKeyToAccount } from 'viem/accounts'; import { arbitrumSepolia } from 'viem/chains'; ``` -------------------------------- ### Deposit Funds to Vertex Protocol Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/deposit-funds This example demonstrates how to deposit funds into a Vertex Protocol subaccount using TypeScript. It covers minting mock ERC20 tokens (testnet only), approving token allowances, executing the deposit transaction, and fetching the updated subaccount summary. It requires the Vertex client and utility functions for common operations. ```typescript import { toFixedPoint } from '@vertex-protocol/utils'; import { getVertexClient, prettyPrintJson } from './common'; async function main() { const vertexClient = getVertexClient(); const { walletClient, publicClient } = vertexClient.context; // If you have access to `walletClient`, you can call `walletClient.account.address` // directly instead of reaching into `vertexClient.context` const address = walletClient!.account.address; const subaccountName = 'default'; // 10 USDC (6 decimals) const depositAmount = toFixedPoint(10, 6); // TESTNET ONLY - Mint yourself some tokens const mintTxHash = await vertexClient.spot._mintMockERC20({ amount: depositAmount, productId: 0, }); // Mint goes on-chain, so wait for confirmation await publicClient.waitForTransactionReceipt({ hash: mintTxHash, }); // Deposits require approval on the ERC20 token, this is on-chain as well const approveTxHash = await vertexClient.spot.approveAllowance({ amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: approveTxHash, }); // Now execute the deposit, which goes on-chain const depositTxHash = await vertexClient.spot.deposit({ // Your choice of name for the subaccount, this subaccount will be credited with the deposit balance subaccountName: 'default', amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: depositTxHash, }); await new Promise((resolve) => setTimeout(resolve, 10000)); // For on-chain state, you can use `getSubaccountSummary` - these should match up const subaccountData = await vertexClient.subaccount.getEngineSubaccountSummary({ subaccountOwner: address, subaccountName, }); prettyPrintJson('Subaccount Data After Deposit', subaccountData); } main(); ``` -------------------------------- ### Vertex Protocol Product Data Example (Product ID 1) Source: https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/subaccount-info Example JSON data representing the configuration and state for a specific financial product (product_id: 1). This includes detailed risk, configuration, state, LP state, and book information. ```json { "product_id": 1, "oracle_price_x18": "1000000000000000000", "risk": { "long_weight_initial_x18": "1000000000000000000", "short_weight_initial_x18": "1000000000000000000", "long_weight_maintenance_x18": "1000000000000000000", "short_weight_maintenance_x18": "1000000000000000000", "large_position_penalty_x18": "0" }, "config": { "token": "0x179522635726710dd7d2035a81d856de4aa7836c", "interest_inflection_util_x18": "800000000000000000", "interest_floor_x18": "10000000000000000", "interest_small_cap_x18": "40000000000000000", "interest_large_cap_x18": "1000000000000000000" }, "state": { "cumulative_deposits_multiplier_x18": "1000000002391497578", "cumulative_borrows_multiplier_x18": "1001593395547514024", "total_deposits_normalized": "60000256267437588885818752247843", "total_borrows_normalized": "391445043137305055810336885" }, "lp_state": { "supply": "0", "quote": { "amount": "0", "last_cumulative_multiplier_x18": "0" }, "base": { "amount": "0", "last_cumulative_multiplier_x18": "0" } }, "book_info": { "size_increment": "0", "price_increment_x18": "0", "min_size": "0", "collected_fees": "0", "lp_spread_x18": "0" } } ``` -------------------------------- ### Get Health Groups via REST (GET) Source: https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/health-groups Uses an HTTP GET request to the query endpoint to retrieve health group data. The query type is specified as a URL parameter. ```APIDOC GET [GATEWAY_REST_ENDPOINT]/query?type=health_groups ``` -------------------------------- ### Create Viem Wallet and Public Clients Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/create-a-vertex-client Demonstrates the creation of Viem's `WalletClient` and `PublicClient`. The `WalletClient` is essential for transaction signing and write operations, while `PublicClient` is used for read operations. Both require chain and transport configurations. ```typescript const walletClient = createWalletClient({ account: privateKeyToAccount('0x...'), chain: arbitrumSepolia, transport: http(), }); const publicClient = createPublicClient({ chain: arbitrumSepolia, transport: http(), }); ``` -------------------------------- ### Place Order EIP712 Typed Data Source: https://docs.vertexprotocol.com/developer-resources/api/gateway/signing/examples Demonstrates the EIP712 typed data structure for placing a standard order. Includes domain separation and order message fields. ```python { 'types': { 'EIP712Domain': [ {'name': 'name', 'type': 'string'}, {'name': 'version', 'type': 'string'}, {'name': 'chainId', 'type': 'uint256'}, {'name': 'verifyingContract', 'type': 'address'} ], 'Order': [ {'name': 'sender', 'type': 'bytes32'}, {'name': 'priceX18', 'type': 'int128'}, {'name': 'amount', 'type': 'int128'}, {'name': 'expiration', 'type': 'uint64'}, {'name': 'nonce', 'type': 'uint64'}, ], }, 'primaryType': 'Order', 'domain': { 'name': 'Vertex', 'version': '0.0.1', 'chainId': 421613, 'verifyingContract': '0xf03f457a30e598d5020164a339727ef40f2b8fbc' }, 'message': { 'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'), 'priceX18': 28898000000000000000000, 'amount': -10000000000000000, 'expiration': 4611687701117784255, 'nonce': 1764428860167815857, }, } ``` -------------------------------- ### EIP-712 Typed Data Definition and Message Example Source: https://docs.vertexprotocol.com/developer-resources/api/gateway/signing/examples Defines the EIP-712 Domain Separator types and a specific message structure for Vertex Protocol transactions. Includes type schemas for EIP712Domain and ListTriggerOrders, along with an example domain and message payload. ```APIDOC { 'EIP712Domain': [ {'name': 'name', 'type': 'string'}, {'name': 'version', 'type': 'string'}, {'name': 'chainId', 'type': 'uint256'}, {'name': 'verifyingContract', 'type': 'address'} ], 'ListTriggerOrders': [ {'name': 'sender', 'type': 'bytes32' }, {'name': 'recvTime', 'type': 'uint64' } ], 'primaryType': 'WithdrawCollateral', 'domain': { 'name': 'Vertex', 'version': '0.0.1', 'chainId': 421613, 'verifyingContract': '0xbf16e41fb4ac9922545bfc1500f67064dc2dcc3b' }, 'message': { 'sender': hex_to_bytes32('0x841fe4876763357975d60da128d8a54bb045d76a64656661756c740000000000'), 'recvTime': 1688939576000 } } ``` -------------------------------- ### Full Vertex Protocol Example Source: https://docs.vertexprotocol.com/developer-resources/vertex-typescript-sdk/how-to/manage-orders A comprehensive end-to-end example demonstrating a typical workflow on the Vertex Protocol. This includes depositing funds, placing an order, querying open orders, cancelling the order, and finally withdrawing funds. It utilizes various functions from `@vertex-protocol/client`, `@vertex-protocol/contracts`, and `@vertex-protocol/utils`. ```typescript import { PlaceOrderParams } from '@vertex-protocol/client'; import { getExpirationTimestamp } from '@vertex-protocol/contracts'; import { nowInSeconds, toFixedPoint } from '@vertex-protocol/utils'; import { getVertexClient, prettyPrintJson } from './common'; async function main() { const vertexClient = getVertexClient(); const { walletClient, publicClient } = vertexClient.context; const address = walletClient!.account.address; const subaccountName = 'default'; const depositAmount = toFixedPoint(1000, 6); const mintTxHash = await vertexClient.spot._mintMockERC20({ amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: mintTxHash, }); const approveTxHash = await vertexClient.spot.approveAllowance({ amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: approveTxHash, }); const depositTxHash = await vertexClient.spot.deposit({ subaccountName: 'default', amount: depositAmount, productId: 0, }); await publicClient.waitForTransactionReceipt({ hash: depositTxHash, }); await new Promise((resolve) => setTimeout(resolve, 10000)); const orderParams: PlaceOrderParams['order'] = { subaccountName, expiration: getExpirationTimestamp({ expirationTime: nowInSeconds() + 60, reduceOnly: false, type: 'post_only', }), price: 80000, // Setting order amount to 10**16 amount: toFixedPoint(0.01, 18), }; const placeOrderResult = await vertexClient.market.placeOrder({ order: orderParams, productId: 2, // Used for spot orders to enable/disable borrowing spotLeverage: undefined, }); prettyPrintJson('Place Order Result', placeOrderResult); const openOrders = await vertexClient.market.getOpenSubaccountOrders({ subaccountOwner: address, subaccountName, productId: 2, }); prettyPrintJson('Subaccount Open Orders', openOrders); const cancelOrderResult = await vertexClient.market.cancelOrders({ digests: [placeOrderResult.data.digest], productIds: [2], subaccountName: 'default', }); prettyPrintJson('Cancel Order Result', cancelOrderResult); await vertexClient.spot.withdraw({ productId: 0, amount: depositAmount - toFixedPoint(1, 6), subaccountName, }); } main(); ``` -------------------------------- ### Candlesticks Response Example Source: https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/candlesticks Example JSON response structure for historical candlestick data. ```JSON { "candlesticks": [ { "product_id": 1, "granularity": 60, "submission_idx": "627709", "timestamp": "1680118140", "open_x18": "27235000000000000000000", "high_x18": "27298000000000000000000", "low_x18": "27235000000000000000000", "close_x18": "27298000000000000000000", "volume": "1999999999999999998" }, { "product_id": 1, "granularity": 60, "submission_idx": "627699", "timestamp": "1680118080", "open_x18": "27218000000000000000000", "high_x18": "27245000000000000000000", "low_x18": "27218000000000000000000", "close_x18": "27245000000000000000000", "volume": "11852999999999999995" } ] } ``` -------------------------------- ### Vertex Protocol Perpetual Product Data Example (Product ID 2) Source: https://docs.vertexprotocol.com/developer-resources/api/gateway/queries/subaccount-info Example JSON data for a perpetual futures product (product_id: 2), showcasing specific parameters like cumulative funding, open interest, and LP funding details. ```json { "product_id": 2, "oracle_price_x18": "30219079716463070000000", "risk": { "long_weight_initial_x18": "875000000000000000", "short_weight_initial_x18": "1125000000000000000", "long_weight_maintenance_x18": "900000000000000000", "short_weight_maintenance_x18": "1100000000000000000", "large_position_penalty_x18": "0" }, "state": { "cumulative_funding_long_x18": "6363466629611946777168", "cumulative_funding_short_x18": "6363466629611946777168", "available_settle": "100612314098927536086702448", "open_interest": "57975708279961875623240" }, "lp_state": { "supply": "783207415944433511804197", "last_cumulative_funding_x18": "6363466629611946777168", "cumulative_funding_per_lp_x18": "-284321955122859921", "base": "37321000000000000000", "quote": "1150991638943862165224593" }, "book_info": { "size_increment": "1000000000000000", "price_increment_x18": "1000000000000000000", "min_size": "10000000000000000", "collected_fees": "7738341933653651206856235", "lp_spread_x18": "3000000000000000" } } ``` -------------------------------- ### Candlesticks Request Body Example Source: https://docs.vertexprotocol.com/developer-resources/api/archive-indexer/candlesticks Example JSON payload for requesting product candlesticks. ```JSON { "candlesticks": { "product_id": 1, "granularity": 60, "limit": 2 } } ```