Skip to content

Commit f2e7a0f

Browse files
authored
Merge pull request Nexacore-Org#359 from Fahmedo/main
commit issue Nexacore-Org#348, Nexacore-Org#349, Nexacore-Org#347 ,Nexacore-Org#346
2 parents f73798b + ef1bb35 commit f2e7a0f

30 files changed

Lines changed: 2905 additions & 0 deletions

sdk/nexafx-js/README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# NexaFx JavaScript SDK
2+
3+
TypeScript client for core NexaFX APIs with generated OpenAPI types, built on native `fetch` and `WebSocket`.
4+
5+
## Install
6+
7+
```bash
8+
npm install @nexacore-org/nexafx-js
9+
```
10+
11+
## Generate types
12+
13+
From the backend root:
14+
15+
```bash
16+
npm run sdk:openapi
17+
cd sdk/nexafx-js
18+
npm install
19+
npm run generate:types
20+
```
21+
22+
## Create a client
23+
24+
```ts
25+
import { NexaFxClient } from '@nexacore-org/nexafx-js';
26+
27+
const client = new NexaFxClient({
28+
baseURL: 'https://api.nexafx.com',
29+
});
30+
```
31+
32+
## Login and token storage
33+
34+
```ts
35+
const client = new NexaFxClient({
36+
baseURL: 'https://api.nexafx.com',
37+
});
38+
39+
await client.auth.login({
40+
email: 'trader@nexafx.com',
41+
password: 'CorrectHorseBatteryStaple!123',
42+
otp: '123456',
43+
});
44+
```
45+
46+
If the backend returns `accessToken` or `refreshToken`, the SDK stores them automatically and retries one failed `401` request by calling `/v1/auth/refresh`.
47+
48+
## Create a transaction
49+
50+
```ts
51+
const transaction = await client.transactions.create({
52+
type: 'deposit',
53+
amount: 100.5,
54+
currency: 'XLM',
55+
sourceAddress: 'GDQP2KPQGKIHYJGXNUIYOMHARUARCA7DJT5FO2FFOOUJ3UHMNGUAO7UP',
56+
});
57+
```
58+
59+
## Iterate paginated transactions
60+
61+
```ts
62+
for await (const item of client.transactions.iterate({ limit: 50 })) {
63+
console.log(item.id, item.status);
64+
}
65+
```
66+
67+
## Subscribe to prices
68+
69+
```ts
70+
const unsubscribe = client.websocket.subscribeToPrices(['EURUSD'], (price) => {
71+
console.log(price.symbol, price.bid, price.ask);
72+
});
73+
74+
unsubscribe();
75+
```
76+
77+
## Build
78+
79+
```bash
80+
npm run build
81+
```

0 commit comments

Comments
 (0)