We've open sourced our SDK for Devnet and Mainnet. Our SDK is a typescript library that can be used to interact with our Zeta program smart contract.
This page will go over the basics - loading up everything, seeing exchange state, placing/cancelling orders as well as some advanced functionality such as callbacks and events. For extra information, check out:
npm install @zetamarkets/sdk
You can change this via
Users have to subscribe to a market index for polling to be done on it. This is because each market requires 2 RPC requests, so polling all markets can easily hit rate limits if not on a dedicated provider.
// Subscribe to a market index.
// Unsubscribe to a market index.
// Manually poll a market index.
await Exchange.updateOrderbook(asset, index);
CrossClienthas a default poll interval of
constants.DEFAULT_CLIENT_POLL_INTERVAL(set to 20 seconds).
You can change this via
This is almost how often the SDK will call
await client.updateState(), which is the manual way of polling user state.
There is a timer that on default fires every 2 seconds, checking the last poll timestamp. If time greater than client.pollInterval has elapsed or there is a pending update, it will poll.
Pending update refers to a margin account websocket change callback. (The SDK subscribes to user
This will do multiple things (
- 1.Fetch user margin account (
- 2.Update user orders (this will poll the market orderbook for each market that the user has a non zero position or open orders in -
- 3.Update user positions (
This timer can be modified via
Tying into this, the motivation behind this complexity is that if a user is asynchronously placing and cancelling orders across multiple markets, you may receive multiple margin account callbacks across consecutive slots.
If each call back polls relevant markets for the latest user order state (2 polls per market), you can easily hit rate limits.
throttleis set to
CrossClient.load, then this timer allows users to batch client polling to the next timer interval (i.e. optimistically, 5 consecutive slot updates will only trigger 1 poll).
throttlecan be set to
client.updateStatewill be called on every margin account change and ensure you have the latest state at all times.
When you want to shut down or restart the client, call this to disconnect the respective websockets.
// Close exchange object.
// Close client object.