HTTP API for your Loop wallet + Temple V2 REST integration: holdings, merge, market data, and limit order actions via /v1/orders/*. Callers send Authorization: Bearer <SERVER_API_KEY>.
Market data (see docs/STRATEGY.md, docs/TEMPLE_MM_ARCHITECTURE.md):
GET /market/ticker— Fair reference from Binancebtcusdt@bookTickeronly (BINANCE_WS_URL). Not Temple.GET /market/orderbook— Temple venue book for basis / sanity checks only, not fair-value truth.
Temple REST auth: TEMPLE_API_KEY only (no email/password path).
-
Copy
.env.exampleto.envand set every variable shown there (no implicit defaults in code for network URLs or keys):- Loop:
PRIVATE_KEY,PARTY_ID,LOOP_NETWORK,WALLET_URL,API_URL - Temple:
NETWORK,TEMPLE_API_KEYNETWORK=testnet->https://api-testnet.templedigitalgroup.com/api/v1/...NETWORK=mainnet->https://api.templedigitalgroup.com/api/v1/...
- Binance (reference price):
BINANCE_WS_URL— e.g.wss://stream.binance.com:9443/ws/btcusdt@bookTicker - Server:
SERVER_API_KEY,PORT
- Loop:
-
Install and build:
npm install
npm run build- Start:
npm startThe process connects to Binance over WebSocket on startup so /market/ticker can serve live reference prices.
npm run validateThis repository provides the Temple SDK service and supporting tooling for building trading and ledger-integrated applications. This README has been rewritten to highlight the primary technologies used in the project—especially Canton and DAML—and to give clear setup and development guidance.
- Core purpose: a Node/TypeScript HTTP API and background services that connect to Temple REST/WS and external market feeds (e.g. Binance) to expose holdings, market data, and order features.
- Primary smart-contract / ledger tech: DAML (for contract modeling) and Canton (as the multi-party ledger/runtime for private, secure DAML apps).
- The codebase is TypeScript (Node.js). Key runtime pieces also interact with WebSocket market feeds and external REST APIs.
- DAML — The high-level language used to model financial contracts and workflows. DAML apps are compiled and deployed to ledgers.
- Canton — A multi-party ledger platform that can host DAML applications with privacy and multi-party execution guarantees. Canton provides the network and runtime for parties to run shared DAML contracts.
- Node.js + TypeScript — API, middlewares, and integration logic (the
src/folder). - WebSockets & REST — Live market feeds (Binance) and external venue integration (Temple APIs).
If you are new to DAML or Canton, the official docs are strongly recommended:
- DAML: https://docs.daml.com/
- Canton: https://www.digitalasset.com/canton (or the Canton repo/docs from your vendor)
Prerequisites
- Node.js (LTS, e.g. >=16 or a version your project requires)
- npm or yarn
- (If you work with DAML/Canton) DAML SDK and Canton tooling installed locally or accessible via CI/deployment environment
Install dependencies
# from repo root
npm installBuild and run
npm run build # if present; otherwise `ts-node` or your preferred runner
npm start # runs the service (if package.json defines start)Note: If package.json uses other script names (e.g. dev, mm, test:routes), use those instead. Check package.json for exact scripts.
Environment
- Copy
.env.exampleto.envand set the required environment variables for your environment. Typical values include API keys, network URLs, and feed endpoints (e.g.BINANCE_WS_URL,TEMPLE_API_KEY,TEMPLE_WS_URL,SERVER_API_KEY,PORT).
This repository primarily contains the TypeScript service layer. If your project includes DAML contracts and you plan to use Canton for deployment, follow these steps as a high-level guide:
- Model your agreements in DAML and keep DAML sources in a dedicated directory (e.g.
daml/orledger/). - Build DAML package(s):
- daml build # produces .dar files
- Deploy to Canton (or your preferred ledger runtime):
- Use your Canton tooling or operator scripts to create domains, participants, and to upload the DAML archive (.dar). The exact commands depend on your Canton installation and operator scripts.
- Connect the Node service to Canton:
- Use the Canton client libraries or a light-weight integration layer (for example an existing TypeScript/JS wrapper such as
temple-canton-jsif present) to submit commands and subscribe to events. - Configure connection parameters (host, port, TLS, credentials) in
.env.
- Run integration tests and system tests that exercise end-to-end behavior (smart contracts on Canton, plus the Node API and market feeds).
Important: DAML/Canton are large systems with specific operational requirements (certificates, parties, topology). Follow your organization's Canton/DAML runbook or the official docs for secure configuration and production setup.
src/— TypeScript source codeindex.ts— entry pointinit.ts,mm-runner.ts— initialization and market-maker runnerfeeds/— market feed clients (e.g.binance-book-ticker.ts,temple-ws.ts)middleware/— express middlewares (auth, etc.)routes/— HTTP route handlers (holdings, instruments, market, merge, orders)services/— integration services (trading logic, ledger adapters)types/— project ambient/type declarations (e.g.temple-canton-js.d.ts)
Any DAML/Canton-specific code or configuration (if present) should be kept in a clearly named folder like daml/ or canton/.
PORT— HTTP server portSERVER_API_KEY— API key for internal callersTEMPLE_API_KEY— Temple REST API keyTEMPLE_WS_URL— Temple WebSocket URL for book/trade eventsBINANCE_WS_URL— Binance ws stream url for price referenceCANTON_*— Canton connection details (host, port, TLS settings) — use names matching your deployment
Create a .env.example entry for any new variables and document them here when you add them.
- Keep DAML models and Node integration decoupled: DAML models describe the ledger's business logic; the Node service orchestrates off-ledger interactions, market feeds, and REST APIs.
- Tests: Add unit tests for service and route logic (Jest, Mocha, or your preferred runner). Add lightweight integration tests that mock external feeds and a separate suite for end-to-end testing against a Canton dev network.
- Security: Do not commit production keys. Use secret management for production deployments.
- Fork the repo and create a feature branch.
- Add tests for new behavior.
- Open a PR describing the change.
If your change includes DAML contracts or Canton topology changes, include deployment instructions and any necessary operator steps.
- DAML docs: https://docs.daml.com/
- Canton docs: vendor or org-provided Canton documentation
See LICENSE in the repository root (or add one if missing).
If you'd like, I can also:
- add a small
daml/README with commands to build.darfiles and link to Canton deploy steps, or - scaffold a
CONTRIBUTING.mdwith a sample PR/test workflow.
Tell me which follow-up you'd like and I'll add it.