@flexemarkets/fm-sdk
v0.0.5
Published
Flexemarkets TypeScript SDK
Downloads
511
Maintainers
Readme
fm-sdk-typescript
TypeScript / JavaScript SDK for the Flexemarkets API.
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, OrderBooks, MarketplaceTrades } from "@flexemarkets/fm-sdk";
import type { FmEvent } 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);
// WebSocket events
const books = new OrderBooks(markets);
const trades = new MarketplaceTrades(markets);
await fm.listen(marketplaceId, (event: FmEvent) => {
if ("kind" in event && event.kind === "orders-update") {
books.update(event.orders);
trades.update(event.orders);
} else if (!Array.isArray(event) && "state" in event) {
console.log(event.state); // Session
} else if ("cash" in event) {
console.log(event.cash); // Holding
}
});
// when done
fm.close();Example: ticker
The SDK includes a ticker example — a live terminal display of order book best bid/ask, spread, and recent trade prices.
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.
