@bitgen/sdk 0.1.5 → 1.0.3

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.
Files changed (328) hide show
  1. package/CHANGELOG.md +55 -0
  2. package/README.md +27 -106
  3. package/dist/cjs/client.d.ts +20 -8
  4. package/dist/cjs/client.d.ts.map +1 -1
  5. package/dist/cjs/client.js +33 -12
  6. package/dist/cjs/client.js.map +1 -1
  7. package/dist/cjs/constants.d.ts +256 -0
  8. package/dist/cjs/constants.d.ts.map +1 -0
  9. package/dist/cjs/constants.js +214 -0
  10. package/dist/cjs/constants.js.map +1 -0
  11. package/dist/cjs/error.d.ts +17 -10
  12. package/dist/cjs/error.d.ts.map +1 -1
  13. package/dist/cjs/error.js +25 -7
  14. package/dist/cjs/error.js.map +1 -1
  15. package/dist/cjs/http.d.ts +13 -8
  16. package/dist/cjs/http.d.ts.map +1 -1
  17. package/dist/cjs/http.js +135 -43
  18. package/dist/cjs/http.js.map +1 -1
  19. package/dist/cjs/index.d.ts +14 -1
  20. package/dist/cjs/index.d.ts.map +1 -1
  21. package/dist/cjs/index.js +30 -1
  22. package/dist/cjs/index.js.map +1 -1
  23. package/dist/cjs/resources/apikeys.d.ts +18 -0
  24. package/dist/cjs/resources/apikeys.d.ts.map +1 -0
  25. package/dist/cjs/resources/apikeys.js +31 -0
  26. package/dist/cjs/resources/apikeys.js.map +1 -0
  27. package/dist/cjs/resources/asset.d.ts +17 -5
  28. package/dist/cjs/resources/asset.d.ts.map +1 -1
  29. package/dist/cjs/resources/asset.js +17 -6
  30. package/dist/cjs/resources/asset.js.map +1 -1
  31. package/dist/cjs/resources/bank.d.ts +11 -6
  32. package/dist/cjs/resources/bank.d.ts.map +1 -1
  33. package/dist/cjs/resources/bank.js +17 -9
  34. package/dist/cjs/resources/bank.js.map +1 -1
  35. package/dist/cjs/resources/core.d.ts +12 -0
  36. package/dist/cjs/resources/core.d.ts.map +1 -0
  37. package/dist/cjs/resources/core.js +22 -0
  38. package/dist/cjs/resources/core.js.map +1 -0
  39. package/dist/cjs/resources/custody.d.ts +27 -0
  40. package/dist/cjs/resources/custody.d.ts.map +1 -0
  41. package/dist/cjs/resources/custody.js +38 -0
  42. package/dist/cjs/resources/custody.js.map +1 -0
  43. package/dist/cjs/resources/customer.d.ts +20 -0
  44. package/dist/cjs/resources/customer.d.ts.map +1 -0
  45. package/dist/cjs/resources/customer.js +38 -0
  46. package/dist/cjs/resources/customer.js.map +1 -0
  47. package/dist/cjs/resources/staking.d.ts +32 -0
  48. package/dist/cjs/resources/staking.d.ts.map +1 -0
  49. package/dist/cjs/resources/staking.js +69 -0
  50. package/dist/cjs/resources/staking.js.map +1 -0
  51. package/dist/cjs/resources/trading.d.ts +24 -0
  52. package/dist/cjs/resources/trading.d.ts.map +1 -0
  53. package/dist/cjs/resources/trading.js +41 -0
  54. package/dist/cjs/resources/trading.js.map +1 -0
  55. package/dist/cjs/resources/transaction.d.ts +6 -9
  56. package/dist/cjs/resources/transaction.d.ts.map +1 -1
  57. package/dist/cjs/resources/transaction.js +10 -15
  58. package/dist/cjs/resources/transaction.js.map +1 -1
  59. package/dist/cjs/resources/webhooks.d.ts +46 -0
  60. package/dist/cjs/resources/webhooks.d.ts.map +1 -0
  61. package/dist/cjs/resources/webhooks.js +142 -0
  62. package/dist/cjs/resources/webhooks.js.map +1 -0
  63. package/dist/cjs/types/apikeys.d.ts +43 -0
  64. package/dist/cjs/types/apikeys.d.ts.map +1 -0
  65. package/dist/cjs/types/apikeys.js +3 -0
  66. package/dist/cjs/types/apikeys.js.map +1 -0
  67. package/dist/cjs/types/asset.d.ts +57 -0
  68. package/dist/cjs/types/asset.d.ts.map +1 -0
  69. package/dist/cjs/types/asset.js +3 -0
  70. package/dist/cjs/types/asset.js.map +1 -0
  71. package/dist/cjs/types/bank.d.ts +58 -0
  72. package/dist/cjs/types/bank.d.ts.map +1 -0
  73. package/dist/cjs/types/bank.js +3 -0
  74. package/dist/cjs/types/bank.js.map +1 -0
  75. package/dist/cjs/types/core.d.ts +32 -0
  76. package/dist/cjs/types/core.d.ts.map +1 -0
  77. package/dist/cjs/types/core.js +3 -0
  78. package/dist/cjs/types/core.js.map +1 -0
  79. package/dist/cjs/types/custody.d.ts +50 -0
  80. package/dist/cjs/types/custody.d.ts.map +1 -0
  81. package/dist/cjs/types/custody.js +3 -0
  82. package/dist/cjs/types/custody.js.map +1 -0
  83. package/dist/cjs/types/customer.d.ts +190 -0
  84. package/dist/cjs/types/customer.d.ts.map +1 -0
  85. package/dist/cjs/types/customer.js +3 -0
  86. package/dist/cjs/types/customer.js.map +1 -0
  87. package/dist/cjs/types/index.d.ts +79 -194
  88. package/dist/cjs/types/index.d.ts.map +1 -1
  89. package/dist/cjs/types/index.js +0 -1
  90. package/dist/cjs/types/index.js.map +1 -1
  91. package/dist/cjs/types/staking.d.ts +88 -0
  92. package/dist/cjs/types/staking.d.ts.map +1 -0
  93. package/dist/cjs/types/staking.js +3 -0
  94. package/dist/cjs/types/staking.js.map +1 -0
  95. package/dist/cjs/types/trading.d.ts +51 -0
  96. package/dist/cjs/types/trading.d.ts.map +1 -0
  97. package/dist/cjs/types/trading.js +3 -0
  98. package/dist/cjs/types/trading.js.map +1 -0
  99. package/dist/cjs/types/transaction.d.ts +61 -0
  100. package/dist/cjs/types/transaction.d.ts.map +1 -0
  101. package/dist/cjs/types/transaction.js +3 -0
  102. package/dist/cjs/types/transaction.js.map +1 -0
  103. package/dist/cjs/types/webhooks.d.ts +55 -0
  104. package/dist/cjs/types/webhooks.d.ts.map +1 -0
  105. package/dist/cjs/types/webhooks.js +3 -0
  106. package/dist/cjs/types/webhooks.js.map +1 -0
  107. package/dist/cjs/utils.d.ts +21 -2
  108. package/dist/cjs/utils.d.ts.map +1 -1
  109. package/dist/cjs/utils.js +67 -4
  110. package/dist/cjs/utils.js.map +1 -1
  111. package/dist/cjs/version.d.ts +2 -0
  112. package/dist/cjs/version.d.ts.map +1 -0
  113. package/dist/cjs/version.js +6 -0
  114. package/dist/cjs/version.js.map +1 -0
  115. package/dist/esm/client.d.ts +20 -8
  116. package/dist/esm/client.d.ts.map +1 -1
  117. package/dist/esm/client.js +33 -12
  118. package/dist/esm/client.js.map +1 -1
  119. package/dist/esm/constants.d.ts +256 -0
  120. package/dist/esm/constants.d.ts.map +1 -0
  121. package/dist/esm/constants.js +211 -0
  122. package/dist/esm/constants.js.map +1 -0
  123. package/dist/esm/error.d.ts +17 -10
  124. package/dist/esm/error.d.ts.map +1 -1
  125. package/dist/esm/error.js +24 -6
  126. package/dist/esm/error.js.map +1 -1
  127. package/dist/esm/http.d.ts +13 -8
  128. package/dist/esm/http.d.ts.map +1 -1
  129. package/dist/esm/http.js +136 -44
  130. package/dist/esm/http.js.map +1 -1
  131. package/dist/esm/index.d.ts +14 -1
  132. package/dist/esm/index.d.ts.map +1 -1
  133. package/dist/esm/index.js +6 -0
  134. package/dist/esm/index.js.map +1 -1
  135. package/dist/esm/resources/apikeys.d.ts +18 -0
  136. package/dist/esm/resources/apikeys.d.ts.map +1 -0
  137. package/dist/esm/resources/apikeys.js +27 -0
  138. package/dist/esm/resources/apikeys.js.map +1 -0
  139. package/dist/esm/resources/asset.d.ts +17 -5
  140. package/dist/esm/resources/asset.d.ts.map +1 -1
  141. package/dist/esm/resources/asset.js +17 -6
  142. package/dist/esm/resources/asset.js.map +1 -1
  143. package/dist/esm/resources/bank.d.ts +11 -6
  144. package/dist/esm/resources/bank.d.ts.map +1 -1
  145. package/dist/esm/resources/bank.js +18 -10
  146. package/dist/esm/resources/bank.js.map +1 -1
  147. package/dist/esm/resources/core.d.ts +12 -0
  148. package/dist/esm/resources/core.d.ts.map +1 -0
  149. package/dist/esm/resources/core.js +18 -0
  150. package/dist/esm/resources/core.js.map +1 -0
  151. package/dist/esm/resources/custody.d.ts +27 -0
  152. package/dist/esm/resources/custody.d.ts.map +1 -0
  153. package/dist/esm/resources/custody.js +34 -0
  154. package/dist/esm/resources/custody.js.map +1 -0
  155. package/dist/esm/resources/customer.d.ts +20 -0
  156. package/dist/esm/resources/customer.d.ts.map +1 -0
  157. package/dist/esm/resources/customer.js +34 -0
  158. package/dist/esm/resources/customer.js.map +1 -0
  159. package/dist/esm/resources/staking.d.ts +32 -0
  160. package/dist/esm/resources/staking.d.ts.map +1 -0
  161. package/dist/esm/resources/staking.js +65 -0
  162. package/dist/esm/resources/staking.js.map +1 -0
  163. package/dist/esm/resources/trading.d.ts +24 -0
  164. package/dist/esm/resources/trading.d.ts.map +1 -0
  165. package/dist/esm/resources/trading.js +37 -0
  166. package/dist/esm/resources/trading.js.map +1 -0
  167. package/dist/esm/resources/transaction.d.ts +6 -9
  168. package/dist/esm/resources/transaction.d.ts.map +1 -1
  169. package/dist/esm/resources/transaction.js +11 -16
  170. package/dist/esm/resources/transaction.js.map +1 -1
  171. package/dist/esm/resources/webhooks.d.ts +46 -0
  172. package/dist/esm/resources/webhooks.d.ts.map +1 -0
  173. package/dist/esm/resources/webhooks.js +138 -0
  174. package/dist/esm/resources/webhooks.js.map +1 -0
  175. package/dist/esm/types/apikeys.d.ts +43 -0
  176. package/dist/esm/types/apikeys.d.ts.map +1 -0
  177. package/dist/esm/types/apikeys.js +2 -0
  178. package/dist/esm/types/apikeys.js.map +1 -0
  179. package/dist/esm/types/asset.d.ts +57 -0
  180. package/dist/esm/types/asset.d.ts.map +1 -0
  181. package/dist/esm/types/asset.js +2 -0
  182. package/dist/esm/types/asset.js.map +1 -0
  183. package/dist/esm/types/bank.d.ts +58 -0
  184. package/dist/esm/types/bank.d.ts.map +1 -0
  185. package/dist/esm/types/bank.js +2 -0
  186. package/dist/esm/types/bank.js.map +1 -0
  187. package/dist/esm/types/core.d.ts +32 -0
  188. package/dist/esm/types/core.d.ts.map +1 -0
  189. package/dist/esm/types/core.js +2 -0
  190. package/dist/esm/types/core.js.map +1 -0
  191. package/dist/esm/types/custody.d.ts +50 -0
  192. package/dist/esm/types/custody.d.ts.map +1 -0
  193. package/dist/esm/types/custody.js +2 -0
  194. package/dist/esm/types/custody.js.map +1 -0
  195. package/dist/esm/types/customer.d.ts +190 -0
  196. package/dist/esm/types/customer.d.ts.map +1 -0
  197. package/dist/esm/types/customer.js +2 -0
  198. package/dist/esm/types/customer.js.map +1 -0
  199. package/dist/esm/types/index.d.ts +79 -194
  200. package/dist/esm/types/index.d.ts.map +1 -1
  201. package/dist/esm/types/index.js +0 -1
  202. package/dist/esm/types/index.js.map +1 -1
  203. package/dist/esm/types/staking.d.ts +88 -0
  204. package/dist/esm/types/staking.d.ts.map +1 -0
  205. package/dist/esm/types/staking.js +2 -0
  206. package/dist/esm/types/staking.js.map +1 -0
  207. package/dist/esm/types/trading.d.ts +51 -0
  208. package/dist/esm/types/trading.d.ts.map +1 -0
  209. package/dist/esm/types/trading.js +2 -0
  210. package/dist/esm/types/trading.js.map +1 -0
  211. package/dist/esm/types/transaction.d.ts +61 -0
  212. package/dist/esm/types/transaction.d.ts.map +1 -0
  213. package/dist/esm/types/transaction.js +2 -0
  214. package/dist/esm/types/transaction.js.map +1 -0
  215. package/dist/esm/types/webhooks.d.ts +55 -0
  216. package/dist/esm/types/webhooks.d.ts.map +1 -0
  217. package/dist/esm/types/webhooks.js +2 -0
  218. package/dist/esm/types/webhooks.js.map +1 -0
  219. package/dist/esm/utils.d.ts +21 -2
  220. package/dist/esm/utils.d.ts.map +1 -1
  221. package/dist/esm/utils.js +62 -4
  222. package/dist/esm/utils.js.map +1 -1
  223. package/dist/esm/version.d.ts +2 -0
  224. package/dist/esm/version.d.ts.map +1 -0
  225. package/dist/esm/version.js +3 -0
  226. package/dist/esm/version.js.map +1 -0
  227. package/package.json +29 -12
  228. package/readme/concepts.md +104 -0
  229. package/readme/configuration.md +72 -0
  230. package/readme/errors.md +67 -0
  231. package/readme/installation.md +43 -0
  232. package/readme/quick-start.md +87 -0
  233. package/readme/resource/apikeys.md +103 -0
  234. package/readme/resource/asset.md +121 -0
  235. package/readme/resource/bank.md +156 -0
  236. package/readme/resource/core.md +91 -0
  237. package/readme/resource/custody.md +166 -0
  238. package/readme/resource/customer.md +208 -0
  239. package/readme/resource/staking.md +277 -0
  240. package/readme/resource/trading.md +166 -0
  241. package/readme/resource/transaction.md +106 -0
  242. package/readme/resource/webhooks.md +307 -0
  243. package/src/client.ts +46 -0
  244. package/src/constants.ts +281 -0
  245. package/src/error.ts +36 -0
  246. package/src/http.ts +201 -0
  247. package/src/index.ts +111 -0
  248. package/src/resources/apikeys.ts +30 -0
  249. package/src/resources/asset.ts +28 -0
  250. package/src/resources/bank.ts +39 -0
  251. package/src/resources/core.ts +19 -0
  252. package/src/resources/custody.ts +37 -0
  253. package/src/resources/customer.ts +46 -0
  254. package/src/resources/staking.ts +88 -0
  255. package/src/resources/trading.ts +41 -0
  256. package/src/resources/transaction.ts +20 -0
  257. package/src/resources/webhooks.ts +169 -0
  258. package/src/types/apikeys.ts +35 -0
  259. package/src/types/asset.ts +59 -0
  260. package/src/types/bank.ts +60 -0
  261. package/src/types/core.ts +32 -0
  262. package/src/types/custody.ts +40 -0
  263. package/src/types/customer.ts +189 -0
  264. package/src/types/index.ts +215 -0
  265. package/src/types/staking.ts +87 -0
  266. package/src/types/trading.ts +56 -0
  267. package/src/types/transaction.ts +62 -0
  268. package/src/types/webhooks.ts +60 -0
  269. package/src/utils.ts +74 -0
  270. package/src/version.ts +2 -0
  271. package/dist/cjs/resources/order.d.ts +0 -17
  272. package/dist/cjs/resources/order.d.ts.map +0 -1
  273. package/dist/cjs/resources/order.js +0 -30
  274. package/dist/cjs/resources/order.js.map +0 -1
  275. package/dist/cjs/resources/stats.d.ts +0 -11
  276. package/dist/cjs/resources/stats.d.ts.map +0 -1
  277. package/dist/cjs/resources/stats.js +0 -18
  278. package/dist/cjs/resources/stats.js.map +0 -1
  279. package/dist/cjs/resources/user.d.ts +0 -22
  280. package/dist/cjs/resources/user.d.ts.map +0 -1
  281. package/dist/cjs/resources/user.js +0 -37
  282. package/dist/cjs/resources/user.js.map +0 -1
  283. package/dist/cjs/resources/wallet.d.ts +0 -11
  284. package/dist/cjs/resources/wallet.d.ts.map +0 -1
  285. package/dist/cjs/resources/wallet.js +0 -19
  286. package/dist/cjs/resources/wallet.js.map +0 -1
  287. package/dist/esm/resources/order.d.ts +0 -17
  288. package/dist/esm/resources/order.d.ts.map +0 -1
  289. package/dist/esm/resources/order.js +0 -26
  290. package/dist/esm/resources/order.js.map +0 -1
  291. package/dist/esm/resources/stats.d.ts +0 -11
  292. package/dist/esm/resources/stats.d.ts.map +0 -1
  293. package/dist/esm/resources/stats.js +0 -14
  294. package/dist/esm/resources/stats.js.map +0 -1
  295. package/dist/esm/resources/user.d.ts +0 -22
  296. package/dist/esm/resources/user.d.ts.map +0 -1
  297. package/dist/esm/resources/user.js +0 -33
  298. package/dist/esm/resources/user.js.map +0 -1
  299. package/dist/esm/resources/wallet.d.ts +0 -11
  300. package/dist/esm/resources/wallet.d.ts.map +0 -1
  301. package/dist/esm/resources/wallet.js +0 -15
  302. package/dist/esm/resources/wallet.js.map +0 -1
  303. package/dist/types/client.d.ts +0 -19
  304. package/dist/types/client.d.ts.map +0 -1
  305. package/dist/types/error.d.ts +0 -15
  306. package/dist/types/error.d.ts.map +0 -1
  307. package/dist/types/http.d.ts +0 -21
  308. package/dist/types/http.d.ts.map +0 -1
  309. package/dist/types/index.d.ts +0 -4
  310. package/dist/types/index.d.ts.map +0 -1
  311. package/dist/types/resources/asset.d.ts +0 -11
  312. package/dist/types/resources/asset.d.ts.map +0 -1
  313. package/dist/types/resources/bank.d.ts +0 -13
  314. package/dist/types/resources/bank.d.ts.map +0 -1
  315. package/dist/types/resources/order.d.ts +0 -17
  316. package/dist/types/resources/order.d.ts.map +0 -1
  317. package/dist/types/resources/stats.d.ts +0 -11
  318. package/dist/types/resources/stats.d.ts.map +0 -1
  319. package/dist/types/resources/transaction.d.ts +0 -15
  320. package/dist/types/resources/transaction.d.ts.map +0 -1
  321. package/dist/types/resources/user.d.ts +0 -22
  322. package/dist/types/resources/user.d.ts.map +0 -1
  323. package/dist/types/resources/wallet.d.ts +0 -11
  324. package/dist/types/resources/wallet.d.ts.map +0 -1
  325. package/dist/types/types/index.d.ts +0 -212
  326. package/dist/types/types/index.d.ts.map +0 -1
  327. package/dist/types/utils.d.ts +0 -7
  328. package/dist/types/utils.d.ts.map +0 -1
@@ -0,0 +1,208 @@
1
+ # Customers
2
+
3
+ A customer is an end user of your organization on the BITGEN platform: a person (KYC) or a business (KYB) with a login, an identity file, settings and — once activated and verified — an EUR account, custody wallets, orders and staking positions. `client.customer` creates customers, lists them, and reads or updates an account.
4
+
5
+ Examples use `client`, a configured `BitgenClient` ([Configuration](../configuration.md)). A customer is designated by a `UserRef`: their uuid, or a model carrying it — the `Created` returned by `create`, a `Customer` of `list`, an `Account` of `get` ([User references](../concepts.md#user-references)).
6
+
7
+ ## Methods
8
+
9
+ | Method | What it does | Returns |
10
+ |---|---|---|
11
+ | `create(params)` | Creates a customer in your organization and sends them the activation email | `Created` |
12
+ | `list(params?)` | Lists the customers of your organization | `Page<Customer>` |
13
+ | `get(user)` | Reads one account: identity files, details, settings | `Account` |
14
+ | `update(user, params)` | Updates the settings a key may write: theme, locale, notifications | `void` |
15
+
16
+ TypeScript types of this resource, exported by the package: `KycIdentity`, `KybIdentity`, `Identity`, `CustomerAccount`, `CustomerClient`, `CustomerSetup`, `CollaboratorLink`, `ManagerLink`, `CustomerAlert`, `CustomerBusiness`, `Customer`, `AccountAddress`, `Account`, `CreateCustomerParams`, `CustomerListParams`, `UpdateCustomerParams` — the constants `Locale`, `CustomerState`, `IdentityState`, `IdentityMode`, `OrganizationCategory` (also types) — plus the shared `UserRef`, `Created`.
17
+
18
+ ## create
19
+
20
+ ```
21
+ client.customer.create(params: CreateCustomerParams): Promise<Created>
22
+ ```
23
+
24
+ | Parameter | Type | Description |
25
+ |---|---|---|
26
+ | `params.account.email` | `string` | Login of the customer — required |
27
+ | `params.account.firstname` | `string` | Optional |
28
+ | `params.account.lastname` | `string` | Optional |
29
+ | `params.account.fin` | `string` | Tax identification number of the customer — optional, 100 characters max |
30
+ | `params.account.needActivation` | `boolean` | Default `true`: BITGEN emails the customer an activation link and the account stays `CustomerState.CREATED` (the bank, custody, trading and staking resources refuse it) until they activate. `false`: the account is usable right away and BITGEN sends no email — for an organization that handles activation and notifications with its own system, or through webhooks |
31
+ | `params.account.notify` | `boolean` | Default `true`: the customer receives BITGEN's emails (newsletter). `false`: none |
32
+ | `params.group.manager` | `string` | uuid of the collaborator of your organization who follows this customer — required; the customer is created in your organization |
33
+ | `params.locale` | `Locale` | `Locale.FR` (default) or `Locale.EN` |
34
+ | `params.organization` | `OrganizationCategory` | Category: `OrganizationCategory.CUSTOMER` (default) or `OrganizationCategory.B2B` — `B2B` also opens a KYB file |
35
+
36
+ ```ts
37
+ import { Locale, OrganizationCategory } from '@bitgen/sdk'
38
+
39
+ const created = await client.customer.create({
40
+ account: { email: 'jean@valjean.fr', firstname: 'Jean', lastname: 'Valjean' },
41
+ group: { manager: 'MANAGER_UUID' },
42
+ locale: Locale.FR,
43
+ organization: OrganizationCategory.B2B, // a business: a KYB file is opened too — CUSTOMER by default
44
+ })
45
+
46
+ const account = await client.customer.get(created) // a `Created` is a `UserRef`
47
+ ```
48
+
49
+ Returns a `Created` — the uuid of the customer, a `UserRef` for every other method. By default the API creates the account and sends the customer an activation email. Until they click it, the account stays `CustomerState.CREATED` (`setup.needActivation` is `true`) and the bank, custody, trading and staking resources do not accept it — only `list`, where it appears as `CREATED`, and `get` see it ([Activation and identity](../concepts.md#activation-and-identity)).
50
+
51
+ ```ts
52
+ const { uuid } = await client.customer.create({
53
+ account: { email: 'jean@valjean.fr', needActivation: false, notify: false }, // you handle onboarding yourself
54
+ group: { manager: 'MANAGER_UUID' },
55
+ })
56
+ ```
57
+
58
+ With `needActivation: false` the account is usable right away and BITGEN sends no activation email — for an organization that handles activation and notifications with its own system, or through webhooks ([Webhooks](webhooks.md)); with `notify: false` the customer receives no BITGEN email at all.
59
+
60
+ When the email already belongs to an active account whose KYC is validated, that account is **attached** to your organization instead of being created. An active account without a validated KYC cannot be attached (`412 user_not_attachable`), an account already attached to another organization is refused (`409 user_already_assigned`), and so is an account still being created, for 15 minutes (`409 account_unavailable`).
61
+
62
+ ## list
63
+
64
+ ```
65
+ client.customer.list(params?: CustomerListParams): Promise<Page<Customer>>
66
+ ```
67
+
68
+ | Parameter | Type | Description |
69
+ |---|---|---|
70
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
71
+ | `params.includeClosed` | `boolean` | Also returns the `CustomerState.CLOSED` customers — default `false` ([Query booleans](../concepts.md#query-booleans)) |
72
+ | `params.manager` | `string` | Only the customers whose direct manager is this collaborator (uuid) |
73
+
74
+ ```ts
75
+ import { CustomerState } from '@bitgen/sdk'
76
+
77
+ const { count, items } = await client.customer.list({ offset: 0, limit: 50 })
78
+
79
+ for (const customer of items) {
80
+ console.log(customer.login, customer.state === CustomerState.ENABLED) // 'jean@valjean.fr' true
81
+ }
82
+ ```
83
+
84
+ Returns a page of `Customer`:
85
+
86
+ | Field | Description |
87
+ |---|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
88
+ | `uuid`, `createdAt` | Identifier and creation time (epoch seconds) |
89
+ | `state` | `CustomerState.CREATED` (activation pending), `ENABLED`, `CLOSED` or `FROZEN` |
90
+ | `isAvailable` | `false` until the customer has activated their account, then `true` |
91
+ | `canLogin` | Whether the customer may sign in to the BITGEN web application |
92
+ | `login` | The email |
93
+ | `account` | `email`, `firstname`, `lastname`, `fin` (tax identification number), `birthdate` (date of birth, epoch seconds, or `null`), `phoneZone` and `phoneNumber` (dialing code, `+33` by default, and the number as an integer), `address` (`{ uuid, state, address }` or `null` — `state` is the state of the address record), `referralCode` (the customer's own referral code, generated at creation) |
94
+ | `client` | `roles` (platform roles of the account — always `ROLE_USER` for a customer), `hasTfa` (two-factor authentication enabled), `hasPhishing` (anti-phishing code enabled), `isValid` (`true` once the account has been activated) |
95
+ | `action.setup` | `theme` (theme of the BITGEN web application, `light` by default), `currency` (display currency, `EUR`), `locale` (language of the web application and of the emails, `Locale.FR` or `Locale.EN`), `choosenOrganization` (category chosen at signup: `OrganizationCategory.CUSTOMER`, `B2B` — a string, compare it with the constants), `needActivation` (activation email pending), `notify` (whether the customer accepts BITGEN emails), `onboarding` (whether the web onboarding has been completed) |
96
+ | `identity` | The KYC or KYB file of the customer ([Identity](#identity)) |
97
+ | `business` | The businesses of the customer, each with its KYB file: `{ identity }[]` |
98
+ | `collaborations.collaborator` | The customer's attachment to your organization: `uuid`, `state` (`WAIT` until activation, then `ENABLED`; `REVOKED` once removed), `roles` (`ROLE_USER` for a customer), `organization` (its name), `organizationUuid`, `manager` (uuid of the collaborator in charge of them) |
99
+ | `collaborations.manager` | Attachments where this account manages other people — always empty for a customer (`mandate`, `mandatedUntil`: CRM data, not needed for an integration) |
100
+ | `alert` | Active compliance alerts: `uuid`, `state` (`OPEN`, `DECLARATED`, `CONFIRMED`), `severity` (`SUCCESS`, `WARNING`, `CRITICAL`), `sources` (the observations behind the alert — analysis data) |
101
+
102
+ ## get
103
+
104
+ ```
105
+ client.customer.get(user: UserRef): Promise<Account>
106
+ ```
107
+
108
+ `user` is the customer, by uuid or model.
109
+
110
+ ```ts
111
+ import { IdentityState } from '@bitgen/sdk'
112
+
113
+ const account = await client.customer.get('CUSTOMER_UUID')
114
+
115
+ console.log(account.setup.needActivation) // true until the activation email is clicked
116
+ console.log(account.identity.state === IdentityState.VALIDATED) // true once the verification is done
117
+ ```
118
+
119
+ Returns an `Account`:
120
+
121
+ | Field | Description |
122
+ |---|---|
123
+ | `uuid` | The customer |
124
+ | `identity` | The KYC or KYB file of the customer ([Identity](#identity)) |
125
+ | `business` | The businesses of the customer, each with its KYB file: `{ identity }[]` |
126
+ | `account` | The same fields as `Customer.account`, with `address` reduced to `{ uuid, address }` (or `null`) |
127
+ | `notifications` | Email preferences: `login` (login-related emails), `newsletter` (BITGEN newsletter) |
128
+ | `setup` | The same fields as `Customer.action.setup`: theme, display currency, language, category chosen at signup, activation pending, BITGEN emails accepted, onboarding completed |
129
+
130
+ An unknown customer answers `404 unknown_user`.
131
+
132
+ ### Identity
133
+
134
+ `Identity` is the verification file of a person (`mode` `IdentityMode.KYC`) or of a business (`IdentityMode.KYB`). The verification itself — questionnaire, documents — is not part of this SDK: read its progress here. Whether a validated identity is required before the financial resources depends on your organization ([Activation and identity](../concepts.md#activation-and-identity)).
135
+
136
+ | Field | Description |
137
+ |---|---|
138
+ | `uuid` | The file |
139
+ | `state` | `IdentityState.CREATED`, `IN_PROGRESS`, `WAIT`, `PENDING`, `VALIDATED`, `REJECTED`, `FROZEN`, `EXPIRED` or `CLOSED` |
140
+ | `mode` | `IdentityMode.KYC` or `IdentityMode.KYB` |
141
+ | `form` | KYC — the answers of the KYC questionnaire: `european_residency` (boolean), `ppe` (politically exposed person, boolean), `ppp` (relative of a politically exposed person, boolean), `source_income`, `net_income`, `experience` (crypto experience); plus `score` (internal scoring) and `submittedAt` — KYB: `activity` (business activity), `score`, `submittedAt` |
142
+ | `data.steps` | One entry per step, `{ status, submittedAt }` — KYC: `info`, `selfie`, `identity`, `residency`; KYB: `info`, `kbis`, `status`, `domiciliation`, `rbe` |
143
+ | `data.verificationUrl` | URL of the identity verification when the provider hosts it, `null` otherwise |
144
+ | `data.hosted` | Whether the verification is hosted by the provider |
145
+ | `data.notifications` | Internal flag |
146
+ | `validatedAt`, `expiresAt` | Epoch seconds, or `null` |
147
+ | `renewalNotifiedAt` | When the renewal reminder was sent (epoch seconds, or `null`) — an identity expires after 12 months (6 for a politically exposed person) |
148
+
149
+ In TypeScript, `Identity` is the union `KycIdentity | KybIdentity`, discriminated on `mode`: narrow on it to type `form`.
150
+
151
+ ```ts
152
+ import { IdentityMode } from '@bitgen/sdk'
153
+
154
+ const { identity } = await client.customer.get('CUSTOMER_UUID')
155
+
156
+ if (identity.mode === IdentityMode.KYC) {
157
+ console.log(identity.form.source_income) // KycIdentity
158
+ } else {
159
+ console.log(identity.form.activity) // KybIdentity
160
+ }
161
+ ```
162
+
163
+ ## update
164
+
165
+ ```
166
+ client.customer.update(user: UserRef, params: UpdateCustomerParams): Promise<void>
167
+ ```
168
+
169
+ `user` is the customer, by uuid or model.
170
+
171
+ | Parameter | Type | Description |
172
+ |---|---|---|
173
+ | `params.theme` | `string` | Theme of the BITGEN web application (`light` by default) |
174
+ | `params.locale` | `Locale` | Language of the web application and of the emails: `Locale.FR` or `Locale.EN` |
175
+ | `params.notifications` | `{ login?: boolean, newsletter?: boolean }` | Email preferences: `login` (login-related emails), `newsletter` (BITGEN newsletter) |
176
+
177
+ ```ts
178
+ import { Locale } from '@bitgen/sdk'
179
+
180
+ await client.customer.update('CUSTOMER_UUID', {
181
+ locale: Locale.EN,
182
+ notifications: { login: true, newsletter: false },
183
+ })
184
+ ```
185
+
186
+ These are the only settings an API key may write — the account details, the identity state and the address are not — and the SDK sends nothing else. The API answers with an empty body: the promise resolves with `undefined`.
187
+
188
+ ## Errors
189
+
190
+ In addition to the [common errors](../errors.md#common-errors):
191
+
192
+ | Status | `code` | Meaning |
193
+ |---|---|---|
194
+ | `400` | `invalid_fin` | `account.fin` (tax identification number) is longer than 100 characters, or not a scalar |
195
+ | `403` | `missing_group_organization_or_manager` | `group.manager` is missing |
196
+ | `404` | `unknown_user` | Unknown customer (`get`), or unknown `manager` (`list`) |
197
+ | `409` | `user_already_assigned` | The email belongs to an account attached to another organization |
198
+ | `409` | `account_unavailable` | The email belongs to an account still being created (less than 15 minutes ago) |
199
+ | `412` | `user_not_attachable` | The email belongs to an active account without a validated KYC |
200
+ | `422` | `invalid_include_closed` | `includeClosed` is not a boolean value |
201
+
202
+ ## Related
203
+
204
+ - [User references](../concepts.md#user-references) — uuid or model (`Created`, `Customer`, `Account`…)
205
+ - [Activation and identity](../concepts.md#activation-and-identity) — what a customer can do before and after activation, and when a validated identity is required
206
+ - [Bank accounts](bank.md) — the EUR account of a customer
207
+ - [Custody wallets](custody.md) — their crypto wallets
208
+ - [Webhooks](webhooks.md) — `user.created` and the `user.identity.*` events
@@ -0,0 +1,277 @@
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 **movements** — a request to stake, unstake, withdraw or claim rewards — each 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
+ ## Methods
10
+
11
+ | Method | What it does | Returns |
12
+ |---|---|---|
13
+ | `providers(asset?)` | Lists the staking providers, for one asset or all | `Page<Core>` |
14
+ | `stake(user, params)` | Places crypto with a provider: opens a position | `Created` (the movement) |
15
+ | `list(params?)` | Lists the movements of your organization, all states | `Page<StakingMovement>` |
16
+ | `movements(params?)` | Lists the movements still in progress: `StakingMovementState.REQUESTED`, `PENDING`, `FAILED` | `Page<StakingMovement>` |
17
+ | `get(movement)` | Reads one movement and its position | `StakingMovement` |
18
+ | `rewards(position, params?)` | Claims the rewards of a position | `void` |
19
+ | `unstake(position, params?)` | Leaves a position, partially or entirely | `void` |
20
+ | `operations(user, params?)` | Lists the staking operations of a customer | `Page<StakingOperation>` |
21
+ | `portfolio(user)` | Reads the EUR balances and curves of a customer's staking | `StakingPortfolio` |
22
+
23
+ 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`.
24
+
25
+ ## providers
26
+
27
+ ```
28
+ client.staking.providers(asset?: AssetInput): Promise<Page<Core>>
29
+ ```
30
+
31
+ A shortcut of `client.core.list({ type: CoreType.STAKING, asset })` ([Connectors](core.md)).
32
+
33
+ | Parameter | Type | Description |
34
+ |---|---|---|
35
+ | `asset` | `AssetInput` | Optional: only the providers of this asset, by uuid or ISO code (`Asset.SOL`) or by model ([Assets](../concepts.md#assets)) |
36
+
37
+ ```ts
38
+ import { Asset, CoreState } from '@bitgen/sdk'
39
+
40
+ const { items: providers } = await client.staking.providers(Asset.SOL)
41
+
42
+ for (const provider of providers) {
43
+ console.log(provider.name, provider.state === CoreState.ENABLED) // 'figment_sol' true
44
+ }
45
+ ```
46
+
47
+ 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:
48
+
49
+ | Config field | Meaning |
50
+ |---|---|
51
+ | `connector` | The BITGEN connector |
52
+ | `apr` or `apy` | Annual rate, in % |
53
+ | `min_deposit` | Minimum deposit, in asset units |
54
+ | `deposit_locked_period` | Activation delay of a deposit |
55
+ | `rewards_locked_period` | Waiting period before a rewards withdrawal is paid |
56
+ | `unstake_locked_period` | Lock-up before an unstake is paid |
57
+ | `can_choose_withdrawal`, `can_choose_rewards` | Whether partial amounts are allowed (otherwise total only) |
58
+ | `min_rewards_eur` | Minimum EUR value of a rewards claim |
59
+
60
+ Periods are written `<unit>@<n>` with the unit `H`, `D`, `W`, `M` or `Y` — `D@3` is 3 days.
61
+
62
+ ## stake
63
+
64
+ ```
65
+ client.staking.stake(user: UserRef, params: StakeParams): Promise<Created>
66
+ ```
67
+
68
+ | Parameter | Type | Description |
69
+ |---|---|---|
70
+ | `params.asset` | `AssetInput` | The asset, by uuid or ISO code (`Asset.SOL`) or by model ([Assets](../concepts.md#assets)) |
71
+ | `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)) |
72
+ | `params.provider` | `string` | The `uuid` or the `name` of a `CoreType.STAKING` connector of your organization (`providers`) |
73
+
74
+ ```ts
75
+ import { Asset, StakingMovementState } from '@bitgen/sdk'
76
+
77
+ const { items: providers } = await client.staking.providers(Asset.SOL)
78
+
79
+ const { uuid: movementId } = await client.staking.stake('CUSTOMER_UUID', {
80
+ asset: Asset.SOL,
81
+ amount: '2',
82
+ provider: providers[0].name, // 'figment_sol'
83
+ })
84
+
85
+ const movement = await client.staking.get(movementId)
86
+ console.log(movement.state === StakingMovementState.REQUESTED) // true
87
+ console.log(movement.staking.uuid) // the position, for `rewards` and `unstake`
88
+ ```
89
+
90
+ 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**.
91
+
92
+ ## list
93
+
94
+ ```
95
+ client.staking.list(params?: StakingListParams): Promise<Page<StakingMovement>>
96
+ ```
97
+
98
+ The movements of your organization, in every state.
99
+
100
+ | Parameter | Type | Description |
101
+ |---|---|---|
102
+ | `params.user` | `UserRef` | Only the movements of this customer (uuid or model; unknown → `404 unknown_user`) |
103
+ | `params.direction` | `StakingMovementKind` | Only this kind of movement: `StakingMovementKind.STAKE`, `UNSTAKE`, `WITHDRAW` or `REWARD` — absent, all |
104
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
105
+
106
+ ```ts
107
+ import { StakingMovementKind } from '@bitgen/sdk'
108
+
109
+ const { count, items } = await client.staking.list({ user: 'CUSTOMER_UUID', direction: StakingMovementKind.STAKE })
110
+ ```
111
+
112
+ Returns a page of `StakingMovement` ([get](#get)).
113
+
114
+ ## movements
115
+
116
+ ```
117
+ client.staking.movements(params?: StakingListParams): Promise<Page<StakingMovement>>
118
+ ```
119
+
120
+ The movements still in progress: `StakingMovementState.REQUESTED`, `PENDING` and `FAILED` only. Same parameters as `list`.
121
+
122
+ ```ts
123
+ const pending = await client.staking.movements({ user: 'CUSTOMER_UUID' })
124
+ ```
125
+
126
+ Returns a page of `StakingMovement` ([get](#get)).
127
+
128
+ ## get
129
+
130
+ ```
131
+ client.staking.get(movement: string | StakingMovement): Promise<StakingMovement>
132
+ ```
133
+
134
+ `movement` is the uuid returned by `stake`, or a `StakingMovement`.
135
+
136
+ ```ts
137
+ import { StakingMovementKind, StakingMovementState, StakingPositionState } from '@bitgen/sdk'
138
+
139
+ const movement = await client.staking.get('MOVEMENT_UUID')
140
+
141
+ console.log(movement.kind === StakingMovementKind.STAKE, movement.state === StakingMovementState.COMPLETED, movement.amount) // true true '2'
142
+ console.log(movement.staking.state === StakingPositionState.ENABLED, movement.staking.data.rewards) // true '0.0123'
143
+ ```
144
+
145
+ Returns a `StakingMovement`:
146
+
147
+ | Field | Description |
148
+ |---|---|
149
+ | `uuid` | The movement |
150
+ | `state` | `StakingMovementState.REQUESTED`, `PENDING`, `COMPLETED`, `FAILED` or `CANCELED` |
151
+ | `kind` | `StakingMovementKind.STAKE`, `UNSTAKE`, `WITHDRAW` or `REWARD` |
152
+ | `provider` | The `name` of the staking connector (`figment_sol`) |
153
+ | `amount` | The quantity of the movement, as a string |
154
+ | `createdAt`, `updatedAt` | Epoch seconds |
155
+ | `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) |
156
+ | `owner` | `UserSummary`: `{ uuid, state, login, account: { firstname, lastname, fin } }` — the customer, a `UserRef` |
157
+ | `asset` | `AssetRef`: `{ uuid, iso, label }` |
158
+ | `organization` | `OrganizationSummary`: `{ uuid, state, name }`, or `null` |
159
+
160
+ An unknown movement, or one outside your organization, answers `404 unknown_staking_movement`.
161
+
162
+ ## rewards
163
+
164
+ ```
165
+ client.staking.rewards(position: string | StakingPosition, params?: StakingAmountParams): Promise<void>
166
+ ```
167
+
168
+ `position` is `movement.staking.uuid`, or `movement.staking` itself.
169
+
170
+ | Parameter | Type | Description |
171
+ |---|---|---|
172
+ | `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)) |
173
+
174
+ ```ts
175
+ const movement = await client.staking.get('MOVEMENT_UUID')
176
+
177
+ await client.staking.rewards(movement.staking) // all the rewards — the position, by model
178
+ await client.staking.rewards('POSITION_UUID', { amount: '0.01' }) // part of them, by uuid
179
+ ```
180
+
181
+ The amount is deducted from the position immediately; the transfer is executed by compliance. 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`.
182
+
183
+ ## unstake
184
+
185
+ ```
186
+ client.staking.unstake(position: string | StakingPosition, params?: StakingAmountParams): Promise<void>
187
+ ```
188
+
189
+ `position` is `movement.staking.uuid`, or `movement.staking` itself.
190
+
191
+ | Parameter | Type | Description |
192
+ |---|---|---|
193
+ | `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)) |
194
+
195
+ ```ts
196
+ const movement = await client.staking.get('MOVEMENT_UUID')
197
+
198
+ await client.staking.unstake('POSITION_UUID', { amount: '1' }) // partial exit, by uuid
199
+ await client.staking.unstake(movement.staking) // full exit — the position, by model
200
+ ```
201
+
202
+ The amount is deducted from the position immediately; the transfer is executed by compliance. 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`.
203
+
204
+ ## operations
205
+
206
+ ```
207
+ client.staking.operations(user: UserRef, params?: PageParams): Promise<Page<StakingOperation>>
208
+ ```
209
+
210
+ | Parameter | Type | Description |
211
+ |---|---|---|
212
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
213
+
214
+ ```ts
215
+ const { count, items } = await client.staking.operations('CUSTOMER_UUID', { offset: 0, limit: 50 })
216
+
217
+ for (const operation of items) {
218
+ console.log(operation.date, operation.event, operation.amount, operation.value) // 1701000000 'reward' '0.0123' 25.1
219
+ }
220
+ ```
221
+
222
+ Returns a page of `StakingOperation`: `txId` (journal entry id), `movement` (uuid of the movement, `null` for a daily reward), `asset` (iso), `kind` (`StakingMovementKind.STAKE`, `UNSTAKE`, `WITHDRAW` or `REWARD`), `amount` (asset units, as a string), `price` (EUR price of the asset at that time), `value` (EUR value), `event` (`created`, `pending`, `validated`, `failed`, `reward`, `claimed`, `unstake`, `closed` — other values may appear), `provider` (connector name), `date` (epoch seconds). An unknown customer, or one outside your organization, answers `404 unknown_staking`.
223
+
224
+ ## portfolio
225
+
226
+ ```
227
+ client.staking.portfolio(user: UserRef): Promise<StakingPortfolio>
228
+ ```
229
+
230
+ ```ts
231
+ const portfolio = await client.staking.portfolio('CUSTOMER_UUID')
232
+
233
+ console.log(portfolio.balances) // { capital: 4060.2, revenues: 25.1 } — EUR
234
+ console.log(portfolio.histories.capital.m) // EUR capital, one point per day over the last month
235
+ ```
236
+
237
+ 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.
238
+
239
+ ## Errors
240
+
241
+ In addition to the [common errors](../errors.md#common-errors), and the custody withdrawal errors `stake` can surface ([Custody wallets › Errors](custody.md#errors)):
242
+
243
+ | Status | `code` | Meaning |
244
+ |---|---|---|
245
+ | `400` | `invalid_amount` | The amount is not valid |
246
+ | `403` | `org_forbidden` | The customer is not an activated member of your organization |
247
+ | `403` | `account_frozen` | The customer's account is frozen |
248
+ | `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)) |
249
+ | `403` | `user_actions_disabled` | Customer actions are disabled for your organization (`user_can_actions` flag) |
250
+ | `404` | `unknown_user` | `stake`: unknown customer; `list`, `movements`: unknown `user` |
251
+ | `404` | `unknown_core` | `stake`: unknown `provider` |
252
+ | `404` | `unknown_asset` | Unknown asset |
253
+ | `404` | `unknown_organization` | The organization is unknown |
254
+ | `404` | `unknown_staking_movement` | `get`: unknown movement, or outside your organization |
255
+ | `404` | `unknown_staking` | `rewards`, `unstake`: unknown position — `operations`, `portfolio`: unknown customer, or outside your organization |
256
+ | `412` | `staking_connector_missing` | The provider has no connector that can be resolved |
257
+ | `412` | `staking_not_enabled` | The `CoreType.STAKING` connector of your organization is not enabled |
258
+ | `412` | `custody_not_enabled` | The `CoreType.CUSTODY` connector of your organization is not enabled |
259
+ | `412` | `staking_deposit_address_missing` | The provider has no deposit address |
260
+ | `412` | `staking_movement_not_completed` | `unstake`: the staking movement is not completed yet |
261
+ | `416` | `amount_precision_exceeded` | More decimals than the asset allows |
262
+ | `416` | `insufficient_rewards` | `rewards`: not enough rewards for the amount |
263
+ | `416` | `insufficient_balance` | `unstake`: not enough capital for the amount |
264
+ | `422` | `amount_below_minimum` | The amount is below the minimum of the provider (`min_deposit` on `stake`, a partial amount on `rewards` / `unstake`) |
265
+ | `422` | `staking_not_active` | The position is not active |
266
+ | `423` | `blocked_by_alert` | An active compliance alert blocks the customer |
267
+ | `424` | `token_price_unavailable` | `rewards`: no price is available for the token |
268
+ | `425` | `no_rewards` | `rewards`: nothing to claim |
269
+ | `425` | `no_balance` | `unstake`: nothing to withdraw |
270
+ | `425` | `deposit_locked_period_not_elapsed` | `unstake`: the lock-up period of the deposit has not elapsed |
271
+
272
+ ## Related
273
+
274
+ - [Connectors](core.md) — the `CoreType.STAKING` connectors, their `config`
275
+ - [Custody wallets](custody.md) — the wallet the staked amount is taken from
276
+ - [Amounts](../concepts.md#amounts) — crypto amounts as strings, minimums
277
+ - [Webhooks](webhooks.md) — `staking.requested`, `staking.status`, `staking.rewards`, `staking.claimed`
@@ -0,0 +1,166 @@
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
+ ## sell
46
+
47
+ ```
48
+ client.trading.sell(user: UserRef, params: TradingOrderParams): Promise<{ tunnel: string, state: OrderState }>
49
+ ```
50
+
51
+ | Parameter | Type | Description |
52
+ |---|---|---|
53
+ | `params.asset` | `AssetInput` | The asset to sell, by uuid or ISO code (`Asset.ETH`) or by model — it must be `AVAILABLE` |
54
+ | `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)) |
55
+ | `params.reference` | `string` | Optional idempotency key, per customer, side and reference |
56
+
57
+ ```ts
58
+ import { Asset } from '@bitgen/sdk'
59
+
60
+ const { tunnel } = await client.trading.sell('CUSTOMER_UUID', {
61
+ asset: Asset.ETH,
62
+ amount: '0.01',
63
+ })
64
+
65
+ const order = await client.trading.get(tunnel)
66
+ console.log(order.received) // EUR credited to the bank account once the order is DONE
67
+ ```
68
+
69
+ 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`.
70
+
71
+ ## get
72
+
73
+ ```
74
+ client.trading.get(order: string | Order): Promise<Order>
75
+ ```
76
+
77
+ `order` is the uuid returned as `tunnel` by `buy` and `sell`, or an `Order`.
78
+
79
+ ```ts
80
+ import { OrderSide, OrderState } from '@bitgen/sdk'
81
+
82
+ const order = await client.trading.get('ORDER_UUID')
83
+
84
+ console.log(order.side === OrderSide.BUY, order.state === OrderState.DONE) // true true
85
+ ```
86
+
87
+ Returns an `Order`:
88
+
89
+ | Field | Description |
90
+ |---|---|
91
+ | `uuid` | The order — the `tunnel` of `buy` / `sell` |
92
+ | `state` | A purchase goes `OrderState.REGISTERED` → `EXECUTING` → `FILLED` → `DELIVERING` → `DONE`; a sale `REGISTERED` → `TRANSFERRING` → `DEPOSITED` → `EXECUTING` → `FILLED` → `DONE`. `PARKED`: executed but nothing was received (terminal); `FAILED` |
93
+ | `side` | `OrderSide.BUY` or `OrderSide.SELL` |
94
+ | `amount` | What was asked, as a string: EUR for a purchase (`"25.00"`), a crypto quantity for a sale |
95
+ | `reference` | The idempotency key given, or `null` |
96
+ | `received` | What the customer got, or `null`: the crypto quantity for a purchase, the EUR credited for a sale |
97
+ | `executedPrice` | The EUR price of the token, or `null` |
98
+ | `fee` | Exchange fee, in EUR, or `null` |
99
+ | `completedAt`, `createdAt` | Epoch seconds — `completedAt` is `null` until the order completes |
100
+ | `user` | `OrderUser`: `{ uuid, login }` — a `UserRef` |
101
+ | `organization` | `OrderOrganization`: `{ uuid, name }` |
102
+ | `asset` | `AssetRef`: `{ uuid, iso, label }` |
103
+
104
+ An order outside your organization answers `404 unknown_order`.
105
+
106
+ ## list
107
+
108
+ ```
109
+ client.trading.list(params?: TradingListParams): Promise<Page<Order>>
110
+ ```
111
+
112
+ The orders of your organization, optionally filtered by customer (`user`), side and asset.
113
+
114
+ | Parameter | Type | Description |
115
+ |---|---|---|
116
+ | `params.user` | `UserRef` | Only the orders of this customer (uuid or model; unknown → `404 unknown_user`) |
117
+ | `params.direction` | `TradingDirection` | `TradingDirection.BUY` or `TradingDirection.SELL` (lowercase values) — absent, both |
118
+ | `params.asset` | `AssetInput` | Only this asset, by ISO code, uuid or model |
119
+ | `params.offset`, `params.limit` | `number` | [Pagination](../concepts.md#pagination) |
120
+
121
+ ```ts
122
+ import { Asset, TradingDirection } from '@bitgen/sdk'
123
+
124
+ const { count, items } = await client.trading.list({
125
+ user: 'CUSTOMER_UUID',
126
+ direction: TradingDirection.SELL,
127
+ asset: Asset.ETH,
128
+ offset: 0,
129
+ limit: 50,
130
+ })
131
+ ```
132
+
133
+ Returns a page of `Order`.
134
+
135
+ ## Errors
136
+
137
+ 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)):
138
+
139
+ | Status | `code` | Meaning |
140
+ |---|---|---|
141
+ | `403` | `user_not_in_scope` | The customer is not an `ENABLED` member of your organization |
142
+ | `403` | `account_frozen` | The customer's account is frozen |
143
+ | `403` | `wallet_frozen` | The customer's wallet is frozen |
144
+ | `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)) |
145
+ | `403` | `user_actions_disabled` | Customer actions are disabled for your organization (`user_can_actions` flag) |
146
+ | `404` | `unknown_bank` | The customer has no EUR account |
147
+ | `404` | `unknown_order` | Unknown order, or outside your organization |
148
+ | `404` | `unknown_user` | `list`: unknown `user` |
149
+ | `412` | `price_unavailable` | No price is available for the asset |
150
+ | `412` | `trading_not_enabled` | The `TRADING` connector of your organization is not enabled |
151
+ | `412` | `exchange_address_missing` | The deposit address of the exchange is missing |
152
+ | `416` | `invalid_amount` | The amount is not valid, or below the minimum |
153
+ | `416` | `amount_precision_exceeded` | More decimals than allowed |
154
+ | `416` | `amount_below_commission` | The amount does not cover the commission |
155
+ | `422` | `invalid_asset` | Unknown asset, or not `AVAILABLE` |
156
+ | `423` | `insufficient_funds` | `buy`: insufficient EUR balance |
157
+ | `423` | `blocked_by_alert` | An active compliance alert blocks the customer |
158
+ | `423` | `bank_lock_unavailable` | The EUR account is locked by a concurrent operation |
159
+
160
+ ## Related
161
+
162
+ - [Amounts](../concepts.md#amounts) — EUR and crypto amounts, minimums
163
+ - [Bank accounts](bank.md) — the EUR account purchases are paid from
164
+ - [Custody wallets](custody.md) — the wallets sales take crypto from
165
+ - [Assets catalogue](asset.md) — which assets are `AVAILABLE`, their decimals
166
+ - [Webhooks](webhooks.md) — `trading.buy`, `trading.sell`