Pies
| Method | Does | Permission | Limit |
|---|---|---|---|
pies.list() |
Every pie, with its progress | pies:read |
1 / 30 s |
pies.get(id) |
One pie with its instruments | pies:read |
1 / 5 s |
pies.create(pie) |
Makes a pie | pies:write |
1 / 5 s |
pies.update(id, pie) |
Changes a pie’s settings or instruments | pies:write |
1 / 5 s |
pies.duplicate(id, copy?) |
Copies a pie, optionally renamed | pies:write |
1 / 5 s |
pies.delete(id) |
Deletes a pie | pies:write |
1 / 5 s |
import { Trading212 } from "@kkkermit/trading212.js";
// Changing pies counts as trading, so a live client needs trading: "enabled".const t212 = Trading212.fromEnv();
const pies = await t212.pies.list();for (const pie of pies) console.log(pie.id, pie.status, pie.cash);
const [first] = pies;if (typeof first?.id === "number") { const details = await t212.pies.get(first.id); console.log(details.settings?.name, details.instruments?.length, "instruments");
const copy = await t212.pies.duplicate(first.id, { name: `${details.settings?.name} copy`, }); console.log(`Made pie ${copy.settings?.id}`);}
const created = await t212.pies.create({ name: "Big tech", dividendCashAction: "REINVEST", instrumentShares: { AAPL_US_EQ: 0.5, MSFT_US_EQ: 0.5 },});console.log(`Created pie ${created.settings?.id}`);const { Trading212 } = require("@kkkermit/trading212.js");
async function main() { // Changing pies counts as trading, so a live client needs trading: "enabled". const t212 = Trading212.fromEnv();
const pies = await t212.pies.list(); for (const pie of pies) console.log(pie.id, pie.status, pie.cash);
const [first] = pies; if (typeof first?.id === "number") { const details = await t212.pies.get(first.id); console.log(details.settings?.name, details.instruments?.length, "instruments");
const copy = await t212.pies.duplicate(first.id, { name: `${details.settings?.name} copy`, }); console.log(`Made pie ${copy.settings?.id}`); }
const created = await t212.pies.create({ name: "Big tech", dividendCashAction: "REINVEST", instrumentShares: { AAPL_US_EQ: 0.5, MSFT_US_EQ: 0.5 }, }); console.log(`Created pie ${created.settings?.id}`);}
main().catch((error) => { console.error(error); process.exitCode = 1;});A pie takes name, icon, goal, endDate, dividendCashAction ("REINVEST" or "TO_ACCOUNT_CASH") and
instrumentShares, a map of ticker to its share of the pie, adding up to 1.
Changing a pie counts as trading: a live client needs trading: "enabled", and a change is never retried.