@flexemarkets/fm-sdk 0.0.3 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +99 -0
- package/package.json +4 -1
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# fm-sdk-typescript
|
|
2
|
+
|
|
3
|
+
TypeScript / JavaScript SDK for the [Flexemarkets](https://api.flexemarkets.com) API.
|
|
4
|
+
|
|
5
|
+
## Requirements
|
|
6
|
+
|
|
7
|
+
- Node.js 22+ (ES modules)
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @flexemarkets/fm-sdk
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Configuration
|
|
16
|
+
|
|
17
|
+
The SDK loads credentials and endpoint from these sources (highest priority first):
|
|
18
|
+
|
|
19
|
+
1. Arguments passed to `Flexemarkets.connect()`
|
|
20
|
+
2. Files `~/.fm/credential` and `~/.fm/endpoint` (Java `.properties` format)
|
|
21
|
+
3. Environment variable `FM_API_URL` (defaults to `https://api.flexemarkets.com`)
|
|
22
|
+
|
|
23
|
+
### Credential file
|
|
24
|
+
|
|
25
|
+
Create `~/.fm/credential`:
|
|
26
|
+
|
|
27
|
+
```properties
|
|
28
|
+
account=myaccount
|
|
29
|
+
email=user@example.com
|
|
30
|
+
password=secret
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
Or use a bearer token:
|
|
34
|
+
|
|
35
|
+
```properties
|
|
36
|
+
token=eyJhbGciOiJIUzI1NiJ9...
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Endpoint file
|
|
40
|
+
|
|
41
|
+
Create `~/.fm/endpoint`:
|
|
42
|
+
|
|
43
|
+
```properties
|
|
44
|
+
endpoint=https://api.flexemarkets.com/api/marketplaces/123
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## SDK usage
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Flexemarkets, OrderBooks, MarketplaceTrades } from "@flexemarkets/fm-sdk";
|
|
51
|
+
import type { FmEvent } from "@flexemarkets/fm-sdk";
|
|
52
|
+
|
|
53
|
+
// connect(null, null, ...) falls back to ~/.fm/credential and ~/.fm/endpoint
|
|
54
|
+
const fm = await Flexemarkets.connect(null, null, "my-bot");
|
|
55
|
+
|
|
56
|
+
// REST API
|
|
57
|
+
const marketplaceId = fm.endpointMarketplaceId;
|
|
58
|
+
const markets = await fm.markets(marketplaceId);
|
|
59
|
+
const session = await fm.session(marketplaceId);
|
|
60
|
+
const holding = await fm.holding(marketplaceId);
|
|
61
|
+
|
|
62
|
+
// Submit orders
|
|
63
|
+
const order = await fm.submitLimit(marketplaceId, markets[0].id, "BUY", 1, 950);
|
|
64
|
+
await fm.submitCancel(marketplaceId, markets[0].id, order.id);
|
|
65
|
+
|
|
66
|
+
// WebSocket events
|
|
67
|
+
const books = new OrderBooks(markets);
|
|
68
|
+
const trades = new MarketplaceTrades(markets);
|
|
69
|
+
|
|
70
|
+
await fm.listen(marketplaceId, (event: FmEvent) => {
|
|
71
|
+
if ("kind" in event && event.kind === "orders-update") {
|
|
72
|
+
books.update(event.orders);
|
|
73
|
+
trades.update(event.orders);
|
|
74
|
+
} else if (!Array.isArray(event) && "state" in event) {
|
|
75
|
+
console.log(event.state); // Session
|
|
76
|
+
} else if ("cash" in event) {
|
|
77
|
+
console.log(event.cash); // Holding
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// when done
|
|
82
|
+
fm.close();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Example: ticker
|
|
86
|
+
|
|
87
|
+
The SDK includes a ticker example — a live terminal display of order book best
|
|
88
|
+
bid/ask, spread, and recent trade prices.
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
fm-ticker OPEN
|
|
92
|
+
|
|
93
|
+
Symbol Bid Ask Spread Last trades
|
|
94
|
+
------ ------ ------ ------ -----------
|
|
95
|
+
AAPL $ 9.50 $10.50 $ 1.00 $9.50 $10.00
|
|
96
|
+
IBM $ 4.00 $ 5.00 $ 1.00 $4.50
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
The display refreshes on each order book update. Press `Ctrl-C` to stop.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@flexemarkets/fm-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Flexemarkets TypeScript SDK",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
],
|
|
32
32
|
"author": "Flexemarkets <support@flexemarkets.com>",
|
|
33
33
|
"license": "MIT",
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=22"
|
|
36
|
+
},
|
|
34
37
|
"repository": {
|
|
35
38
|
"type": "git",
|
|
36
39
|
"url": "git+https://github.com/flexemarkets/fm-sdk.git",
|