Skip to content

Commit

Permalink
Merge pull request #55 from clear-street/release-please--branches--ma…
Browse files Browse the repository at this point in the history
…in--changes--next--components--studio-sdk

release: 0.1.0-alpha.12
  • Loading branch information
sonicxml authored Nov 1, 2024
2 parents 4dfcaad + b73004a commit c9fc3d7
Show file tree
Hide file tree
Showing 13 changed files with 238 additions and 97 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
".": "0.1.0-alpha.10"
".": "0.1.0-alpha.12"
}
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 29
configured_endpoints: 30
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/clear-street%2Fstudio-sdk-468b5da24bbf73b3a3861d44c5a8051fe6c55a6ec64c5c6f2d45f22c76bf35b2.yml
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 0.1.0-alpha.12 (2024-11-01)

Full Changelog: [v0.1.0-alpha.10...v0.1.0-alpha.12](https://github.com/clear-street/studio-sdk-node/compare/v0.1.0-alpha.10...v0.1.0-alpha.12)

### Features

* **api:** enable inventories endpoint ([#54](https://github.com/clear-street/studio-sdk-node/issues/54)) ([8b58322](https://github.com/clear-street/studio-sdk-node/commit/8b58322a671d6f51b422b4a1ef46b36bf9c43b25))

## 0.1.0-alpha.10 (2024-10-11)

Full Changelog: [v0.1.0-alpha.9...v0.1.0-alpha.10](https://github.com/clear-street/studio-sdk-node/compare/v0.1.0-alpha.9...v0.1.0-alpha.10)
Expand Down
10 changes: 10 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ Methods:

- <code title="get /accounts/{account_id}/holdings">client.accounts.holdings.<a href="./src/resources/accounts/holdings.ts">list</a>(accountId, { ...params }) -> HoldingListResponse</code>

## Inventories

Types:

- <code><a href="./src/resources/accounts/inventories.ts">InventoryRetrieveResponse</a></code>

Methods:

- <code title="get /accounts/{account_id}/inventories/{symbol}">client.accounts.inventories.<a href="./src/resources/accounts/inventories.ts">retrieve</a>(accountId, symbol) -> InventoryRetrieveResponse</code>

# Instruments

Types:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@clear-street/studio-sdk",
"version": "0.1.0-alpha.10",
"version": "0.1.0-alpha.12",
"description": "The official TypeScript library for the Studio SDK API",
"author": "Studio SDK <[email protected]>",
"types": "dist/index.d.ts",
Expand Down
16 changes: 11 additions & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ export class APIPromise<T> extends Promise<T> {
});
}

_thenUnwrap<U>(transform: (data: T) => U): APIPromise<U> {
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
return new APIPromise(this.responsePromise, async (props) =>
transform(await this.parseResponse(props), props),
);
}

/**
Expand Down Expand Up @@ -349,9 +351,13 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

// Don't set the retry count header if it was already set or removed by the caller. We check `headers`,
// which can contain nulls, instead of `reqHeaders` to account for the removal case.
if (getHeader(headers, 'x-stainless-retry-count') === undefined) {
// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
if (
getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
getHeader(headers, 'x-stainless-retry-count') === undefined
) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}

Expand Down
4 changes: 4 additions & 0 deletions src/resources/accounts/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as AccountsAPI from './accounts';
import * as BulkOrdersAPI from './bulk-orders';
import * as EasyBorrowsAPI from './easy-borrows';
import * as HoldingsAPI from './holdings';
import * as InventoriesAPI from './inventories';
import * as LocateOrdersAPI from './locate-orders';
import * as OrdersAPI from './orders';
import * as PnlDetailsAPI from './pnl-details';
Expand All @@ -25,6 +26,7 @@ export class Accounts extends APIResource {
pnlDetails: PnlDetailsAPI.PnlDetails = new PnlDetailsAPI.PnlDetails(this._client);
pnlSums: PnlSumsAPI.PnlSums = new PnlSumsAPI.PnlSums(this._client);
holdings: HoldingsAPI.Holdings = new HoldingsAPI.Holdings(this._client);
inventories: InventoriesAPI.Inventories = new InventoriesAPI.Inventories(this._client);

/**
* Get an account by its ID.
Expand Down Expand Up @@ -94,4 +96,6 @@ export namespace Accounts {
export import Holdings = HoldingsAPI.Holdings;
export import HoldingListResponse = HoldingsAPI.HoldingListResponse;
export import HoldingListParams = HoldingsAPI.HoldingListParams;
export import Inventories = InventoriesAPI.Inventories;
export import InventoryRetrieveResponse = InventoriesAPI.InventoryRetrieveResponse;
}
1 change: 1 addition & 0 deletions src/resources/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export { Account, AccountListResponse, Accounts } from './accounts';
export { BulkOrderCreateResponse, BulkOrderCreateParams, BulkOrders } from './bulk-orders';
export { EasyBorrowListResponse, EasyBorrows } from './easy-borrows';
export { HoldingListResponse, HoldingListParams, Holdings } from './holdings';
export { InventoryRetrieveResponse, Inventories } from './inventories';
export {
LocateOrderListResponse,
LocateOrderCreateParams,
Expand Down
46 changes: 46 additions & 0 deletions src/resources/accounts/inventories.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import { APIResource } from '../../resource';
import * as Core from '../../core';
import * as InventoriesAPI from './inventories';

export class Inventories extends APIResource {
/**
* Get located inventory for a symbol.
*/
retrieve(
accountId: string,
symbol: string,
options?: Core.RequestOptions,
): Core.APIPromise<InventoryRetrieveResponse> {
return this._client.get(`/accounts/${accountId}/inventories/${symbol}`, options);
}
}

export interface InventoryRetrieveResponse {
/**
* Account ID for the account.
*/
account_id?: string;

/**
* String representation of quantity.
*/
available?: string;

/**
* String representation of quantity.
*/
reserved?: string;

symbol?: string;

/**
* String representation of quantity.
*/
used?: string;
}

export namespace Inventories {
export import InventoryRetrieveResponse = InventoriesAPI.InventoryRetrieveResponse;
}
2 changes: 1 addition & 1 deletion src/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = '0.1.0-alpha.10'; // x-release-please-version
export const VERSION = '0.1.0-alpha.12'; // x-release-please-version
29 changes: 29 additions & 0 deletions tests/api-resources/accounts/inventories.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import StudioSDK from '@clear-street/studio-sdk';
import { Response } from 'node-fetch';

const client = new StudioSDK({
bearerToken: 'My Bearer Token',
baseURL: process.env['TEST_API_BASE_URL'] ?? 'http://127.0.0.1:4010',
});

describe('resource inventories', () => {
test('retrieve', async () => {
const responsePromise = client.accounts.inventories.retrieve('x', 'AAPL');
const rawResponse = await responsePromise.asResponse();
expect(rawResponse).toBeInstanceOf(Response);
const response = await responsePromise;
expect(response).not.toBeInstanceOf(Response);
const dataAndResponse = await responsePromise.withResponse();
expect(dataAndResponse.data).toBe(response);
expect(dataAndResponse.response).toBe(rawResponse);
});

test('retrieve: request options instead of params are passed correctly', async () => {
// ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error
await expect(
client.accounts.inventories.retrieve('x', 'AAPL', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(StudioSDK.NotFoundError);
});
});
33 changes: 33 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,39 @@ describe('retries', () => {
expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');
});

test('omit retry count header by default', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise<Response> => {
count++;
if (count <= 2) {
return new Response(undefined, {
status: 429,
headers: {
'Retry-After': '0.1',
},
});
}
capturedRequest = init;
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};
const client = new StudioSDK({
bearerToken: 'My Bearer Token',
fetch: testFetch,
maxRetries: 4,
defaultHeaders: { 'X-Stainless-Retry-Count': null },
});

expect(
await client.request({
path: '/foo',
method: 'get',
}),
).toEqual({ a: 1 });

expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');
});

test('overwrite retry count header', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
Expand Down
Loading

0 comments on commit c9fc3d7

Please sign in to comment.