Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion typescript/phoenix-sdk/examples/printTraderIndices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Connection } from "@solana/web3.js";

import * as Phoenix from "../src";

// Ex: ts-node tests/printTraderIndices.ts
// Ex: ts-node examples/printTraderIndices.ts
export async function printTraderIndices() {
const connection = new Connection("https://api.mainnet-beta.solana.com");
const phoenix = await Phoenix.Client.create(connection);
Expand Down
43 changes: 43 additions & 0 deletions typescript/phoenix-sdk/examples/printTraderStates.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Connection } from "@solana/web3.js";

import * as Phoenix from "../src";

// Ex: ts-node examples/printTraderStates.ts
export async function printTraderStates() {
const connection = new Connection("https://api.mainnet-beta.solana.com");
const phoenix = await Phoenix.Client.create(connection);
for (const [marketAddress, market] of phoenix.marketConfigs) {
if (market.name === "SOL/USDC") {
console.log("SOL/USDC marketAddress: ", marketAddress);
const marketState = phoenix.marketStates.get(marketAddress);
if (!marketState) {
continue;
}
for (const [traderPubkey, traderState] of marketState.data.traders) {
console.log("Trader pubkey: ", traderPubkey);
console.log(
"Quote lots locked:",
traderState.quoteLotsLocked.toString()
);
console.log(
"Base lots locked: ",
traderState.baseLotsLocked.toString()
);
console.log("Quote lots free: ", traderState.quoteLotsFree.toString());
console.log("Base lots free: ", traderState.baseLotsFree.toString());
}
break;
}
}
}

(async function () {
try {
await printTraderStates();
} catch (err) {
console.log("Error: ", err);
process.exit(1);
}

process.exit(0);
})();