@clear-street/studio-sdk 0.1.0-alpha.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.
Files changed (291) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/LICENSE +201 -0
  3. package/README.md +288 -0
  4. package/_shims/MultipartBody.d.ts +9 -0
  5. package/_shims/MultipartBody.d.ts.map +1 -0
  6. package/_shims/MultipartBody.js +16 -0
  7. package/_shims/MultipartBody.js.map +1 -0
  8. package/_shims/MultipartBody.mjs +12 -0
  9. package/_shims/MultipartBody.mjs.map +1 -0
  10. package/_shims/README.md +46 -0
  11. package/_shims/auto/runtime-bun.d.ts +5 -0
  12. package/_shims/auto/runtime-bun.d.ts.map +1 -0
  13. package/_shims/auto/runtime-bun.js +21 -0
  14. package/_shims/auto/runtime-bun.js.map +1 -0
  15. package/_shims/auto/runtime-bun.mjs +2 -0
  16. package/_shims/auto/runtime-bun.mjs.map +1 -0
  17. package/_shims/auto/runtime-node.d.ts +5 -0
  18. package/_shims/auto/runtime-node.d.ts.map +1 -0
  19. package/_shims/auto/runtime-node.js +21 -0
  20. package/_shims/auto/runtime-node.js.map +1 -0
  21. package/_shims/auto/runtime-node.mjs +2 -0
  22. package/_shims/auto/runtime-node.mjs.map +1 -0
  23. package/_shims/auto/runtime.d.ts +5 -0
  24. package/_shims/auto/runtime.d.ts.map +1 -0
  25. package/_shims/auto/runtime.js +21 -0
  26. package/_shims/auto/runtime.js.map +1 -0
  27. package/_shims/auto/runtime.mjs +2 -0
  28. package/_shims/auto/runtime.mjs.map +1 -0
  29. package/_shims/auto/types-node.d.ts +5 -0
  30. package/_shims/auto/types-node.d.ts.map +1 -0
  31. package/_shims/auto/types-node.js +21 -0
  32. package/_shims/auto/types-node.js.map +1 -0
  33. package/_shims/auto/types-node.mjs +2 -0
  34. package/_shims/auto/types-node.mjs.map +1 -0
  35. package/_shims/auto/types.d.ts +101 -0
  36. package/_shims/auto/types.js +3 -0
  37. package/_shims/auto/types.mjs +3 -0
  38. package/_shims/bun-runtime.d.ts +6 -0
  39. package/_shims/bun-runtime.d.ts.map +1 -0
  40. package/_shims/bun-runtime.js +14 -0
  41. package/_shims/bun-runtime.js.map +1 -0
  42. package/_shims/bun-runtime.mjs +10 -0
  43. package/_shims/bun-runtime.mjs.map +1 -0
  44. package/_shims/index.d.ts +81 -0
  45. package/_shims/index.js +13 -0
  46. package/_shims/index.mjs +7 -0
  47. package/_shims/manual-types.d.ts +12 -0
  48. package/_shims/manual-types.js +3 -0
  49. package/_shims/manual-types.mjs +3 -0
  50. package/_shims/node-runtime.d.ts +3 -0
  51. package/_shims/node-runtime.d.ts.map +1 -0
  52. package/_shims/node-runtime.js +90 -0
  53. package/_shims/node-runtime.js.map +1 -0
  54. package/_shims/node-runtime.mjs +56 -0
  55. package/_shims/node-runtime.mjs.map +1 -0
  56. package/_shims/node-types.d.ts +42 -0
  57. package/_shims/node-types.js +3 -0
  58. package/_shims/node-types.mjs +3 -0
  59. package/_shims/registry.d.ts +37 -0
  60. package/_shims/registry.d.ts.map +1 -0
  61. package/_shims/registry.js +41 -0
  62. package/_shims/registry.js.map +1 -0
  63. package/_shims/registry.mjs +37 -0
  64. package/_shims/registry.mjs.map +1 -0
  65. package/_shims/web-runtime.d.ts +5 -0
  66. package/_shims/web-runtime.d.ts.map +1 -0
  67. package/_shims/web-runtime.js +78 -0
  68. package/_shims/web-runtime.js.map +1 -0
  69. package/_shims/web-runtime.mjs +71 -0
  70. package/_shims/web-runtime.mjs.map +1 -0
  71. package/_shims/web-types.d.ts +83 -0
  72. package/_shims/web-types.js +3 -0
  73. package/_shims/web-types.mjs +3 -0
  74. package/core.d.ts +239 -0
  75. package/core.d.ts.map +1 -0
  76. package/core.js +881 -0
  77. package/core.js.map +1 -0
  78. package/core.mjs +850 -0
  79. package/core.mjs.map +1 -0
  80. package/error.d.ts +53 -0
  81. package/error.d.ts.map +1 -0
  82. package/error.js +143 -0
  83. package/error.js.map +1 -0
  84. package/error.mjs +127 -0
  85. package/error.mjs.map +1 -0
  86. package/index.d.mts +128 -0
  87. package/index.d.ts +128 -0
  88. package/index.d.ts.map +1 -0
  89. package/index.js +112 -0
  90. package/index.js.map +1 -0
  91. package/index.mjs +84 -0
  92. package/index.mjs.map +1 -0
  93. package/package.json +104 -0
  94. package/resource.d.ts +6 -0
  95. package/resource.d.ts.map +1 -0
  96. package/resource.js +11 -0
  97. package/resource.js.map +1 -0
  98. package/resource.mjs +7 -0
  99. package/resource.mjs.map +1 -0
  100. package/resources/accounts/accounts.d.ts +74 -0
  101. package/resources/accounts/accounts.d.ts.map +1 -0
  102. package/resources/accounts/accounts.js +73 -0
  103. package/resources/accounts/accounts.js.map +1 -0
  104. package/resources/accounts/accounts.mjs +46 -0
  105. package/resources/accounts/accounts.mjs.map +1 -0
  106. package/resources/accounts/bulk-orders.d.ts +137 -0
  107. package/resources/accounts/bulk-orders.d.ts.map +1 -0
  108. package/resources/accounts/bulk-orders.js +29 -0
  109. package/resources/accounts/bulk-orders.js.map +1 -0
  110. package/resources/accounts/bulk-orders.mjs +25 -0
  111. package/resources/accounts/bulk-orders.mjs.map +1 -0
  112. package/resources/accounts/easy-borrows.d.ts +17 -0
  113. package/resources/accounts/easy-borrows.d.ts.map +1 -0
  114. package/resources/accounts/easy-borrows.js +18 -0
  115. package/resources/accounts/easy-borrows.js.map +1 -0
  116. package/resources/accounts/easy-borrows.mjs +14 -0
  117. package/resources/accounts/easy-borrows.mjs.map +1 -0
  118. package/resources/accounts/index.d.ts +10 -0
  119. package/resources/accounts/index.d.ts.map +1 -0
  120. package/resources/accounts/index.js +23 -0
  121. package/resources/accounts/index.js.map +1 -0
  122. package/resources/accounts/index.mjs +11 -0
  123. package/resources/accounts/index.mjs.map +1 -0
  124. package/resources/accounts/locate-orders.d.ts +56 -0
  125. package/resources/accounts/locate-orders.d.ts.map +1 -0
  126. package/resources/accounts/locate-orders.js +39 -0
  127. package/resources/accounts/locate-orders.js.map +1 -0
  128. package/resources/accounts/locate-orders.mjs +35 -0
  129. package/resources/accounts/locate-orders.mjs.map +1 -0
  130. package/resources/accounts/orders.d.ts +168 -0
  131. package/resources/accounts/orders.d.ts.map +1 -0
  132. package/resources/accounts/orders.js +53 -0
  133. package/resources/accounts/orders.js.map +1 -0
  134. package/resources/accounts/orders.mjs +49 -0
  135. package/resources/accounts/orders.mjs.map +1 -0
  136. package/resources/accounts/pnl-details.d.ts +113 -0
  137. package/resources/accounts/pnl-details.d.ts.map +1 -0
  138. package/resources/accounts/pnl-details.js +17 -0
  139. package/resources/accounts/pnl-details.js.map +1 -0
  140. package/resources/accounts/pnl-details.mjs +13 -0
  141. package/resources/accounts/pnl-details.mjs.map +1 -0
  142. package/resources/accounts/pnl-summary.d.ts +10 -0
  143. package/resources/accounts/pnl-summary.d.ts.map +1 -0
  144. package/resources/accounts/pnl-summary.js +15 -0
  145. package/resources/accounts/pnl-summary.js.map +1 -0
  146. package/resources/accounts/pnl-summary.mjs +11 -0
  147. package/resources/accounts/pnl-summary.mjs.map +1 -0
  148. package/resources/accounts/positions.d.ts +37 -0
  149. package/resources/accounts/positions.d.ts.map +1 -0
  150. package/resources/accounts/positions.js +24 -0
  151. package/resources/accounts/positions.js.map +1 -0
  152. package/resources/accounts/positions.mjs +20 -0
  153. package/resources/accounts/positions.mjs.map +1 -0
  154. package/resources/accounts/trades.d.ts +37 -0
  155. package/resources/accounts/trades.d.ts.map +1 -0
  156. package/resources/accounts/trades.js +24 -0
  157. package/resources/accounts/trades.js.map +1 -0
  158. package/resources/accounts/trades.mjs +20 -0
  159. package/resources/accounts/trades.mjs.map +1 -0
  160. package/resources/entities/entities.d.ts +458 -0
  161. package/resources/entities/entities.d.ts.map +1 -0
  162. package/resources/entities/entities.js +61 -0
  163. package/resources/entities/entities.js.map +1 -0
  164. package/resources/entities/entities.mjs +34 -0
  165. package/resources/entities/entities.mjs.map +1 -0
  166. package/resources/entities/index.d.ts +6 -0
  167. package/resources/entities/index.d.ts.map +1 -0
  168. package/resources/entities/index.js +15 -0
  169. package/resources/entities/index.js.map +1 -0
  170. package/resources/entities/index.mjs +7 -0
  171. package/resources/entities/index.mjs.map +1 -0
  172. package/resources/entities/pnl-summaries.d.ts +10 -0
  173. package/resources/entities/pnl-summaries.d.ts.map +1 -0
  174. package/resources/entities/pnl-summaries.js +15 -0
  175. package/resources/entities/pnl-summaries.js.map +1 -0
  176. package/resources/entities/pnl-summaries.mjs +11 -0
  177. package/resources/entities/pnl-summaries.mjs.map +1 -0
  178. package/resources/entities/portfolio-margins.d.ts +10 -0
  179. package/resources/entities/portfolio-margins.d.ts.map +1 -0
  180. package/resources/entities/portfolio-margins.js +15 -0
  181. package/resources/entities/portfolio-margins.js.map +1 -0
  182. package/resources/entities/portfolio-margins.mjs +11 -0
  183. package/resources/entities/portfolio-margins.mjs.map +1 -0
  184. package/resources/entities/regt-margin-simulations.d.ts +97 -0
  185. package/resources/entities/regt-margin-simulations.d.ts.map +1 -0
  186. package/resources/entities/regt-margin-simulations.js +30 -0
  187. package/resources/entities/regt-margin-simulations.js.map +1 -0
  188. package/resources/entities/regt-margin-simulations.mjs +26 -0
  189. package/resources/entities/regt-margin-simulations.mjs.map +1 -0
  190. package/resources/entities/regt-margins.d.ts +10 -0
  191. package/resources/entities/regt-margins.d.ts.map +1 -0
  192. package/resources/entities/regt-margins.js +15 -0
  193. package/resources/entities/regt-margins.js.map +1 -0
  194. package/resources/entities/regt-margins.mjs +11 -0
  195. package/resources/entities/regt-margins.mjs.map +1 -0
  196. package/resources/index.d.ts +5 -0
  197. package/resources/index.d.ts.map +1 -0
  198. package/resources/index.js +26 -0
  199. package/resources/index.js.map +1 -0
  200. package/resources/index.mjs +6 -0
  201. package/resources/index.mjs.map +1 -0
  202. package/resources/instruments.d.ts +45 -0
  203. package/resources/instruments.d.ts.map +1 -0
  204. package/resources/instruments.js +18 -0
  205. package/resources/instruments.js.map +1 -0
  206. package/resources/instruments.mjs +14 -0
  207. package/resources/instruments.mjs.map +1 -0
  208. package/resources/shared.d.ts +251 -0
  209. package/resources/shared.d.ts.map +1 -0
  210. package/resources/shared.js +4 -0
  211. package/resources/shared.js.map +1 -0
  212. package/resources/shared.mjs +3 -0
  213. package/resources/shared.mjs.map +1 -0
  214. package/shims/node.d.ts +29 -0
  215. package/shims/node.d.ts.map +1 -0
  216. package/shims/node.js +31 -0
  217. package/shims/node.js.map +1 -0
  218. package/shims/node.mjs +5 -0
  219. package/shims/node.mjs.map +1 -0
  220. package/shims/web.d.ts +26 -0
  221. package/shims/web.d.ts.map +1 -0
  222. package/shims/web.js +31 -0
  223. package/shims/web.js.map +1 -0
  224. package/shims/web.mjs +5 -0
  225. package/shims/web.mjs.map +1 -0
  226. package/src/_shims/MultipartBody.ts +9 -0
  227. package/src/_shims/README.md +46 -0
  228. package/src/_shims/auto/runtime-bun.ts +4 -0
  229. package/src/_shims/auto/runtime-node.ts +4 -0
  230. package/src/_shims/auto/runtime.ts +4 -0
  231. package/src/_shims/auto/types-node.ts +4 -0
  232. package/src/_shims/auto/types.d.ts +101 -0
  233. package/src/_shims/auto/types.js +3 -0
  234. package/src/_shims/auto/types.mjs +3 -0
  235. package/src/_shims/bun-runtime.ts +14 -0
  236. package/src/_shims/index.d.ts +81 -0
  237. package/src/_shims/index.js +13 -0
  238. package/src/_shims/index.mjs +7 -0
  239. package/src/_shims/manual-types.d.ts +12 -0
  240. package/src/_shims/manual-types.js +3 -0
  241. package/src/_shims/manual-types.mjs +3 -0
  242. package/src/_shims/node-runtime.ts +83 -0
  243. package/src/_shims/node-types.d.ts +42 -0
  244. package/src/_shims/node-types.js +3 -0
  245. package/src/_shims/node-types.mjs +3 -0
  246. package/src/_shims/registry.ts +67 -0
  247. package/src/_shims/web-runtime.ts +103 -0
  248. package/src/_shims/web-types.d.ts +83 -0
  249. package/src/_shims/web-types.js +3 -0
  250. package/src/_shims/web-types.mjs +3 -0
  251. package/src/core.ts +1165 -0
  252. package/src/error.ts +146 -0
  253. package/src/index.ts +206 -0
  254. package/src/lib/.keep +4 -0
  255. package/src/resource.ts +11 -0
  256. package/src/resources/accounts/accounts.ts +87 -0
  257. package/src/resources/accounts/bulk-orders.ts +163 -0
  258. package/src/resources/accounts/easy-borrows.ts +23 -0
  259. package/src/resources/accounts/index.ts +25 -0
  260. package/src/resources/accounts/locate-orders.ts +94 -0
  261. package/src/resources/accounts/orders.ts +246 -0
  262. package/src/resources/accounts/pnl-details.ts +143 -0
  263. package/src/resources/accounts/pnl-summary.ts +14 -0
  264. package/src/resources/accounts/positions.ts +66 -0
  265. package/src/resources/accounts/trades.ts +62 -0
  266. package/src/resources/entities/entities.ts +562 -0
  267. package/src/resources/entities/index.ts +12 -0
  268. package/src/resources/entities/pnl-summaries.ts +14 -0
  269. package/src/resources/entities/portfolio-margins.ts +14 -0
  270. package/src/resources/entities/regt-margin-simulations.ts +127 -0
  271. package/src/resources/entities/regt-margins.ts +14 -0
  272. package/src/resources/index.ts +13 -0
  273. package/src/resources/instruments.ts +70 -0
  274. package/src/resources/shared.ts +320 -0
  275. package/src/shims/node.ts +50 -0
  276. package/src/shims/web.ts +50 -0
  277. package/src/tsconfig.json +11 -0
  278. package/src/uploads.ts +248 -0
  279. package/src/version.ts +1 -0
  280. package/uploads.d.ts +75 -0
  281. package/uploads.d.ts.map +1 -0
  282. package/uploads.js +165 -0
  283. package/uploads.js.map +1 -0
  284. package/uploads.mjs +152 -0
  285. package/uploads.mjs.map +1 -0
  286. package/version.d.ts +2 -0
  287. package/version.d.ts.map +1 -0
  288. package/version.js +5 -0
  289. package/version.js.map +1 -0
  290. package/version.mjs +2 -0
  291. package/version.mjs.map +1 -0
package/src/error.ts ADDED
@@ -0,0 +1,146 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { castToError, Headers } from './core';
4
+
5
+ export class StudioSDKError extends Error {}
6
+
7
+ export class APIError extends StudioSDKError {
8
+ readonly status: number | undefined;
9
+ readonly headers: Headers | undefined;
10
+ readonly error: Object | undefined;
11
+
12
+ constructor(
13
+ status: number | undefined,
14
+ error: Object | undefined,
15
+ message: string | undefined,
16
+ headers: Headers | undefined,
17
+ ) {
18
+ super(`${APIError.makeMessage(status, error, message)}`);
19
+ this.status = status;
20
+ this.headers = headers;
21
+ this.error = error;
22
+ }
23
+
24
+ private static makeMessage(status: number | undefined, error: any, message: string | undefined) {
25
+ const msg =
26
+ error?.message ?
27
+ typeof error.message === 'string' ?
28
+ error.message
29
+ : JSON.stringify(error.message)
30
+ : error ? JSON.stringify(error)
31
+ : message;
32
+
33
+ if (status && msg) {
34
+ return `${status} ${msg}`;
35
+ }
36
+ if (status) {
37
+ return `${status} status code (no body)`;
38
+ }
39
+ if (msg) {
40
+ return msg;
41
+ }
42
+ return '(no status code or body)';
43
+ }
44
+
45
+ static generate(
46
+ status: number | undefined,
47
+ errorResponse: Object | undefined,
48
+ message: string | undefined,
49
+ headers: Headers | undefined,
50
+ ) {
51
+ if (!status) {
52
+ return new APIConnectionError({ cause: castToError(errorResponse) });
53
+ }
54
+
55
+ const error = errorResponse as Record<string, any>;
56
+
57
+ if (status === 400) {
58
+ return new BadRequestError(status, error, message, headers);
59
+ }
60
+
61
+ if (status === 401) {
62
+ return new AuthenticationError(status, error, message, headers);
63
+ }
64
+
65
+ if (status === 403) {
66
+ return new PermissionDeniedError(status, error, message, headers);
67
+ }
68
+
69
+ if (status === 404) {
70
+ return new NotFoundError(status, error, message, headers);
71
+ }
72
+
73
+ if (status === 409) {
74
+ return new ConflictError(status, error, message, headers);
75
+ }
76
+
77
+ if (status === 422) {
78
+ return new UnprocessableEntityError(status, error, message, headers);
79
+ }
80
+
81
+ if (status === 429) {
82
+ return new RateLimitError(status, error, message, headers);
83
+ }
84
+
85
+ if (status >= 500) {
86
+ return new InternalServerError(status, error, message, headers);
87
+ }
88
+
89
+ return new APIError(status, error, message, headers);
90
+ }
91
+ }
92
+
93
+ export class APIUserAbortError extends APIError {
94
+ override readonly status: undefined = undefined;
95
+
96
+ constructor({ message }: { message?: string } = {}) {
97
+ super(undefined, undefined, message || 'Request was aborted.', undefined);
98
+ }
99
+ }
100
+
101
+ export class APIConnectionError extends APIError {
102
+ override readonly status: undefined = undefined;
103
+
104
+ constructor({ message, cause }: { message?: string; cause?: Error | undefined }) {
105
+ super(undefined, undefined, message || 'Connection error.', undefined);
106
+ // in some environments the 'cause' property is already declared
107
+ // @ts-ignore
108
+ if (cause) this.cause = cause;
109
+ }
110
+ }
111
+
112
+ export class APIConnectionTimeoutError extends APIConnectionError {
113
+ constructor({ message }: { message?: string } = {}) {
114
+ super({ message: message ?? 'Request timed out.' });
115
+ }
116
+ }
117
+
118
+ export class BadRequestError extends APIError {
119
+ override readonly status: 400 = 400;
120
+ }
121
+
122
+ export class AuthenticationError extends APIError {
123
+ override readonly status: 401 = 401;
124
+ }
125
+
126
+ export class PermissionDeniedError extends APIError {
127
+ override readonly status: 403 = 403;
128
+ }
129
+
130
+ export class NotFoundError extends APIError {
131
+ override readonly status: 404 = 404;
132
+ }
133
+
134
+ export class ConflictError extends APIError {
135
+ override readonly status: 409 = 409;
136
+ }
137
+
138
+ export class UnprocessableEntityError extends APIError {
139
+ override readonly status: 422 = 422;
140
+ }
141
+
142
+ export class RateLimitError extends APIError {
143
+ override readonly status: 429 = 429;
144
+ }
145
+
146
+ export class InternalServerError extends APIError {}
package/src/index.ts ADDED
@@ -0,0 +1,206 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import * as Errors from './error';
4
+ import * as Uploads from './uploads';
5
+ import { type Agent } from './_shims/index';
6
+ import * as Core from "./core";
7
+ import * as API from "./resources/index";
8
+
9
+ export interface ClientOptions {
10
+ /**
11
+ * Defaults to process.env['STUDIO_SDK_BEARER_TOKEN'].
12
+ */
13
+ bearerToken?: string | undefined;
14
+
15
+ /**
16
+ * Override the default base URL for the API, e.g., "https://api.example.com/v2/"
17
+ *
18
+ * Defaults to process.env['STUDIO_SDK_BASE_URL'].
19
+ */
20
+ baseURL?: string | null | undefined;
21
+
22
+ /**
23
+ * The maximum amount of time (in milliseconds) that the client should wait for a response
24
+ * from the server before timing out a single request.
25
+ *
26
+ * Note that request timeouts are retried by default, so in a worst-case scenario you may wait
27
+ * much longer than this timeout before the promise succeeds or fails.
28
+ */
29
+ timeout?: number;
30
+
31
+ /**
32
+ * An HTTP agent used to manage HTTP(S) connections.
33
+ *
34
+ * If not provided, an agent will be constructed by default in the Node.js environment,
35
+ * otherwise no agent is used.
36
+ */
37
+ httpAgent?: Agent;
38
+
39
+ /**
40
+ * Specify a custom `fetch` function implementation.
41
+ *
42
+ * If not provided, we use `node-fetch` on Node.js and otherwise expect that `fetch` is
43
+ * defined globally.
44
+ */
45
+ fetch?: Core.Fetch | undefined;
46
+
47
+ /**
48
+ * The maximum number of times that the client will retry a request in case of a
49
+ * temporary failure, like a network error or a 5XX error from the server.
50
+ *
51
+ * @default 2
52
+ */
53
+ maxRetries?: number;
54
+
55
+ /**
56
+ * Default headers to include with every request to the API.
57
+ *
58
+ * These can be removed in individual requests by explicitly setting the
59
+ * header to `undefined` or `null` in request options.
60
+ */
61
+ defaultHeaders?: Core.Headers;
62
+
63
+ /**
64
+ * Default query parameters to include with every request to the API.
65
+ *
66
+ * These can be removed in individual requests by explicitly setting the
67
+ * param to `undefined` in request options.
68
+ */
69
+ defaultQuery?: Core.DefaultQuery;
70
+ }
71
+
72
+ /**
73
+ * API Client for interfacing with the Studio SDK API.
74
+ */
75
+ export class StudioSDK extends Core.APIClient {
76
+ bearerToken: string;
77
+
78
+ private _options: ClientOptions;
79
+
80
+ /**
81
+ * API Client for interfacing with the Studio SDK API.
82
+ *
83
+ * @param {string | undefined} [opts.bearerToken=process.env['STUDIO_SDK_BEARER_TOKEN'] ?? undefined]
84
+ * @param {string} [opts.baseURL=process.env['STUDIO_SDK_BASE_URL'] ?? https://api.clearstreet.io/studio/v2] - Override the default base URL for the API.
85
+ * @param {number} [opts.timeout=1 minute] - The maximum amount of time (in milliseconds) the client will wait for a response before timing out.
86
+ * @param {number} [opts.httpAgent] - An HTTP agent used to manage HTTP(s) connections.
87
+ * @param {Core.Fetch} [opts.fetch] - Specify a custom `fetch` function implementation.
88
+ * @param {number} [opts.maxRetries=2] - The maximum number of times the client will retry a request.
89
+ * @param {Core.Headers} opts.defaultHeaders - Default headers to include with every request to the API.
90
+ * @param {Core.DefaultQuery} opts.defaultQuery - Default query parameters to include with every request to the API.
91
+ */
92
+ constructor({
93
+ baseURL = Core.readEnv('STUDIO_SDK_BASE_URL'),
94
+ bearerToken = Core.readEnv('STUDIO_SDK_BEARER_TOKEN'),
95
+ ...opts
96
+ }: ClientOptions = {}) {
97
+ if (bearerToken === undefined) {
98
+ throw new Errors.StudioSDKError(
99
+ "The STUDIO_SDK_BEARER_TOKEN environment variable is missing or empty; either provide it, or instantiate the StudioSDK client with an bearerToken option, like new StudioSDK({ bearerToken: 'My Bearer Token' }).",
100
+ );
101
+ }
102
+
103
+ const options: ClientOptions = {
104
+ bearerToken,
105
+ ...opts,
106
+ baseURL: baseURL || `https://api.clearstreet.io/studio/v2`,
107
+ };
108
+
109
+ super({
110
+ baseURL: options.baseURL!,
111
+ timeout: options.timeout ?? 60000 /* 1 minute */,
112
+ httpAgent: options.httpAgent,
113
+ maxRetries: options.maxRetries,
114
+ fetch: options.fetch,
115
+ });
116
+
117
+ this._options = options;
118
+
119
+ this.bearerToken = bearerToken;
120
+ }
121
+
122
+ entities: API.Entities = new API.Entities(this);
123
+ accounts: API.Accounts = new API.Accounts(this);
124
+ instruments: API.Instruments = new API.Instruments(this);
125
+
126
+ protected override defaultQuery(): Core.DefaultQuery | undefined {
127
+ return this._options.defaultQuery;
128
+ }
129
+
130
+ protected override defaultHeaders(opts: Core.FinalRequestOptions): Core.Headers {
131
+ return {
132
+ ...super.defaultHeaders(opts),
133
+ ...this._options.defaultHeaders,
134
+ };
135
+ }
136
+
137
+ protected override authHeaders(opts: Core.FinalRequestOptions): Core.Headers {
138
+ return { Authorization: `Bearer ${this.bearerToken}` };
139
+ }
140
+
141
+ static StudioSDK = this;
142
+
143
+ static StudioSDKError = Errors.StudioSDKError;
144
+ static APIError = Errors.APIError;
145
+ static APIConnectionError = Errors.APIConnectionError;
146
+ static APIConnectionTimeoutError = Errors.APIConnectionTimeoutError;
147
+ static APIUserAbortError = Errors.APIUserAbortError;
148
+ static NotFoundError = Errors.NotFoundError;
149
+ static ConflictError = Errors.ConflictError;
150
+ static RateLimitError = Errors.RateLimitError;
151
+ static BadRequestError = Errors.BadRequestError;
152
+ static AuthenticationError = Errors.AuthenticationError;
153
+ static InternalServerError = Errors.InternalServerError;
154
+ static PermissionDeniedError = Errors.PermissionDeniedError;
155
+ static UnprocessableEntityError = Errors.UnprocessableEntityError;
156
+
157
+ static toFile = Uploads.toFile;
158
+ static fileFromPath = Uploads.fileFromPath;
159
+ }
160
+
161
+ export const {
162
+ StudioSDKError,
163
+ APIError,
164
+ APIConnectionError,
165
+ APIConnectionTimeoutError,
166
+ APIUserAbortError,
167
+ NotFoundError,
168
+ ConflictError,
169
+ RateLimitError,
170
+ BadRequestError,
171
+ AuthenticationError,
172
+ InternalServerError,
173
+ PermissionDeniedError,
174
+ UnprocessableEntityError,
175
+ } = Errors;
176
+
177
+ export import toFile = Uploads.toFile;
178
+ export import fileFromPath = Uploads.fileFromPath;
179
+
180
+ export namespace StudioSDK {
181
+ export import RequestOptions = Core.RequestOptions;
182
+
183
+ export import Entities = API.Entities;
184
+ export import Entity = API.Entity;
185
+ export import PnlSummary = API.PnlSummary;
186
+ export import PortfolioMargin = API.PortfolioMargin;
187
+ export import RegtMargin = API.RegtMargin;
188
+ export import EntityListResponse = API.EntityListResponse;
189
+
190
+ export import Accounts = API.Accounts;
191
+ export import Account = API.Account;
192
+ export import AccountListResponse = API.AccountListResponse;
193
+
194
+ export import Instruments = API.Instruments;
195
+ export import Instrument = API.Instrument;
196
+ export import InstrumentRetrieveParams = API.InstrumentRetrieveParams;
197
+
198
+ export import LocateOrder = API.LocateOrder;
199
+ export import Order = API.Order;
200
+ export import PnlSummaryForAccount = API.PnlSummaryForAccount;
201
+ export import Position = API.Position;
202
+ export import RegtMarginSimulation = API.RegtMarginSimulation;
203
+ export import Trade = API.Trade;
204
+ }
205
+
206
+ export default StudioSDK;
package/src/lib/.keep ADDED
@@ -0,0 +1,4 @@
1
+ File generated from our OpenAPI spec by Stainless.
2
+
3
+ This directory can be used to store custom files to expand the SDK.
4
+ It is ignored by Stainless code generation and its content (other than this keep file) won't be touched.
@@ -0,0 +1,11 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import type { StudioSDK } from './index';
4
+
5
+ export class APIResource {
6
+ protected _client: StudioSDK;
7
+
8
+ constructor(client: StudioSDK) {
9
+ this._client = client;
10
+ }
11
+ }
@@ -0,0 +1,87 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../../resource";
4
+ import * as Core from "../../core";
5
+ import * as AccountsAPI from "./accounts";
6
+ import * as BulkOrdersAPI from "./bulk-orders";
7
+ import * as EasyBorrowsAPI from "./easy-borrows";
8
+ import * as LocateOrdersAPI from "./locate-orders";
9
+ import * as OrdersAPI from "./orders";
10
+ import * as PnlDetailsAPI from "./pnl-details";
11
+ import * as PnlSummaryAPI from "./pnl-summary";
12
+ import * as PositionsAPI from "./positions";
13
+ import * as TradesAPI from "./trades";
14
+
15
+ export class Accounts extends APIResource {
16
+ bulkOrders: BulkOrdersAPI.BulkOrders = new BulkOrdersAPI.BulkOrders(this._client);
17
+ orders: OrdersAPI.Orders = new OrdersAPI.Orders(this._client);
18
+ trades: TradesAPI.Trades = new TradesAPI.Trades(this._client);
19
+ positions: PositionsAPI.Positions = new PositionsAPI.Positions(this._client);
20
+ locateOrders: LocateOrdersAPI.LocateOrders = new LocateOrdersAPI.LocateOrders(this._client);
21
+ easyBorrows: EasyBorrowsAPI.EasyBorrows = new EasyBorrowsAPI.EasyBorrows(this._client);
22
+ pnlSummary: PnlSummaryAPI.PnlSummary = new PnlSummaryAPI.PnlSummary(this._client);
23
+ pnlDetails: PnlDetailsAPI.PnlDetails = new PnlDetailsAPI.PnlDetails(this._client);
24
+
25
+ /**
26
+ * Get an account by its ID.
27
+ */
28
+ retrieve(accountId: string, options?: Core.RequestOptions): Core.APIPromise<Account> {
29
+ return this._client.get(`/accounts/${accountId}`, options);
30
+ }
31
+
32
+ /**
33
+ * List all available accounts.
34
+ */
35
+ list(options?: Core.RequestOptions): Core.APIPromise<AccountListResponse> {
36
+ return this._client.get('/accounts', options);
37
+ }
38
+ }
39
+
40
+ export interface Account {
41
+ /**
42
+ * Account ID for the account.
43
+ */
44
+ account_id: string;
45
+
46
+ /**
47
+ * Entity ID for the legal entity.
48
+ */
49
+ entity_id: string;
50
+
51
+ name: string;
52
+ }
53
+
54
+ export interface AccountListResponse {
55
+ data?: Array<Account>;
56
+ }
57
+
58
+ export namespace Accounts {
59
+ export import Account = AccountsAPI.Account;
60
+ export import AccountListResponse = AccountsAPI.AccountListResponse;
61
+ export import BulkOrders = BulkOrdersAPI.BulkOrders;
62
+ export import BulkOrderCreateResponse = BulkOrdersAPI.BulkOrderCreateResponse;
63
+ export import BulkOrderCreateParams = BulkOrdersAPI.BulkOrderCreateParams;
64
+ export import Orders = OrdersAPI.Orders;
65
+ export import OrderCreateResponse = OrdersAPI.OrderCreateResponse;
66
+ export import OrderRetrieveResponse = OrdersAPI.OrderRetrieveResponse;
67
+ export import OrderListResponse = OrdersAPI.OrderListResponse;
68
+ export import OrderDeleteResponse = OrdersAPI.OrderDeleteResponse;
69
+ export import OrderCreateParams = OrdersAPI.OrderCreateParams;
70
+ export import OrderListParams = OrdersAPI.OrderListParams;
71
+ export import OrderDeleteParams = OrdersAPI.OrderDeleteParams;
72
+ export import Trades = TradesAPI.Trades;
73
+ export import TradeListResponse = TradesAPI.TradeListResponse;
74
+ export import TradeListParams = TradesAPI.TradeListParams;
75
+ export import Positions = PositionsAPI.Positions;
76
+ export import PositionListResponse = PositionsAPI.PositionListResponse;
77
+ export import PositionListParams = PositionsAPI.PositionListParams;
78
+ export import LocateOrders = LocateOrdersAPI.LocateOrders;
79
+ export import LocateOrderListResponse = LocateOrdersAPI.LocateOrderListResponse;
80
+ export import LocateOrderCreateParams = LocateOrdersAPI.LocateOrderCreateParams;
81
+ export import LocateOrderUpdateParams = LocateOrdersAPI.LocateOrderUpdateParams;
82
+ export import EasyBorrows = EasyBorrowsAPI.EasyBorrows;
83
+ export import EasyBorrowListResponse = EasyBorrowsAPI.EasyBorrowListResponse;
84
+ export import PnlSummary = PnlSummaryAPI.PnlSummary;
85
+ export import PnlDetails = PnlDetailsAPI.PnlDetails;
86
+ export import PnlDetailListResponse = PnlDetailsAPI.PnlDetailListResponse;
87
+ }
@@ -0,0 +1,163 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../../resource";
4
+ import * as Core from "../../core";
5
+ import * as BulkOrdersAPI from "./bulk-orders";
6
+
7
+ export class BulkOrders extends APIResource {
8
+ /**
9
+ * Creates multiple orders in a single request, up to 1000. Note that a successful
10
+ * call to this endpoint does not necessarily mean your orders have been accepted,
11
+ * e.g. a downstream venue might reject your order. You should therefore utilize
12
+ * our WebSocket APIs to listen for changes in order lifecycle events.
13
+ *
14
+ * The response will contain an array of objects, indicating whether your order was
15
+ * submitted. If the order was submitted, the `order_id` field will be populated
16
+ * with the order ID assigned to this order. If the order was rejected, the
17
+ * `reason` field will be populated with the reason for rejection. The data array
18
+ * returned in the response object is guaranteed to be ordered in the same order as
19
+ * the orders you provided in the request. Again, note that even if your order was
20
+ * submitted, that doesn't mean it was _accepted_, and may still be rejected by
21
+ * downstream venues.
22
+ */
23
+ create(
24
+ accountId: string,
25
+ body: BulkOrderCreateParams,
26
+ options?: Core.RequestOptions,
27
+ ): Core.APIPromise<BulkOrderCreateResponse> {
28
+ return this._client.post(`/accounts/${accountId}/bulk-orders`, { body, ...options });
29
+ }
30
+ }
31
+
32
+ export interface BulkOrderCreateResponse {
33
+ /**
34
+ * Array indicating whether each respective order was submitted or not. This array
35
+ * is guaranteed to be sorted in the same order as the orders you provided in your
36
+ * request.
37
+ */
38
+ data: Array<BulkOrderCreateResponse.Data>;
39
+
40
+ /**
41
+ * Total number of orders rejected
42
+ */
43
+ rejected: number;
44
+
45
+ /**
46
+ * Total number of orders submitted
47
+ */
48
+ submitted: number;
49
+ }
50
+
51
+ export namespace BulkOrderCreateResponse {
52
+ export interface Data {
53
+ /**
54
+ * True if the order was submitted successfully, false otherwise.
55
+ */
56
+ submitted: boolean;
57
+
58
+ /**
59
+ * If the order was submitted, the order ID assigned to this order. Empty if the
60
+ * order was rejected.
61
+ */
62
+ order_id?: string;
63
+
64
+ /**
65
+ * If the order rejected, the reason for rejection. Empty if the order was
66
+ * accepted.
67
+ */
68
+ reason?: string;
69
+ }
70
+ }
71
+
72
+ export interface BulkOrderCreateParams {
73
+ /**
74
+ * An array of orders to create.
75
+ */
76
+ orders: Array<BulkOrderCreateParams.Order>;
77
+ }
78
+
79
+ export namespace BulkOrderCreateParams {
80
+ export interface Order {
81
+ /**
82
+ * The type of order, can be one of the following:
83
+ *
84
+ * - `limit`: A limit order will execute at-or-better than the limit price you
85
+ * specify
86
+ * - `market`: An order that will execute at the prevailing market prices
87
+ */
88
+ order_type: 'limit' | 'market';
89
+
90
+ /**
91
+ * The maximum quantity to be executed.
92
+ */
93
+ quantity: string;
94
+
95
+ /**
96
+ * Buy, sell, sell-short indicator.
97
+ */
98
+ side: 'buy' | 'sell' | 'sell-short';
99
+
100
+ /**
101
+ * Strategy type used for execution, can be one of below. Note, we use sensible
102
+ * defaults for strategy parameters at the moment. In future, we will provide a way
103
+ * to provide specify these parameters.
104
+ *
105
+ * - `sor`: Smart order router
106
+ * - `dark`: Dark pool
107
+ * - `ap`: Arrival price
108
+ * - `pov`: Percentage of volume
109
+ * - `twap`: Time weighted average price
110
+ * - `vwap`: Volume weighted average price
111
+ *
112
+ * For more information on these strategies, please refer to our
113
+ * [documentation](https://docs.clearstreet.io/studio/docs/execution-strategies).
114
+ */
115
+ strategy_type: 'sor' | 'dark' | 'ap' | 'pov' | 'twap' | 'vwap';
116
+
117
+ /**
118
+ * The symbol this order is for. See `symbol_format` for supported symbol formats.
119
+ */
120
+ symbol: string;
121
+
122
+ /**
123
+ * The lifecycle enforcement of this order.
124
+ *
125
+ * - `day`: The order will exist for the duration of the current trading session
126
+ * - `ioc`: The order will immediately be executed or cancelled
127
+ * - `day-plus`: The order will exist only for the duration the current trading
128
+ * session plus extended hours, if applicable
129
+ * - `at-open`: The order will exist only for the opening auction of the next
130
+ * session
131
+ * - `at-close`: The order will exist only for the closing auction of the current
132
+ * session
133
+ */
134
+ time_in_force: 'day' | 'ioc' | 'day-plus' | 'at-open' | 'at-close';
135
+
136
+ /**
137
+ * Name of the broker that provided you inventory for a short-sale. Required if
138
+ * `side` is `sell-short`. If you procured inventory through us, you can use
139
+ * `CLST`.
140
+ */
141
+ locate_broker?: string;
142
+
143
+ /**
144
+ * The price to execute at-or-better.
145
+ */
146
+ price?: string;
147
+
148
+ /**
149
+ * An ID that you provide.
150
+ */
151
+ reference_id?: string;
152
+
153
+ /**
154
+ * Denotes the format of the provided `symbol` field.
155
+ */
156
+ symbol_format?: 'cms' | 'osi';
157
+ }
158
+ }
159
+
160
+ export namespace BulkOrders {
161
+ export import BulkOrderCreateResponse = BulkOrdersAPI.BulkOrderCreateResponse;
162
+ export import BulkOrderCreateParams = BulkOrdersAPI.BulkOrderCreateParams;
163
+ }
@@ -0,0 +1,23 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from "../../resource";
4
+ import * as Core from "../../core";
5
+ import * as EasyBorrowsAPI from "./easy-borrows";
6
+
7
+ export class EasyBorrows extends APIResource {
8
+ /**
9
+ * List all current easy-to-borrow stock symbols. This list changes dynamically
10
+ * daily.
11
+ */
12
+ list(accountId: string, options?: Core.RequestOptions): Core.APIPromise<EasyBorrowListResponse> {
13
+ return this._client.get(`/accounts/${accountId}/easy-borrows`, options);
14
+ }
15
+ }
16
+
17
+ export interface EasyBorrowListResponse {
18
+ data: Array<string>;
19
+ }
20
+
21
+ export namespace EasyBorrows {
22
+ export import EasyBorrowListResponse = EasyBorrowsAPI.EasyBorrowListResponse;
23
+ }
@@ -0,0 +1,25 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ export { Account, AccountListResponse, Accounts } from './accounts';
4
+ export { BulkOrderCreateResponse, BulkOrderCreateParams, BulkOrders } from './bulk-orders';
5
+ export { EasyBorrowListResponse, EasyBorrows } from './easy-borrows';
6
+ export {
7
+ LocateOrderListResponse,
8
+ LocateOrderCreateParams,
9
+ LocateOrderUpdateParams,
10
+ LocateOrders,
11
+ } from './locate-orders';
12
+ export {
13
+ OrderCreateResponse,
14
+ OrderRetrieveResponse,
15
+ OrderListResponse,
16
+ OrderDeleteResponse,
17
+ OrderCreateParams,
18
+ OrderListParams,
19
+ OrderDeleteParams,
20
+ Orders,
21
+ } from './orders';
22
+ export { PnlDetailListResponse, PnlDetails } from './pnl-details';
23
+ export { PnlSummary } from './pnl-summary';
24
+ export { PositionListResponse, PositionListParams, Positions } from './positions';
25
+ export { TradeListResponse, TradeListParams, Trades } from './trades';