@flexemarkets/fm-sdk
v0.7.0
Published
Flexemarkets TypeScript SDK
Maintainers
Readme
fm-sdk-typescript
TypeScript / JavaScript SDK for the Flexemarkets API.
⚠️ Alpha software — the API is not stable
fm-sdk is pre-1.0 and under active development. Anything public may be added, renamed, or removed in any release, including in ways that break code that compiles and runs today, and without a deprecation period first. Under semantic versioning a
0.xrelease carries no compatibility promise, and that is how these versions are used: treat every0.xbump as potentially breaking.Pin an exact version rather than a range (
"@flexemarkets/fm-sdk": "0.2.0", not^0.2.0), read the upgrade notes for the release you are moving to, and expect to change code when you move.Not recommended for production use.
Requirements
- Node.js 22+ (ES modules)
Install
npm install @flexemarkets/fm-sdkConfiguration
The SDK loads credentials and endpoint from these sources (highest priority first):
- Arguments passed to
Flexemarkets.connect() - Files
~/.fm/credentialand~/.fm/endpoint(Java.propertiesformat) - Environment variable
FM_API_URL(defaults tohttps://api.flexemarkets.com)
Credential file
Create ~/.fm/credential:
account=myaccount
[email protected]
password=secretOr use a bearer token:
token=eyJhbGciOiJIUzI1NiJ9...Endpoint file
Create ~/.fm/endpoint:
endpoint=https://api.flexemarkets.com/api/marketplaces/123SDK usage
import { Flexemarkets } from "@flexemarkets/fm-sdk";
// connect(null, null, ...) falls back to ~/.fm/credential and ~/.fm/endpoint
const fm = await Flexemarkets.connect(null, null, "my-bot");
// REST API
const marketplaceId = fm.endpointMarketplaceId;
const markets = await fm.markets(marketplaceId);
const session = await fm.session(marketplaceId);
const holding = await fm.holding(marketplaceId);
// Submit orders
const order = await fm.submitLimit(marketplaceId, markets[0].id, "BUY", 1, 950);
await fm.submitCancel(marketplaceId, markets[0].id, order.id);
// Live market data. A desk keeps the books and tapes for you: it seeds them
// over REST, applies deltas, and re-seeds after a sequence gap.
const desk = await fm.desk(marketplaceId);
const marketId = markets[0].id;
desk.onBookChange(marketId, (book) => console.log(book.bestPrice("BUY")));
desk.onSessionChange((s) => console.log(s.state));
desk.onHoldingChange((h) => console.log(h.cash));
const one = desk.book(marketId); // one market
for (const book of desk.books()) { // every market in the marketplace
console.log(book.symbol, book.bestPrice("BUY"));
}
desk.close();Example: ticker
The SDK includes a ticker example — a live terminal display of order book best bid/ask, spread, and recent trade prices.
npx tsx src/ticker.ts -C ~/.fm/credential -E 123Options:
| Flag | Description |
|------|-------------|
| -C, --credential | Credential file path or bearer token |
| -E, --endpoint | Marketplace id, endpoint file path, or URL |
Output:
fm-ticker OPEN
Symbol Bid Ask Spread Last trades
------ ------ ------ ------ -----------
AAPL $ 9.50 $10.50 $ 1.00 $9.50 $10.00
IBM $ 4.00 $ 5.00 $ 1.00 $4.50The display refreshes on each order book update. Press Ctrl-C to stop.
