@bitgen/sdk 0.1.6 → 1.0.4
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/CHANGELOG.md +63 -2
- package/README.md +27 -106
- package/dist/cjs/client.d.ts +20 -8
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +33 -12
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/constants.d.ts +256 -0
- package/dist/cjs/constants.d.ts.map +1 -0
- package/dist/cjs/constants.js +214 -0
- package/dist/cjs/constants.js.map +1 -0
- package/dist/cjs/error.d.ts +17 -10
- package/dist/cjs/error.d.ts.map +1 -1
- package/dist/cjs/error.js +25 -7
- package/dist/cjs/error.js.map +1 -1
- package/dist/cjs/http.d.ts +13 -8
- package/dist/cjs/http.d.ts.map +1 -1
- package/dist/cjs/http.js +135 -44
- package/dist/cjs/http.js.map +1 -1
- package/dist/cjs/index.d.ts +14 -1
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +30 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/resources/apikeys.d.ts +18 -0
- package/dist/cjs/resources/apikeys.d.ts.map +1 -0
- package/dist/cjs/resources/apikeys.js +31 -0
- package/dist/cjs/resources/apikeys.js.map +1 -0
- package/dist/cjs/resources/asset.d.ts +17 -5
- package/dist/cjs/resources/asset.d.ts.map +1 -1
- package/dist/cjs/resources/asset.js +17 -6
- package/dist/cjs/resources/asset.js.map +1 -1
- package/dist/cjs/resources/bank.d.ts +11 -6
- package/dist/cjs/resources/bank.d.ts.map +1 -1
- package/dist/cjs/resources/bank.js +17 -9
- package/dist/cjs/resources/bank.js.map +1 -1
- package/dist/cjs/resources/core.d.ts +12 -0
- package/dist/cjs/resources/core.d.ts.map +1 -0
- package/dist/cjs/resources/core.js +22 -0
- package/dist/cjs/resources/core.js.map +1 -0
- package/dist/cjs/resources/custody.d.ts +27 -0
- package/dist/cjs/resources/custody.d.ts.map +1 -0
- package/dist/cjs/resources/custody.js +38 -0
- package/dist/cjs/resources/custody.js.map +1 -0
- package/dist/cjs/resources/customer.d.ts +20 -0
- package/dist/cjs/resources/customer.d.ts.map +1 -0
- package/dist/cjs/resources/customer.js +38 -0
- package/dist/cjs/resources/customer.js.map +1 -0
- package/dist/cjs/resources/staking.d.ts +32 -0
- package/dist/cjs/resources/staking.d.ts.map +1 -0
- package/dist/cjs/resources/staking.js +69 -0
- package/dist/cjs/resources/staking.js.map +1 -0
- package/dist/cjs/resources/trading.d.ts +24 -0
- package/dist/cjs/resources/trading.d.ts.map +1 -0
- package/dist/cjs/resources/trading.js +41 -0
- package/dist/cjs/resources/trading.js.map +1 -0
- package/dist/cjs/resources/transaction.d.ts +6 -9
- package/dist/cjs/resources/transaction.d.ts.map +1 -1
- package/dist/cjs/resources/transaction.js +10 -15
- package/dist/cjs/resources/transaction.js.map +1 -1
- package/dist/cjs/resources/webhooks.d.ts +46 -0
- package/dist/cjs/resources/webhooks.d.ts.map +1 -0
- package/dist/cjs/resources/webhooks.js +142 -0
- package/dist/cjs/resources/webhooks.js.map +1 -0
- package/dist/cjs/types/apikeys.d.ts +43 -0
- package/dist/cjs/types/apikeys.d.ts.map +1 -0
- package/dist/cjs/types/apikeys.js +3 -0
- package/dist/cjs/types/apikeys.js.map +1 -0
- package/dist/cjs/types/asset.d.ts +57 -0
- package/dist/cjs/types/asset.d.ts.map +1 -0
- package/dist/cjs/types/asset.js +3 -0
- package/dist/cjs/types/asset.js.map +1 -0
- package/dist/cjs/types/bank.d.ts +58 -0
- package/dist/cjs/types/bank.d.ts.map +1 -0
- package/dist/cjs/types/bank.js +3 -0
- package/dist/cjs/types/bank.js.map +1 -0
- package/dist/cjs/types/core.d.ts +32 -0
- package/dist/cjs/types/core.d.ts.map +1 -0
- package/dist/cjs/types/core.js +3 -0
- package/dist/cjs/types/core.js.map +1 -0
- package/dist/cjs/types/custody.d.ts +50 -0
- package/dist/cjs/types/custody.d.ts.map +1 -0
- package/dist/cjs/types/custody.js +3 -0
- package/dist/cjs/types/custody.js.map +1 -0
- package/dist/cjs/types/customer.d.ts +190 -0
- package/dist/cjs/types/customer.d.ts.map +1 -0
- package/dist/cjs/types/customer.js +3 -0
- package/dist/cjs/types/customer.js.map +1 -0
- package/dist/cjs/types/index.d.ts +78 -194
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +0 -1
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/staking.d.ts +88 -0
- package/dist/cjs/types/staking.d.ts.map +1 -0
- package/dist/cjs/types/staking.js +3 -0
- package/dist/cjs/types/staking.js.map +1 -0
- package/dist/cjs/types/trading.d.ts +51 -0
- package/dist/cjs/types/trading.d.ts.map +1 -0
- package/dist/cjs/types/trading.js +3 -0
- package/dist/cjs/types/trading.js.map +1 -0
- package/dist/cjs/types/transaction.d.ts +61 -0
- package/dist/cjs/types/transaction.d.ts.map +1 -0
- package/dist/cjs/types/transaction.js +3 -0
- package/dist/cjs/types/transaction.js.map +1 -0
- package/dist/cjs/types/webhooks.d.ts +55 -0
- package/dist/cjs/types/webhooks.d.ts.map +1 -0
- package/dist/cjs/types/webhooks.js +3 -0
- package/dist/cjs/types/webhooks.js.map +1 -0
- package/dist/cjs/utils.d.ts +21 -2
- package/dist/cjs/utils.d.ts.map +1 -1
- package/dist/cjs/utils.js +67 -4
- package/dist/cjs/utils.js.map +1 -1
- package/dist/cjs/version.d.ts +2 -0
- package/dist/cjs/version.d.ts.map +1 -0
- package/dist/cjs/version.js +6 -0
- package/dist/cjs/version.js.map +1 -0
- package/dist/esm/client.d.ts +20 -8
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +33 -12
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/constants.d.ts +256 -0
- package/dist/esm/constants.d.ts.map +1 -0
- package/dist/esm/constants.js +211 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/error.d.ts +17 -10
- package/dist/esm/error.d.ts.map +1 -1
- package/dist/esm/error.js +24 -6
- package/dist/esm/error.js.map +1 -1
- package/dist/esm/http.d.ts +13 -8
- package/dist/esm/http.d.ts.map +1 -1
- package/dist/esm/http.js +136 -45
- package/dist/esm/http.js.map +1 -1
- package/dist/esm/index.d.ts +14 -1
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/resources/apikeys.d.ts +18 -0
- package/dist/esm/resources/apikeys.d.ts.map +1 -0
- package/dist/esm/resources/apikeys.js +27 -0
- package/dist/esm/resources/apikeys.js.map +1 -0
- package/dist/esm/resources/asset.d.ts +17 -5
- package/dist/esm/resources/asset.d.ts.map +1 -1
- package/dist/esm/resources/asset.js +17 -6
- package/dist/esm/resources/asset.js.map +1 -1
- package/dist/esm/resources/bank.d.ts +11 -6
- package/dist/esm/resources/bank.d.ts.map +1 -1
- package/dist/esm/resources/bank.js +18 -10
- package/dist/esm/resources/bank.js.map +1 -1
- package/dist/esm/resources/core.d.ts +12 -0
- package/dist/esm/resources/core.d.ts.map +1 -0
- package/dist/esm/resources/core.js +18 -0
- package/dist/esm/resources/core.js.map +1 -0
- package/dist/esm/resources/custody.d.ts +27 -0
- package/dist/esm/resources/custody.d.ts.map +1 -0
- package/dist/esm/resources/custody.js +34 -0
- package/dist/esm/resources/custody.js.map +1 -0
- package/dist/esm/resources/customer.d.ts +20 -0
- package/dist/esm/resources/customer.d.ts.map +1 -0
- package/dist/esm/resources/customer.js +34 -0
- package/dist/esm/resources/customer.js.map +1 -0
- package/dist/esm/resources/staking.d.ts +32 -0
- package/dist/esm/resources/staking.d.ts.map +1 -0
- package/dist/esm/resources/staking.js +65 -0
- package/dist/esm/resources/staking.js.map +1 -0
- package/dist/esm/resources/trading.d.ts +24 -0
- package/dist/esm/resources/trading.d.ts.map +1 -0
- package/dist/esm/resources/trading.js +37 -0
- package/dist/esm/resources/trading.js.map +1 -0
- package/dist/esm/resources/transaction.d.ts +6 -9
- package/dist/esm/resources/transaction.d.ts.map +1 -1
- package/dist/esm/resources/transaction.js +11 -16
- package/dist/esm/resources/transaction.js.map +1 -1
- package/dist/esm/resources/webhooks.d.ts +46 -0
- package/dist/esm/resources/webhooks.d.ts.map +1 -0
- package/dist/esm/resources/webhooks.js +138 -0
- package/dist/esm/resources/webhooks.js.map +1 -0
- package/dist/esm/types/apikeys.d.ts +43 -0
- package/dist/esm/types/apikeys.d.ts.map +1 -0
- package/dist/esm/types/apikeys.js +2 -0
- package/dist/esm/types/apikeys.js.map +1 -0
- package/dist/esm/types/asset.d.ts +57 -0
- package/dist/esm/types/asset.d.ts.map +1 -0
- package/dist/esm/types/asset.js +2 -0
- package/dist/esm/types/asset.js.map +1 -0
- package/dist/esm/types/bank.d.ts +58 -0
- package/dist/esm/types/bank.d.ts.map +1 -0
- package/dist/esm/types/bank.js +2 -0
- package/dist/esm/types/bank.js.map +1 -0
- package/dist/esm/types/core.d.ts +32 -0
- package/dist/esm/types/core.d.ts.map +1 -0
- package/dist/esm/types/core.js +2 -0
- package/dist/esm/types/core.js.map +1 -0
- package/dist/esm/types/custody.d.ts +50 -0
- package/dist/esm/types/custody.d.ts.map +1 -0
- package/dist/esm/types/custody.js +2 -0
- package/dist/esm/types/custody.js.map +1 -0
- package/dist/esm/types/customer.d.ts +190 -0
- package/dist/esm/types/customer.d.ts.map +1 -0
- package/dist/esm/types/customer.js +2 -0
- package/dist/esm/types/customer.js.map +1 -0
- package/dist/esm/types/index.d.ts +78 -194
- package/dist/esm/types/index.d.ts.map +1 -1
- package/dist/esm/types/index.js +0 -1
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/staking.d.ts +88 -0
- package/dist/esm/types/staking.d.ts.map +1 -0
- package/dist/esm/types/staking.js +2 -0
- package/dist/esm/types/staking.js.map +1 -0
- package/dist/esm/types/trading.d.ts +51 -0
- package/dist/esm/types/trading.d.ts.map +1 -0
- package/dist/esm/types/trading.js +2 -0
- package/dist/esm/types/trading.js.map +1 -0
- package/dist/esm/types/transaction.d.ts +61 -0
- package/dist/esm/types/transaction.d.ts.map +1 -0
- package/dist/esm/types/transaction.js +2 -0
- package/dist/esm/types/transaction.js.map +1 -0
- package/dist/esm/types/webhooks.d.ts +55 -0
- package/dist/esm/types/webhooks.d.ts.map +1 -0
- package/dist/esm/types/webhooks.js +2 -0
- package/dist/esm/types/webhooks.js.map +1 -0
- package/dist/esm/utils.d.ts +21 -2
- package/dist/esm/utils.d.ts.map +1 -1
- package/dist/esm/utils.js +62 -4
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +2 -0
- package/dist/esm/version.d.ts.map +1 -0
- package/dist/esm/version.js +3 -0
- package/dist/esm/version.js.map +1 -0
- package/package.json +29 -12
- package/readme/concepts.md +128 -0
- package/readme/configuration.md +72 -0
- package/readme/errors.md +67 -0
- package/readme/installation.md +43 -0
- package/readme/media/activation.svg +58 -0
- package/readme/media/deposit-flow.svg +70 -0
- package/readme/media/order-buy.svg +43 -0
- package/readme/media/order-sell.svg +47 -0
- package/readme/media/purchase-flow.svg +61 -0
- package/readme/media/sale-flow.svg +61 -0
- package/readme/media/staking-position.svg +75 -0
- package/readme/media/transaction-lifecycle.svg +61 -0
- package/readme/media/webhook-delivery.svg +53 -0
- package/readme/media/withdrawal-flow.svg +64 -0
- package/readme/quick-start.md +87 -0
- package/readme/resource/apikeys.md +103 -0
- package/readme/resource/asset.md +121 -0
- package/readme/resource/bank.md +161 -0
- package/readme/resource/core.md +91 -0
- package/readme/resource/custody.md +166 -0
- package/readme/resource/customer.md +210 -0
- package/readme/resource/staking.md +281 -0
- package/readme/resource/trading.md +171 -0
- package/readme/resource/transaction.md +110 -0
- package/readme/resource/webhooks.md +309 -0
- package/src/client.ts +46 -0
- package/src/constants.ts +281 -0
- package/src/error.ts +36 -0
- package/src/http.ts +201 -0
- package/src/index.ts +111 -0
- package/src/resources/apikeys.ts +30 -0
- package/src/resources/asset.ts +28 -0
- package/src/resources/bank.ts +39 -0
- package/src/resources/core.ts +19 -0
- package/src/resources/custody.ts +37 -0
- package/src/resources/customer.ts +46 -0
- package/src/resources/staking.ts +88 -0
- package/src/resources/trading.ts +41 -0
- package/src/resources/transaction.ts +20 -0
- package/src/resources/webhooks.ts +169 -0
- package/src/types/apikeys.ts +35 -0
- package/src/types/asset.ts +59 -0
- package/src/types/bank.ts +60 -0
- package/src/types/core.ts +32 -0
- package/src/types/custody.ts +40 -0
- package/src/types/customer.ts +189 -0
- package/src/types/index.ts +215 -0
- package/src/types/staking.ts +87 -0
- package/src/types/trading.ts +56 -0
- package/src/types/transaction.ts +62 -0
- package/src/types/webhooks.ts +60 -0
- package/src/utils.ts +74 -0
- package/src/version.ts +2 -0
- package/dist/cjs/resources/order.d.ts +0 -17
- package/dist/cjs/resources/order.d.ts.map +0 -1
- package/dist/cjs/resources/order.js +0 -30
- package/dist/cjs/resources/order.js.map +0 -1
- package/dist/cjs/resources/stats.d.ts +0 -11
- package/dist/cjs/resources/stats.d.ts.map +0 -1
- package/dist/cjs/resources/stats.js +0 -18
- package/dist/cjs/resources/stats.js.map +0 -1
- package/dist/cjs/resources/user.d.ts +0 -22
- package/dist/cjs/resources/user.d.ts.map +0 -1
- package/dist/cjs/resources/user.js +0 -37
- package/dist/cjs/resources/user.js.map +0 -1
- package/dist/cjs/resources/wallet.d.ts +0 -11
- package/dist/cjs/resources/wallet.d.ts.map +0 -1
- package/dist/cjs/resources/wallet.js +0 -19
- package/dist/cjs/resources/wallet.js.map +0 -1
- package/dist/esm/resources/order.d.ts +0 -17
- package/dist/esm/resources/order.d.ts.map +0 -1
- package/dist/esm/resources/order.js +0 -26
- package/dist/esm/resources/order.js.map +0 -1
- package/dist/esm/resources/stats.d.ts +0 -11
- package/dist/esm/resources/stats.d.ts.map +0 -1
- package/dist/esm/resources/stats.js +0 -14
- package/dist/esm/resources/stats.js.map +0 -1
- package/dist/esm/resources/user.d.ts +0 -22
- package/dist/esm/resources/user.d.ts.map +0 -1
- package/dist/esm/resources/user.js +0 -33
- package/dist/esm/resources/user.js.map +0 -1
- package/dist/esm/resources/wallet.d.ts +0 -11
- package/dist/esm/resources/wallet.d.ts.map +0 -1
- package/dist/esm/resources/wallet.js +0 -15
- package/dist/esm/resources/wallet.js.map +0 -1
- package/dist/types/client.d.ts +0 -19
- package/dist/types/client.d.ts.map +0 -1
- package/dist/types/error.d.ts +0 -15
- package/dist/types/error.d.ts.map +0 -1
- package/dist/types/http.d.ts +0 -21
- package/dist/types/http.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -4
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/resources/asset.d.ts +0 -11
- package/dist/types/resources/asset.d.ts.map +0 -1
- package/dist/types/resources/bank.d.ts +0 -13
- package/dist/types/resources/bank.d.ts.map +0 -1
- package/dist/types/resources/order.d.ts +0 -17
- package/dist/types/resources/order.d.ts.map +0 -1
- package/dist/types/resources/stats.d.ts +0 -11
- package/dist/types/resources/stats.d.ts.map +0 -1
- package/dist/types/resources/transaction.d.ts +0 -15
- package/dist/types/resources/transaction.d.ts.map +0 -1
- package/dist/types/resources/user.d.ts +0 -22
- package/dist/types/resources/user.d.ts.map +0 -1
- package/dist/types/resources/wallet.d.ts +0 -11
- package/dist/types/resources/wallet.d.ts.map +0 -1
- package/dist/types/types/index.d.ts +0 -213
- package/dist/types/types/index.d.ts.map +0 -1
- package/dist/types/utils.d.ts +0 -7
- package/dist/types/utils.d.ts.map +0 -1
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
# Staking
|
|
2
|
+
|
|
3
|
+
Staking places the crypto of a customer with a staking provider to earn rewards. A **provider** is a `CoreType.STAKING` connector of the platform, one per asset (`figment_sol`, `bitgen_eth`…), with its own rate, minimum deposit and lock-up periods. Staking is driven by a **movement** — the request to stake, rewritten into the exit when the position is left entirely — attached to a **position**, the capital placed with the provider. `client.staking` lists the providers, opens a position, follows the movements, claims rewards, unstakes, and reads the operations and the EUR portfolio of a customer.
|
|
4
|
+
|
|
5
|
+
Two distinct identifiers: `stake` returns the uuid of a **movement**, which `get`, `list` and `movements` handle; the **position** it opened is `movement.staking.uuid`, which `rewards` and `unstake` take.
|
|
6
|
+
|
|
7
|
+
Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). A customer is designated by a `UserRef`: their uuid, or a model carrying it, such as the `Created` returned by `client.customer.create` ([User references](../concepts.md#user-references)). A customer who is not an activated member of your organization is refused with `403 org_forbidden` ([Activation and identity](../concepts.md#activation-and-identity)).
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+
|
|
11
|
+
## Methods
|
|
12
|
+
|
|
13
|
+
| Method | What it does | Returns |
|
|
14
|
+
|---|---|---|
|
|
15
|
+
| `providers(asset?)` | Lists the staking providers, for one asset or all | `Page<Core>` |
|
|
16
|
+
| `stake(user, params)` | Places crypto with a provider: opens a position | `Created` (the movement) |
|
|
17
|
+
| `list(params?)` | Lists the movements of your organization, all states | `Page<StakingMovement>` |
|
|
18
|
+
| `movements(params?)` | Lists the movements still in progress: `StakingMovementState.REQUESTED`, `PENDING`, `FAILED` | `Page<StakingMovement>` |
|
|
19
|
+
| `get(movement)` | Reads one movement and its position | `StakingMovement` |
|
|
20
|
+
| `rewards(position, params?)` | Claims the rewards of a position | `void` |
|
|
21
|
+
| `unstake(position, params?)` | Leaves a position, partially or entirely | `void` |
|
|
22
|
+
| `operations(user, params?)` | Lists the staking operations of a customer | `Page<StakingOperation>` |
|
|
23
|
+
| `portfolio(user)` | Reads the EUR balances and curves of a customer's staking | `StakingPortfolio` |
|
|
24
|
+
|
|
25
|
+
TypeScript types of this resource, exported by the package: `StakingPosition`, `StakingMovement`, `StakingOperation`, `StakingPortfolio`, `StakeParams`, `StakingListParams`, `StakingAmountParams` — the constants `StakingMovementState`, `StakingMovementKind`, `StakingPositionState` (also types) — plus the shared `UserRef`, `UserSummary`, `OrganizationSummary`, `AssetRef`, `AssetInput`, `Created`, `Amount`, `PageParams`, `Core`, `CoreRef`.
|
|
26
|
+
|
|
27
|
+
## Providers
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
client.staking.providers(asset?: AssetInput): Promise<Page<Core>>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
A shortcut of `client.core.list({ type: CoreType.STAKING, asset })` ([Connectors](core.md)).
|
|
34
|
+
|
|
35
|
+
| Parameter | Type | Description |
|
|
36
|
+
|---|---|---|
|
|
37
|
+
| `asset` | `AssetInput` | Optional: only the providers of this asset, by uuid or ISO code (`Asset.SOL`) or by model ([Assets](../concepts.md#assets)) |
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
import { Asset, CoreState } from '@bitgen/sdk'
|
|
41
|
+
|
|
42
|
+
const { items: providers } = await client.staking.providers(Asset.SOL)
|
|
43
|
+
|
|
44
|
+
for (const provider of providers) {
|
|
45
|
+
console.log(provider.name, provider.state === CoreState.ENABLED) // 'figment_sol' true
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Returns the `CoreType.STAKING` connectors, not paginated. The `uuid` or the `name` of a provider is the `provider` of `stake`. Its `config` describes the offer:
|
|
50
|
+
|
|
51
|
+
| Config field | Meaning |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `connector` | The BITGEN connector |
|
|
54
|
+
| `apr` or `apy` | Annual rate, in % |
|
|
55
|
+
| `min_deposit` | Minimum deposit, in asset units |
|
|
56
|
+
| `deposit_locked_period` | Activation delay of a deposit |
|
|
57
|
+
| `rewards_locked_period` | Waiting period before a rewards withdrawal is paid |
|
|
58
|
+
| `unstake_locked_period` | Lock-up before an unstake is paid |
|
|
59
|
+
| `can_choose_withdrawal`, `can_choose_rewards` | Whether partial amounts are allowed (otherwise total only) |
|
|
60
|
+
| `min_rewards_eur` | Minimum EUR value of a rewards claim |
|
|
61
|
+
|
|
62
|
+
Periods are written `<unit>@<n>` with the unit `H`, `D`, `W`, `M` or `Y` — `D@3` is 3 days.
|
|
63
|
+
|
|
64
|
+
## Stake
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
client.staking.stake(user: UserRef, params: StakeParams): Promise<Created>
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
| Parameter | Type | Description |
|
|
71
|
+
|---|---|---|
|
|
72
|
+
| `params.asset` | `AssetInput` | The asset, by uuid or ISO code (`Asset.SOL`) or by model ([Assets](../concepts.md#assets)) |
|
|
73
|
+
| `params.amount` | `Amount` | The crypto quantity to stake, as a string, at least the provider's minimum deposit (`min_deposit` in its configuration, see `providers()`) — `422 amount_below_minimum` below it ([Amounts](../concepts.md#amounts)) |
|
|
74
|
+
| `params.provider` | `string` | The `uuid` or the `name` of a `CoreType.STAKING` connector of your organization (`providers`) |
|
|
75
|
+
|
|
76
|
+
```ts
|
|
77
|
+
import { Asset, StakingMovementState } from '@bitgen/sdk'
|
|
78
|
+
|
|
79
|
+
const { items: providers } = await client.staking.providers(Asset.SOL)
|
|
80
|
+
|
|
81
|
+
const { uuid: movementId } = await client.staking.stake('CUSTOMER_UUID', {
|
|
82
|
+
asset: Asset.SOL,
|
|
83
|
+
amount: '2',
|
|
84
|
+
provider: providers[0].name, // 'figment_sol'
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
const movement = await client.staking.get(movementId)
|
|
88
|
+
console.log(movement.state === StakingMovementState.REQUESTED) // true
|
|
89
|
+
console.log(movement.staking.uuid) // the position, for `rewards` and `unstake`
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
The amount is moved from the customer's custody wallet to the deposit address of the provider through an internal transfer: the errors of a custody withdrawal can surface ([Custody wallets › Errors](custody.md#errors)), in particular `416 requested_amount_error` for an insufficient crypto balance. Returns a `Created` — the uuid of the **movement**.
|
|
93
|
+
|
|
94
|
+
## List
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
client.staking.list(params?: StakingListParams): Promise<Page<StakingMovement>>
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The movements of your organization, in every state.
|
|
101
|
+
|
|
102
|
+
| Parameter | Type | Description |
|
|
103
|
+
|---|---|---|
|
|
104
|
+
| `params.user` | `UserRef` | Only the movements of this customer (uuid or model; unknown → `404 unknown_user`) |
|
|
105
|
+
| `params.direction` | `StakingMovementKind` | Only this kind of movement: `StakingMovementKind.STAKE`, `UNSTAKE`, `WITHDRAW` or `REWARD` — absent, all. A movement is `STAKE`, then `UNSTAKE` after a full exit; `WITHDRAW` and `REWARD` match no movement — a partial exit and a claim create none — and give an empty page |
|
|
106
|
+
| `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { StakingMovementKind } from '@bitgen/sdk'
|
|
110
|
+
|
|
111
|
+
const { count, items } = await client.staking.list({ user: 'CUSTOMER_UUID', direction: StakingMovementKind.STAKE })
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Returns a page of `StakingMovement` ([get](#get)).
|
|
115
|
+
|
|
116
|
+
## Movements
|
|
117
|
+
|
|
118
|
+
```
|
|
119
|
+
client.staking.movements(params?: StakingListParams): Promise<Page<StakingMovement>>
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The movements still in progress: `StakingMovementState.REQUESTED`, `PENDING` and `FAILED` only. Same parameters as `list`.
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
const pending = await client.staking.movements({ user: 'CUSTOMER_UUID' })
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Returns a page of `StakingMovement` ([get](#get)).
|
|
129
|
+
|
|
130
|
+
## Get
|
|
131
|
+
|
|
132
|
+
```
|
|
133
|
+
client.staking.get(movement: string | StakingMovement): Promise<StakingMovement>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`movement` is the uuid returned by `stake`, or a `StakingMovement`.
|
|
137
|
+
|
|
138
|
+
```ts
|
|
139
|
+
import { StakingMovementKind, StakingMovementState, StakingPositionState } from '@bitgen/sdk'
|
|
140
|
+
|
|
141
|
+
const movement = await client.staking.get('MOVEMENT_UUID')
|
|
142
|
+
|
|
143
|
+
console.log(movement.kind === StakingMovementKind.STAKE, movement.state === StakingMovementState.COMPLETED, movement.amount) // true true '2'
|
|
144
|
+
console.log(movement.staking.state === StakingPositionState.ENABLED, movement.staking.data.rewards) // true '0.0123'
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Returns a `StakingMovement`:
|
|
148
|
+
|
|
149
|
+
| Field | Description |
|
|
150
|
+
|---|---|
|
|
151
|
+
| `uuid` | The movement |
|
|
152
|
+
| `state` | `StakingMovementState.REQUESTED`, `PENDING`, `COMPLETED`, `FAILED` or `CANCELED` — the cycle is below the table |
|
|
153
|
+
| `kind` | `StakingMovementKind.STAKE` from the request, `UNSTAKE` once a full exit is requested — the same movement, rewritten; `WITHDRAW` and `REWARD` are values of the `direction` filter and of the operations journal, carried by no movement |
|
|
154
|
+
| `provider` | The `name` of the staking connector (`figment_sol`) |
|
|
155
|
+
| `amount` | The quantity of the movement, as a string |
|
|
156
|
+
| `createdAt`, `updatedAt` | Epoch seconds |
|
|
157
|
+
| `staking` | The position (`StakingPosition`): `uuid`, `state` (`StakingPositionState.CREATED`, `ENABLED`, `UNSTAKING`, `CLOSED` or `FAILED`), `amount` (the net capital placed, as a string), `error` (failure reason when `FAILED`, `null` otherwise), `data` (`rewards`: rewards accrued and available, in asset units, as a string; `lastRewardAt`: epoch seconds of the last daily accrual — when available), `createdAt`, `updatedAt`, `core` (`CoreRef`: `{ uuid, name, label }`, the provider) |
|
|
158
|
+
| `owner` | `UserSummary`: `{ uuid, state, login, account: { firstname, lastname, fin } }` — the customer, a `UserRef` |
|
|
159
|
+
| `asset` | `AssetRef`: `{ uuid, iso, label }` |
|
|
160
|
+
| `organization` | `OrganizationSummary`: `{ uuid, state, name }`, or `null` |
|
|
161
|
+
|
|
162
|
+
A position has a single movement, whose uuid — the one returned by `stake` — never changes. The movement goes `STAKE` `REQUESTED` → `PENDING` (the deposit is on its way; the `amount` of the position becomes the net quantity received) → `COMPLETED` (the position is `ENABLED`); `REQUESTED` → `FAILED` when the transfer fails, `PENDING` → `CANCELED` when the platform cancels the request — the position is `FAILED` in both cases. A full exit (`unstake`) rewrites the same movement `UNSTAKE` `REQUESTED` (the position is `UNSTAKING`), then `COMPLETED` when the platform closes the position (`CLOSED`). A partial exit and a claim leave the movement untouched: the position stays `ENABLED`, its `amount` and `data.rewards` decrease.
|
|
163
|
+
|
|
164
|
+
An unknown movement, or one outside your organization, answers `404 unknown_staking_movement`.
|
|
165
|
+
|
|
166
|
+
## Rewards
|
|
167
|
+
|
|
168
|
+
```
|
|
169
|
+
client.staking.rewards(position: string | StakingPosition, params?: StakingAmountParams): Promise<void>
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
`position` is `movement.staking.uuid`, or `movement.staking` itself.
|
|
173
|
+
|
|
174
|
+
| Parameter | Type | Description |
|
|
175
|
+
|---|---|---|
|
|
176
|
+
| `params.amount` | `Amount` | Optional: the rewards to claim, as a string — absent, all of them; the EUR value must reach the provider's minimum (`min_rewards_eur`) — `422 amount_below_minimum` below it ([Amounts](../concepts.md#amounts)) |
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
const movement = await client.staking.get('MOVEMENT_UUID')
|
|
180
|
+
|
|
181
|
+
await client.staking.rewards(movement.staking) // all the rewards — the position, by model
|
|
182
|
+
await client.staking.rewards('POSITION_UUID', { amount: '0.01' }) // part of them, by uuid
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
The amount is deducted from the position immediately; the transfer is executed by compliance. No movement is created or changed: `data.rewards` of the position decreases, and the event `staking.claimed` reports the claim. Without rewards to claim the API answers `425 no_rewards`; a partial amount below the minimum of the provider, `422 amount_below_minimum`. The API answers with an empty body: the promise resolves with `undefined`.
|
|
186
|
+
|
|
187
|
+
## Unstake
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
client.staking.unstake(position: string | StakingPosition, params?: StakingAmountParams): Promise<void>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`position` is `movement.staking.uuid`, or `movement.staking` itself.
|
|
194
|
+
|
|
195
|
+
| Parameter | Type | Description |
|
|
196
|
+
|---|---|---|
|
|
197
|
+
| `params.amount` | `Amount` | Optional: the capital to withdraw from the position, as a string — absent, the whole position; a partial exit must reach the provider's minimum deposit — `422 amount_below_minimum` below it; a full exit (no amount) ignores it ([Amounts](../concepts.md#amounts)) |
|
|
198
|
+
|
|
199
|
+
```ts
|
|
200
|
+
const movement = await client.staking.get('MOVEMENT_UUID')
|
|
201
|
+
|
|
202
|
+
await client.staking.unstake('POSITION_UUID', { amount: '1' }) // partial exit, by uuid
|
|
203
|
+
await client.staking.unstake(movement.staking) // full exit — the position, by model
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
The amount is deducted from the position immediately; the transfer is executed by compliance. A full exit — no `amount`, or the whole position — rewrites the movement of the position: `kind` `UNSTAKE`, `state` `REQUESTED`, and the position is `UNSTAKING`; follow it with `get` and the uuid returned by `stake`; the event `staking.status` reports `UNSTAKING`, then `CLOSED` once the platform closes the position. A partial exit touches no movement: the position stays `ENABLED` with a reduced `amount`, and `staking.status` reports `WITHDRAWAL`. A full exit ignores the minimums; a partial amount below the minimum of the provider answers `422 amount_below_minimum`. The position must be past the lock-up period of the provider (`425 deposit_locked_period_not_elapsed`) and its staking movement completed (`412 staking_movement_not_completed`). The API answers with an empty body: the promise resolves with `undefined`.
|
|
207
|
+
|
|
208
|
+
## Operations
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
client.staking.operations(user: UserRef, params?: PageParams): Promise<Page<StakingOperation>>
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
| Parameter | Type | Description |
|
|
215
|
+
|---|---|---|
|
|
216
|
+
| `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
|
|
217
|
+
|
|
218
|
+
```ts
|
|
219
|
+
const { count, items } = await client.staking.operations('CUSTOMER_UUID', { offset: 0, limit: 50 })
|
|
220
|
+
|
|
221
|
+
for (const operation of items) {
|
|
222
|
+
console.log(operation.date, operation.event, operation.amount, operation.value) // 1701000000 'reward' '0.0123' 25.1
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Returns a page of `StakingOperation`: `txId` (journal entry id), `movement` (uuid of the movement of the position — `reward` and `claim` entries carry it too — or `null`), `asset` (iso), `kind` (`StakingMovementKind.STAKE`, `UNSTAKE`, `WITHDRAW` or `REWARD` — `REWARD` for the `reward` and `claim` entries), `amount` (asset units, as a string), `price` (EUR price of the asset at that time), `value` (EUR value), `event` (`validated`, `failed`, `canceled`, `reward`, `claim` or `closed` — other values may appear), `provider` (connector name), `date` (epoch seconds). An unknown customer, or one outside your organization, answers `404 unknown_staking`.
|
|
227
|
+
|
|
228
|
+
## Portfolio
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
client.staking.portfolio(user: UserRef): Promise<StakingPortfolio>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
```ts
|
|
235
|
+
const portfolio = await client.staking.portfolio('CUSTOMER_UUID')
|
|
236
|
+
|
|
237
|
+
console.log(portfolio.balances) // { capital: 4060.2, revenues: 25.1 } — EUR
|
|
238
|
+
console.log(portfolio.histories.capital.m) // EUR capital, one point per day over the last month
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
Returns a `StakingPortfolio`: `uuid`, `balances` (`{ capital, revenues }`, EUR), `histories` (`{ capital, revenues }`, two `History` curves — [Timestamps and histories](../concepts.md#timestamps-and-histories)). An unknown customer, or one outside your organization, answers `404 unknown_staking` — deliberately the same code, so that the answer reveals nothing.
|
|
242
|
+
|
|
243
|
+
## Errors
|
|
244
|
+
|
|
245
|
+
In addition to the [common errors](../errors.md#common-errors), and the custody withdrawal errors `stake` can surface ([Custody wallets › Errors](custody.md#errors)):
|
|
246
|
+
|
|
247
|
+
| Status | `code` | Meaning |
|
|
248
|
+
|---|---|---|
|
|
249
|
+
| `400` | `invalid_amount` | The amount is not valid |
|
|
250
|
+
| `403` | `org_forbidden` | The customer is not an activated member of your organization |
|
|
251
|
+
| `403` | `account_frozen` | The customer's account is frozen |
|
|
252
|
+
| `403` | `kyc_not_validated` | Your organization uses BITGEN's identity verification and the customer's identity is not validated ([Activation and identity](../concepts.md#activation-and-identity)) |
|
|
253
|
+
| `403` | `user_actions_disabled` | Customer actions are disabled for your organization (`user_can_actions` flag) |
|
|
254
|
+
| `404` | `unknown_user` | `stake`: unknown customer; `list`, `movements`: unknown `user` |
|
|
255
|
+
| `404` | `unknown_core` | `stake`: unknown `provider` |
|
|
256
|
+
| `404` | `unknown_asset` | Unknown asset |
|
|
257
|
+
| `404` | `unknown_organization` | The organization is unknown |
|
|
258
|
+
| `404` | `unknown_staking_movement` | `get`: unknown movement, or outside your organization |
|
|
259
|
+
| `404` | `unknown_staking` | `rewards`, `unstake`: unknown position — `operations`, `portfolio`: unknown customer, or outside your organization |
|
|
260
|
+
| `412` | `staking_connector_missing` | The provider has no connector that can be resolved |
|
|
261
|
+
| `412` | `staking_not_enabled` | The `CoreType.STAKING` connector of your organization is not enabled |
|
|
262
|
+
| `412` | `custody_not_enabled` | The `CoreType.CUSTODY` connector of your organization is not enabled |
|
|
263
|
+
| `412` | `staking_deposit_address_missing` | The provider has no deposit address |
|
|
264
|
+
| `412` | `staking_movement_not_completed` | `unstake`: the staking movement is not completed yet |
|
|
265
|
+
| `416` | `amount_precision_exceeded` | More decimals than the asset allows |
|
|
266
|
+
| `416` | `insufficient_rewards` | `rewards`: not enough rewards for the amount |
|
|
267
|
+
| `416` | `insufficient_balance` | `unstake`: not enough capital for the amount |
|
|
268
|
+
| `422` | `amount_below_minimum` | The amount is below the minimum of the provider (`min_deposit` on `stake`, a partial amount on `rewards` / `unstake`) |
|
|
269
|
+
| `422` | `staking_not_active` | The position is not active |
|
|
270
|
+
| `423` | `blocked_by_alert` | An active compliance alert blocks the customer |
|
|
271
|
+
| `424` | `token_price_unavailable` | `rewards`: no price is available for the token |
|
|
272
|
+
| `425` | `no_rewards` | `rewards`: nothing to claim |
|
|
273
|
+
| `425` | `no_balance` | `unstake`: nothing to withdraw |
|
|
274
|
+
| `425` | `deposit_locked_period_not_elapsed` | `unstake`: the lock-up period of the deposit has not elapsed |
|
|
275
|
+
|
|
276
|
+
## Related
|
|
277
|
+
|
|
278
|
+
- [Connectors](core.md) — the `CoreType.STAKING` connectors, their `config`
|
|
279
|
+
- [Custody wallets](custody.md) — the wallet the staked amount is taken from
|
|
280
|
+
- [Amounts](../concepts.md#amounts) — crypto amounts as strings, minimums
|
|
281
|
+
- [Webhooks](webhooks.md) — `staking.requested`, `staking.status`, `staking.rewards`, `staking.claimed`
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
# Trading
|
|
2
|
+
|
|
3
|
+
Trading buys crypto for a customer with the EUR of their bank account, and sells crypto from their custody wallets, through the exchange of the platform. `client.trading` places purchases and sales, reads an order and lists the orders of your organization.
|
|
4
|
+
|
|
5
|
+
Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). The customer of an order is designated by a `UserRef` — their uuid, or a model carrying it, not an email ([User references](../concepts.md#user-references)) and must be an `ENABLED` member of your organization: a customer who has not activated their account is refused with `403 user_not_in_scope` ([Activation and identity](../concepts.md#activation-and-identity)).
|
|
6
|
+
|
|
7
|
+
## Methods
|
|
8
|
+
|
|
9
|
+
| Method | What it does | Returns |
|
|
10
|
+
|---|---|---|
|
|
11
|
+
| `buy(user, params)` | Buys crypto with EUR from the customer's bank account | `{ tunnel, state }` |
|
|
12
|
+
| `sell(user, params)` | Sells crypto from the customer's custody wallet | `{ tunnel, state }` |
|
|
13
|
+
| `get(order)` | Reads one order | `Order` |
|
|
14
|
+
| `list(params?)` | Lists the orders of your organization, optionally filtered by customer (`user`), side and asset | `Page<Order>` |
|
|
15
|
+
|
|
16
|
+
TypeScript types of this resource, exported by the package: `Order`, `OrderUser`, `OrderOrganization`, `TradingOrderParams`, `TradingListParams` — the constants `OrderState`, `OrderSide`, `TradingDirection` (also types) — plus the shared `UserRef`, `AssetRef`, `AssetInput`, `Amount`, `Page`.
|
|
17
|
+
|
|
18
|
+
## Buy
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
client.trading.buy(user: UserRef, params: TradingOrderParams): Promise<{ tunnel: string, state: OrderState }>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Parameter | Type | Description |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `params.asset` | `AssetInput` | The asset to buy, by uuid or ISO code (`Asset.ETH`) or by model ([Assets](../concepts.md#assets)) — it must be `AVAILABLE` |
|
|
27
|
+
| `params.amount` | `Amount` | EUR to spend, 2 decimals max; a minimum applies — `416 invalid_amount` below it ([Amounts](../concepts.md#amounts)) |
|
|
28
|
+
| `params.reference` | `string` | Optional idempotency key, per customer, side and reference: replaying it returns the existing order |
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { Asset, OrderState } from '@bitgen/sdk'
|
|
32
|
+
|
|
33
|
+
const { tunnel, state } = await client.trading.buy('CUSTOMER_UUID', {
|
|
34
|
+
asset: Asset.ETH,
|
|
35
|
+
amount: '25.00',
|
|
36
|
+
reference: 'order-42',
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const order = await client.trading.get(tunnel)
|
|
40
|
+
console.log(order.state === OrderState.DONE, order.received, order.executedPrice) // true 0.0123 2031.5
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The API reserves `amount` on the customer's EUR account (`423 insufficient_funds` if the balance is insufficient, `404 unknown_bank` without an EUR account) and creates the order. `tunnel` is its uuid, `state` its initial state.
|
|
44
|
+
|
|
45
|
+

|
|
46
|
+
|
|
47
|
+
## Sell
|
|
48
|
+
|
|
49
|
+
```
|
|
50
|
+
client.trading.sell(user: UserRef, params: TradingOrderParams): Promise<{ tunnel: string, state: OrderState }>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
| Parameter | Type | Description |
|
|
54
|
+
|---|---|---|
|
|
55
|
+
| `params.asset` | `AssetInput` | The asset to sell, by uuid or ISO code (`Asset.ETH`) or by model — it must be `AVAILABLE` |
|
|
56
|
+
| `params.amount` | `Amount` | The crypto quantity to sell, as a string, at most the decimals of the asset; the EUR value of the quantity must reach a minimum — `416 invalid_amount` below it ([Amounts](../concepts.md#amounts)) |
|
|
57
|
+
| `params.reference` | `string` | Optional idempotency key, per customer, side and reference |
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { Asset } from '@bitgen/sdk'
|
|
61
|
+
|
|
62
|
+
const { tunnel } = await client.trading.sell('CUSTOMER_UUID', {
|
|
63
|
+
asset: Asset.ETH,
|
|
64
|
+
amount: '0.01',
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
const order = await client.trading.get(tunnel)
|
|
68
|
+
console.log(order.received) // EUR credited to the bank account once the order is DONE
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
The sale takes the crypto from the customer's custody wallet through an internal transfer to the exchange: the errors of a custody withdrawal can surface ([Custody wallets › Errors](custody.md#errors)), in particular `416 requested_amount_error` for an insufficient crypto balance and `503 custody_vault_unavailable`.
|
|
72
|
+
|
|
73
|
+

|
|
74
|
+
|
|
75
|
+
## Get
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
client.trading.get(order: string | Order): Promise<Order>
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`order` is the uuid returned as `tunnel` by `buy` and `sell`, or an `Order`.
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
import { OrderSide, OrderState } from '@bitgen/sdk'
|
|
85
|
+
|
|
86
|
+
const order = await client.trading.get('ORDER_UUID')
|
|
87
|
+
|
|
88
|
+
console.log(order.side === OrderSide.BUY, order.state === OrderState.DONE) // true true
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Returns an `Order`:
|
|
92
|
+
|
|
93
|
+
| Field | Description |
|
|
94
|
+
|---|---|
|
|
95
|
+
| `uuid` | The order — the `tunnel` of `buy` / `sell` |
|
|
96
|
+
| `state` | A purchase goes `OrderState.REGISTERED` → `EXECUTING` → `FILLED` → `DELIVERING` → `DONE`; a sale `REGISTERED` → `TRANSFERRING` → `DEPOSITED` → `EXECUTING` → `FILLED` → `DONE`. `FAILED` and `PARKED` are terminal, reached before anything of the target asset was received: `FAILED` from `REGISTERED` or `EXECUTING` for a purchase (the EUR reserve is released), from `REGISTERED`, `TRANSFERRING` or `EXECUTING` for a sale (the crypto goes back to the wallet); `PARKED` from `EXECUTING` only — executed, but nothing of the target asset was received; the BITGEN team takes over |
|
|
97
|
+
| `side` | `OrderSide.BUY` or `OrderSide.SELL` |
|
|
98
|
+
| `amount` | What was asked, as a string: EUR for a purchase (`"25.00"`), a crypto quantity for a sale |
|
|
99
|
+
| `reference` | The idempotency key given, or `null` |
|
|
100
|
+
| `received` | What the customer got, or `null`: the crypto quantity for a purchase, the EUR credited for a sale |
|
|
101
|
+
| `executedPrice` | The EUR price of the token, or `null` |
|
|
102
|
+
| `fee` | Exchange fee, in EUR, or `null` |
|
|
103
|
+
| `completedAt`, `createdAt` | Epoch seconds — `completedAt` is `null` until the order completes |
|
|
104
|
+
| `user` | `OrderUser`: `{ uuid, login }` — a `UserRef` |
|
|
105
|
+
| `organization` | `OrderOrganization`: `{ uuid, name }` |
|
|
106
|
+
| `asset` | `AssetRef`: `{ uuid, iso, label }` |
|
|
107
|
+
|
|
108
|
+
An order outside your organization answers `404 unknown_order`.
|
|
109
|
+
|
|
110
|
+
## List
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
client.trading.list(params?: TradingListParams): Promise<Page<Order>>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
The orders of your organization, optionally filtered by customer (`user`), side and asset.
|
|
117
|
+
|
|
118
|
+
| Parameter | Type | Description |
|
|
119
|
+
|---|---|---|
|
|
120
|
+
| `params.user` | `UserRef` | Only the orders of this customer (uuid or model; unknown → `404 unknown_user`) |
|
|
121
|
+
| `params.direction` | `TradingDirection` | `TradingDirection.BUY` or `TradingDirection.SELL` (lowercase values) — absent, both |
|
|
122
|
+
| `params.asset` | `AssetInput` | Only this asset, by ISO code, uuid or model |
|
|
123
|
+
| `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
import { Asset, TradingDirection } from '@bitgen/sdk'
|
|
127
|
+
|
|
128
|
+
const { count, items } = await client.trading.list({
|
|
129
|
+
user: 'CUSTOMER_UUID',
|
|
130
|
+
direction: TradingDirection.SELL,
|
|
131
|
+
asset: Asset.ETH,
|
|
132
|
+
offset: 0,
|
|
133
|
+
limit: 50,
|
|
134
|
+
})
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Returns a page of `Order`.
|
|
138
|
+
|
|
139
|
+
## Errors
|
|
140
|
+
|
|
141
|
+
In addition to the [common errors](../errors.md#common-errors), and the custody withdrawal errors a sale can surface ([Custody wallets › Errors](custody.md#errors)):
|
|
142
|
+
|
|
143
|
+
| Status | `code` | Meaning |
|
|
144
|
+
|---|---|---|
|
|
145
|
+
| `403` | `user_not_in_scope` | The customer is not an `ENABLED` member of your organization |
|
|
146
|
+
| `403` | `account_frozen` | The customer's account is frozen |
|
|
147
|
+
| `403` | `wallet_frozen` | The customer's wallet is frozen |
|
|
148
|
+
| `403` | `kyc_not_validated` | Your organization uses BITGEN's identity verification and the customer's identity is not validated ([Activation and identity](../concepts.md#activation-and-identity)) |
|
|
149
|
+
| `403` | `user_actions_disabled` | Customer actions are disabled for your organization (`user_can_actions` flag) |
|
|
150
|
+
| `404` | `unknown_bank` | The customer has no EUR account |
|
|
151
|
+
| `404` | `unknown_order` | Unknown order, or outside your organization |
|
|
152
|
+
| `404` | `unknown_user` | `list`: unknown `user` |
|
|
153
|
+
| `412` | `price_unavailable` | No price is available for the asset |
|
|
154
|
+
| `412` | `trading_not_enabled` | The `TRADING` connector of your organization is not enabled |
|
|
155
|
+
| `412` | `exchange_address_missing` | The deposit address of the exchange is missing |
|
|
156
|
+
| `416` | `invalid_amount` | The amount is not valid, or below the minimum |
|
|
157
|
+
| `416` | `amount_precision_exceeded` | More decimals than allowed |
|
|
158
|
+
| `416` | `amount_below_commission` | The amount does not cover the commission |
|
|
159
|
+
| `422` | `invalid_asset` | Unknown asset, or not `AVAILABLE` |
|
|
160
|
+
| `423` | `insufficient_funds` | `buy`: insufficient EUR balance |
|
|
161
|
+
| `423` | `blocked_by_alert` | An active compliance alert blocks the customer |
|
|
162
|
+
| `423` | `bank_lock_unavailable` | The EUR account is locked by a concurrent operation |
|
|
163
|
+
|
|
164
|
+
## Related
|
|
165
|
+
|
|
166
|
+
- [Amounts](../concepts.md#amounts) — EUR and crypto amounts, minimums
|
|
167
|
+
- [Bank accounts](bank.md) — the EUR account purchases are paid from
|
|
168
|
+
- [Custody wallets](custody.md) — the wallets sales take crypto from
|
|
169
|
+
- [Assets catalogue](asset.md) — which assets are `AVAILABLE`, their decimals
|
|
170
|
+
- [Webhooks](webhooks.md) — `trading.buy`, `trading.sell`
|
|
171
|
+
- [Following a purchase and a sale](../concepts.md#following-a-purchase-and-a-sale) — where the EUR, the execution, the delivery and the credit show up, resource by resource
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Transactions
|
|
2
|
+
|
|
3
|
+
The transaction journal is the unified, read-only record of the fiat and crypto movements of your organization: bank deposits and withdrawals, custody deposits and withdrawals, and the internal legs of sales and staking. Transactions are created by the platform — never through the API — and referenced by the other resources: `bank.withdraw` and `custody.withdraw` return the uuid of the transaction they create. `client.transaction` lists and reads them.
|
|
4
|
+
|
|
5
|
+
Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)).
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Methods
|
|
10
|
+
|
|
11
|
+
| Method | What it does | Returns |
|
|
12
|
+
|---|---|---|
|
|
13
|
+
| `list(params?)` | Lists the transactions of your organization | `Page<Transaction>` |
|
|
14
|
+
| `get(transaction)` | Reads one transaction, by uuid or reference | `Transaction` |
|
|
15
|
+
|
|
16
|
+
TypeScript types of this resource, exported by the package: `TransactionAlert`, `Transaction`, `TransactionListParams` — the constants `TransactionState`, `TransactionSource`, `TransactionDirection` (also types) — plus the shared `UserRef`, `UserSummary`, `OrganizationSummary`, `OrganizationHub`, `AssetInput`, `Page`.
|
|
17
|
+
|
|
18
|
+
## List
|
|
19
|
+
|
|
20
|
+
```
|
|
21
|
+
client.transaction.list(params?: TransactionListParams): Promise<Page<Transaction>>
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Parameter | Type | Description |
|
|
25
|
+
|---|---|---|
|
|
26
|
+
| `params.user` | `UserRef` | Only the transactions of this customer (uuid or model; unknown → `404 unknown_user`) |
|
|
27
|
+
| `params.status` | `TransactionState` | Only this state: `TransactionState.ANALYZING`, `PENDING`, `COMPLETED`, `FROZEN`, `FAILED`, `TRANSFERING` or `SEIZED` — anything else → `400 invalid_transaction_state` |
|
|
28
|
+
| `params.source` | `TransactionSource` | `TransactionSource.BANK` or `TransactionSource.CUSTODY` |
|
|
29
|
+
| `params.direction` | `TransactionDirection` | `TransactionDirection.IN` or `TransactionDirection.OUT` |
|
|
30
|
+
| `params.asset` | `AssetInput` | Only this asset, by ISO code (`Asset.ETH`), uuid or model |
|
|
31
|
+
| `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) — `limit` up to 100 on this list |
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
import { Asset, TransactionDirection, TransactionSource, TransactionState } from '@bitgen/sdk'
|
|
35
|
+
|
|
36
|
+
const { count, items } = await client.transaction.list({
|
|
37
|
+
user: 'CUSTOMER_UUID',
|
|
38
|
+
status: TransactionState.PENDING,
|
|
39
|
+
source: TransactionSource.CUSTODY,
|
|
40
|
+
direction: TransactionDirection.IN,
|
|
41
|
+
asset: Asset.ETH,
|
|
42
|
+
offset: 0,
|
|
43
|
+
limit: 100,
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
for (const transaction of items) {
|
|
47
|
+
console.log(transaction.direction, transaction.asset, transaction.amount, transaction.state)
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Returns a page of `Transaction`.
|
|
52
|
+
|
|
53
|
+
## Get
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
client.transaction.get(transaction: string | Transaction): Promise<Transaction>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`transaction` is the uuid of the transaction, its `reference`, or a `Transaction` of `list()`.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { TransactionState } from '@bitgen/sdk'
|
|
63
|
+
|
|
64
|
+
const { transaction } = await client.bank.withdraw('CUSTOMER_UUID', { amount: '50.00' })
|
|
65
|
+
|
|
66
|
+
const withdrawal = await client.transaction.get(transaction)
|
|
67
|
+
console.log(withdrawal.state === TransactionState.PENDING) // true
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Returns a `Transaction`:
|
|
71
|
+
|
|
72
|
+
| Field | Description |
|
|
73
|
+
|---|---|
|
|
74
|
+
| `uuid` | The transaction |
|
|
75
|
+
| `state` | `TransactionState.ANALYZING`, `PENDING`, `COMPLETED`, `FROZEN`, `FAILED`, `TRANSFERING` or `SEIZED` — the cycle is below the table |
|
|
76
|
+
| `source` | `TransactionSource.BANK` (EUR) or `TransactionSource.CUSTODY` (crypto) |
|
|
77
|
+
| `direction` | `TransactionDirection.IN` or `TransactionDirection.OUT` |
|
|
78
|
+
| `asset` | The asset iso — `EUR` for bank transactions |
|
|
79
|
+
| `amount` | The amount, in that asset (a number — for crypto, the exact amount is the string held by the custody wallet) |
|
|
80
|
+
| `eurValue` | EUR value when recorded, or `null` |
|
|
81
|
+
| `reference` | The reference, or `null` |
|
|
82
|
+
| `credited` | For an incoming transaction: `true` once the EUR account or the wallet has actually been credited, right after `COMPLETED` |
|
|
83
|
+
| `silent` | `true` for an internal leg (staking, sale) that is not an operation of the customer |
|
|
84
|
+
| `data` | Additional context set by the platform (compliance details, internal flags) — varies with the transaction, not needed for an integration |
|
|
85
|
+
| `createdAt`, `updatedAt` | Epoch seconds |
|
|
86
|
+
| `owner` | The customer, a `UserSummary`: `{ uuid, state, login, account: { firstname, lastname, fin } }` — a `UserRef` — or `null` |
|
|
87
|
+
| `assignee` | The compliance officer assigned while the transaction is on hold (`PENDING`, `FROZEN`), same shape as `owner`; `null` otherwise |
|
|
88
|
+
| `organization` | `OrganizationSummary` with its `hub`: `{ uuid, state, name, hub }` — `hub` is the hub the organization belongs to (`OrganizationHub`, `{ uuid, name }`, or `null`) — or `null` |
|
|
89
|
+
| `alert` | The compliance alert attached to the transaction (`TransactionAlert`), or `null`: `uuid`, `state` (`OPEN`, `RESOLVED`, `DISMISSED`, `DECLARATED`, `CONFIRMED`), `severity` (`SUCCESS`, `WARNING`, `CRITICAL`), `type` (`KYT`, `KYC_EXPIRE`, `SUSPICIOUS_ACTIVITY`, `AML`, `SANCTIONS`), `description`, `confidence` (confidence of the analysis, 0–100), `recommendation` (suggested action), `factors` (elements that weighed in the analysis), `sources` (the observations analysed), `history` (state changes of the alert), `incidentKey` (groups the alerts of a same incident), `createdAt`, `updatedAt`, `user` (the customer), `assignee` (the compliance officer), `organization` |
|
|
90
|
+
|
|
91
|
+
An unknown uuid or reference, or a transaction outside your organization, answers `404 unknown_transaction`.
|
|
92
|
+
|
|
93
|
+
Every transaction is born `ANALYZING`, the compliance analysis — the internal legs too. A clean verdict sends an incoming transaction to `COMPLETED`, then the EUR account or the wallet is credited; an outgoing one to `TRANSFERING` — the wire or the on-chain send executes — then `COMPLETED` at its confirmation. An alert, or a crypto deposit on a frozen wallet, holds it in `PENDING`: an `alert` is attached and the compliance of your organization becomes the `assignee`. The compliance then freezes it (`PENDING` → `FROZEN`), validates it (`PENDING` or `FROZEN` → `COMPLETED` for an incoming transaction, `TRANSFERING` for an outgoing one; the alert is `RESOLVED`), refuses it (`PENDING` or `FROZEN` → `FAILED`) or seizes it (`FROZEN` → `SEIZED`); an execution that fails also ends `FAILED` (`TRANSFERING` → `FAILED`). `COMPLETED`, `FAILED` and `SEIZED` are terminal. A failed incoming transaction was never credited; a failed outgoing one releases its reserve or re-credits the wallet. Two exceptions appear in the list: a crypto deposit that failed on chain is recorded `FAILED` right away, and the return or the seizure of a refused or seized deposit is a separate outgoing transaction, born `TRANSFERING`. The internal legs (`silent`) go through the analysis like the others and send no event.
|
|
94
|
+
|
|
95
|
+
## Errors
|
|
96
|
+
|
|
97
|
+
In addition to the [common errors](../errors.md#common-errors):
|
|
98
|
+
|
|
99
|
+
| Status | `code` | Meaning |
|
|
100
|
+
|---|---|---|
|
|
101
|
+
| `400` | `invalid_transaction_state` | `status` is not one of the transaction states |
|
|
102
|
+
| `404` | `unknown_user` | `list`: unknown `user` |
|
|
103
|
+
| `404` | `unknown_transaction` | Unknown uuid or reference, or outside your organization |
|
|
104
|
+
|
|
105
|
+
## Related
|
|
106
|
+
|
|
107
|
+
- [Bank accounts](bank.md) — EUR withdrawals return a transaction uuid
|
|
108
|
+
- [Custody wallets](custody.md) — on-chain withdrawals return a transaction uuid
|
|
109
|
+
- [Pagination](../concepts.md#pagination) — `limit` up to 100 on this list
|
|
110
|
+
- [Webhooks](webhooks.md) — `bank.transaction`, `custody.transaction`, `alert.opened`, `alert.status`
|