@bizjaya/finclient 0.1.1 → 0.2.1
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 +57 -22
- package/dist/index.cjs +372 -160
- package/dist/index.d.cts +3299 -657
- package/dist/index.d.ts +3299 -657
- package/dist/index.js +371 -159
- package/dist/webhook.cjs +49 -0
- package/dist/webhook.d.cts +11 -0
- package/dist/webhook.d.ts +11 -0
- package/dist/webhook.js +24 -0
- package/package.json +19 -8
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# @bizjaya/finclient
|
|
2
2
|
|
|
3
|
-
The official TypeScript SDK for FinCopy's public
|
|
3
|
+
The official TypeScript SDK for FinCopy's public API, `https://api.fincopy.io`. Since version 0.2.0 it uses numeric ACNO
|
|
4
|
+
account paths under `/v1/fxs`, which changed the 0.1 API; see the changelog before upgrading.
|
|
4
5
|
|
|
5
6
|
```sh
|
|
6
7
|
npm install @bizjaya/finclient
|
|
@@ -11,33 +12,67 @@ import { FinClient } from "@bizjaya/finclient";
|
|
|
11
12
|
|
|
12
13
|
const fin = new FinClient({ apiKey: process.env.FINCOPY_API_KEY! });
|
|
13
14
|
const accounts = await fin.copy.accounts.list();
|
|
14
|
-
for (const account of accounts) console.log(account.Fleet?.Account?.
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
15
|
+
for (const account of accounts.items) console.log(account.Fleet?.Account?.ACNO, account.Fleet?.Account?.Login);
|
|
16
|
+
|
|
17
|
+
// ACNO is in the route; the JSON body contains only trade fields.
|
|
18
|
+
// await fin.copy.orders.make(52014125, { SYM: "EURUSD", ACT: "NEW", OTY: "OP_BUY", LOT: 0.01 });
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
The client defaults to `https://api.fincopy.io`. Account-scoped methods take the numeric ACNO, and paged list methods
|
|
22
|
+
return `{ items, paging, ... }`. DTO fields keep the API's PascalCase names.
|
|
23
|
+
|
|
24
|
+
- `copy.accounts`: settings and lifecycle, pairs, symbols, quotes, orders, history, DCA, performance, activity, strategy
|
|
25
|
+
preview and apply, and terminal operations.
|
|
26
|
+
- `copy.orders`: preflight, trade, hedge, modify, cancel and DCA answers.
|
|
27
|
+
- `copy.fx`: lists across every account you can reach (pairs, orders, history, activity, DCA, terminal operations,
|
|
28
|
+
performance window and bars), strategies, signals, alerts, brokers and the event stream.
|
|
29
|
+
- `copy.changes` and `copy.webhooks`: the change feed and webhook setup.
|
|
30
|
+
|
|
31
|
+
## API key or member session
|
|
32
|
+
|
|
33
|
+
API-key mode is for trusted server-side code. Do not put an API key in browser JavaScript, a mobile app, a public
|
|
34
|
+
repository, or a client-side environment variable.
|
|
35
|
+
|
|
36
|
+
Member session mode sends the signed-in member's `fincopy_member` cookie instead of a key: omit `apiKey` and pass `fetch`.
|
|
37
|
+
A session client defaults to `credentials: "include"`, so in a browser page on a FinCopy site the browser's `fetch` sends
|
|
38
|
+
the cookie. On a server, pass a `fetch` that adds the cookie header.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const fin = new FinClient({ fetch: (input, init) => fetch(input, init) });
|
|
42
|
+
const account = await fin.copy.accounts.get(52014125);
|
|
22
43
|
```
|
|
23
44
|
|
|
24
|
-
|
|
45
|
+
The API accepts browser requests only from FinCopy's own sites. Session trade writes pass the member's trade-PIN gate on
|
|
46
|
+
the server. The main entry uses no Node.js built-ins, so it runs in browsers, Node.js 20+, Deno and Bun.
|
|
47
|
+
|
|
48
|
+
`copy.accounts.remove(acno, { TrPin }, options)` disconnects the hosted terminal, forgets its broker password and frees its seat.
|
|
49
|
+
Customer account settings and trade history remain so the login can be restored later; a free demo's account and terminal records
|
|
50
|
+
are deleted. Open orders stay at the broker, and virtual TP, SL and TS stop working while no terminal runs. Include the member's
|
|
51
|
+
trading PIN for a session account when its PIN is enabled; API-key requests do not use a session PIN. Pass an `idempotencyKey`
|
|
52
|
+
in `options` so retries receive the same operation.
|
|
53
|
+
|
|
54
|
+
## Results, errors and the stream
|
|
55
|
+
|
|
56
|
+
Trade calls report that an operation was queued; follow the stream, change feed or webhook for its terminal result. Errors
|
|
57
|
+
are raised as `FinApiError` with HTTP status, API code, validation errors, any `Retry-After` value, and an `errorCode` of
|
|
58
|
+
`timeout`, `network`, `rate_limited`, `invalid_response` or `empty_response` when the SDK set one. Retries reuse the same
|
|
59
|
+
`Idempotency-Key`.
|
|
25
60
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
rate limits, gateway errors and network failures, honouring the API's `Retry-After`.
|
|
61
|
+
`copy.fx.stream()` does not reconnect. It ends when the server closes it (about every 30 minutes); a broken connection
|
|
62
|
+
raises a `network` error. Open it again in a loop, waiting a few seconds between attempts.
|
|
29
63
|
|
|
30
|
-
|
|
31
|
-
client-side environment variable. FinCopy's envelope is handled by the client; DTO fields keep the API's PascalCase wire names.
|
|
32
|
-
Writes automatically carry an `Idempotency-Key`, which can be supplied explicitly in the request options when a caller needs
|
|
33
|
-
to retry the same operation later. Orders complete asynchronously; use the change feed or webhook to learn their result.
|
|
64
|
+
## Webhooks
|
|
34
65
|
|
|
35
|
-
|
|
36
|
-
|
|
66
|
+
Webhook verification is server-side and uses Node.js's crypto module, so it has its own entry:
|
|
67
|
+
|
|
68
|
+
```ts
|
|
69
|
+
import { FinWebhook } from "@bizjaya/finclient/webhook";
|
|
70
|
+
|
|
71
|
+
const valid = FinWebhook.verify(secret, timestampHeader, rawBody, signatureHeader);
|
|
72
|
+
```
|
|
37
73
|
|
|
38
|
-
See [FinCopy API docs](https://fincopy.io/docs)
|
|
39
|
-
[
|
|
40
|
-
because it places a trade.
|
|
74
|
+
See the [FinCopy API docs](https://fincopy.io/docs), the [QuickStart](./examples/QuickStart.ts), and the
|
|
75
|
+
[FinClient source](https://github.com/bizjaya/FinClient).
|
|
41
76
|
|
|
42
77
|
## Build from source
|
|
43
78
|
|