@bizjaya/finclient 0.1.1 → 0.2.0
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 +51 -22
- package/dist/index.cjs +371 -161
- package/dist/index.d.cts +3134 -521
- package/dist/index.d.ts +3134 -521
- package/dist/index.js +370 -160
- 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 +13 -2
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.pro`. Version 0.2.0 uses numeric ACNO account
|
|
4
|
+
paths under `/v1/fxs` and changes the 0.1 API; see the changelog before upgrading.
|
|
4
5
|
|
|
5
6
|
```sh
|
|
6
7
|
npm install @bizjaya/finclient
|
|
@@ -11,33 +12,61 @@ 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
|
-
for await (const page of fin.copy.changes.readPages(cursor)) {
|
|
19
|
-
for (const change of page.Changes ?? []) console.log(change.Entity, change.AccountId, change.OID, change.Status);
|
|
20
|
-
if (page.Cursor) saveCursor(page.Cursor);
|
|
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 });
|
|
22
19
|
```
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
The client defaults to `https://api.fincopy.pro`. 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);
|
|
43
|
+
```
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
rate limits, gateway errors and network failures, honouring the API's `Retry-After`.
|
|
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 18+, Deno and Bun.
|
|
29
47
|
|
|
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.
|
|
48
|
+
## Results, errors and the stream
|
|
34
49
|
|
|
35
|
-
|
|
36
|
-
|
|
50
|
+
Trade calls report that an operation was queued; follow the stream, change feed or webhook for its terminal result. Errors
|
|
51
|
+
are raised as `FinApiError` with HTTP status, API code, validation errors, any `Retry-After` value, and an `errorCode` of
|
|
52
|
+
`timeout`, `network`, `rate_limited`, `invalid_response` or `empty_response` when the SDK set one. Retries reuse the same
|
|
53
|
+
`Idempotency-Key`.
|
|
54
|
+
|
|
55
|
+
`copy.fx.stream()` does not reconnect. It ends when the server closes it (about every 30 minutes); a broken connection
|
|
56
|
+
raises a `network` error. Open it again in a loop, waiting a few seconds between attempts.
|
|
57
|
+
|
|
58
|
+
## Webhooks
|
|
59
|
+
|
|
60
|
+
Webhook verification is server-side and uses Node.js's crypto module, so it has its own entry:
|
|
61
|
+
|
|
62
|
+
```ts
|
|
63
|
+
import { FinWebhook } from "@bizjaya/finclient/webhook";
|
|
64
|
+
|
|
65
|
+
const valid = FinWebhook.verify(secret, timestampHeader, rawBody, signatureHeader);
|
|
66
|
+
```
|
|
37
67
|
|
|
38
|
-
See [FinCopy API docs](https://fincopy.io/docs)
|
|
39
|
-
[
|
|
40
|
-
because it places a trade.
|
|
68
|
+
See the [FinCopy API docs](https://fincopy.io/docs), the [QuickStart](./examples/QuickStart.ts), and the
|
|
69
|
+
[FinClient source](https://github.com/bizjaya/FinClient).
|
|
41
70
|
|
|
42
71
|
## Build from source
|
|
43
72
|
|