Forkast Developer Docs
Forkast SDK Integration Guide
Examples
2 min
these typescript examples show common forkast client flows authenticate with a signed message, place and manage orders, cancel in bulk, and redeem positions each snippet is ready to drop into a script and highlights the minimum inputs you need place bulk orders authenticates, submits multiple orders in one request (up to 5), then fetches open orders and cancels a specific order by its id import { accountservice, orderservice, network } from "@forkastgg/client"; import type { loginresponse, bulkorderinput } from "@forkastgg/client"; const network = network mainnet; const apikey = process env test api key ?? ""; const privatekey = process env test private key ?? ""; const wallet = process env test wallet ?? ""; const proxywallet = process env test proxy wallet ?? ""; async function main() { const accountservice = new accountservice(network, apikey); const orderservice = new orderservice(network, apikey); const login loginresponse = await accountservice loginwithprivatekey(privatekey); const { accesstoken } = login; const orders bulkorderinput\[] = \[ { tokenid "token id here", side 0, price 0 78, amount 86 }, { tokenid "token id here", side 0, price 0 79, amount 86 }, { tokenid "token id here", side 0, price 0 8, amount 86 }, ]; const bulk = await orderservice placebulkorders( orders, { wallet, proxy wallet proxywallet, private key privatekey }, accesstoken ); console log("bulk", bulk); const all = await orderservice getallorders(wallet, 123, accesstoken); const first = all orderresult? data? \[0]; if (first) { const cancel = await orderservice cancelorder(string(first orders id), accesstoken); console log("cancel", cancel); } } main() catch(console error); redeem all positions authenticates, loads resolved positions, builds a redeem payload for up to 10 markets, and submits a single redeem transaction for all import { accountservice, marketstatus, network } from "@forkastgg/client"; import type { loginresponse } from "@forkastgg/client"; const network = network mainnet; const apikey = process env test api key ?? ""; const privatekey = process env test private key ?? ""; const proxywallet = process env test proxy wallet ?? ""; async function main() { const accountservice = new accountservice(network, apikey); const login loginresponse = await accountservice loginwithprivatekey(privatekey); const { accesstoken } = login; const positions = await accountservice getpositions( accesstoken, 1, 10, marketstatus resolved ); const redeemdata = (positions results ?? \[]) map((p any) => { const marketid = number(p marketid ?? p market id); const resolvedaddress = string(p resolvedaddress ?? p resolved address ?? ""); const questionid = string(p questionid ?? p question id ?? ""); const outcometype = number(p outcometype ?? p outcome type); if (!marketid || !resolvedaddress || !questionid || number isnan(outcometype)) { return null; } return { marketid, resolvedaddress, questionid, outcometype }; }) filter(boolean) slice(0, 10); if (redeemdata length === 0) { console log("no redeemable positions "); return; } const redeem = await accountservice redeemallpositions( accesstoken, redeemdata, proxywallet, privatekey ); console log(redeem); } main() catch(console error);