Skip to content

Commit

Permalink
feat(api): add modify orders endpoint (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 29, 2024
1 parent 95bad5e commit 8e67f34
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 30
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/clear-street%2Fstudio-sdk-468b5da24bbf73b3a3861d44c5a8051fe6c55a6ec64c5c6f2d45f22c76bf35b2.yml
configured_endpoints: 31
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/clear-street%2Fstudio-sdk-5efb317738842339f6e8bd32592691a65d19a54adc34bfa319d6bac2404404a7.yml
1 change: 1 addition & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ Methods:
- <code title="get /accounts/{account_id}/orders">client.accounts.orders.<a href="./src/resources/accounts/orders.ts">list</a>(accountId, { ...params }) -> OrderListResponse</code>
- <code title="delete /accounts/{account_id}/orders">client.accounts.orders.<a href="./src/resources/accounts/orders.ts">delete</a>(accountId, { ...params }) -> OrderDeleteResponse</code>
- <code title="delete /accounts/{account_id}/orders/{order_id}">client.accounts.orders.<a href="./src/resources/accounts/orders.ts">cancel</a>(accountId, orderId) -> void</code>
- <code title="patch /accounts/{account_id}/orders/{order_id}">client.accounts.orders.<a href="./src/resources/accounts/orders.ts">patch</a>(accountId, orderId, { ...params }) -> void</code>

## Trades

Expand Down
2 changes: 2 additions & 0 deletions src/resources/accounts/accounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
OrderDeleteResponse,
OrderListParams,
OrderListResponse,
OrderPatchParams,
OrderRetrieveResponse,
Orders,
} from './orders';
Expand Down Expand Up @@ -115,6 +116,7 @@ export declare namespace Accounts {
type OrderCreateParams as OrderCreateParams,
type OrderListParams as OrderListParams,
type OrderDeleteParams as OrderDeleteParams,
type OrderPatchParams as OrderPatchParams,
};

export {
Expand Down
1 change: 1 addition & 0 deletions src/resources/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export {
type OrderCreateParams,
type OrderListParams,
type OrderDeleteParams,
type OrderPatchParams,
} from './orders';
export { PnlDetails, type PnlDetailListResponse } from './pnl-details';
export { PnlSummary } from './pnl-summary';
Expand Down
35 changes: 35 additions & 0 deletions src/resources/accounts/orders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ export class Orders extends APIResource {
headers: { Accept: '*/*', ...options?.headers },
});
}

/**
* Attempts to update an existing order. This can be used to update a subset of an
* order's attributes, for example price and quantity.
*/
patch(
accountId: string,
orderId: string,
body: OrderPatchParams,
options?: Core.RequestOptions,
): Core.APIPromise<void> {
return this._client.patch(`/accounts/${accountId}/orders/${orderId}`, {
body,
...options,
headers: { Accept: '*/*', ...options?.headers },
});
}
}

export interface OrderCreateResponse {
Expand Down Expand Up @@ -231,6 +248,23 @@ export interface OrderDeleteParams {
symbol_format?: 'cms' | 'osi';
}

export interface OrderPatchParams {
/**
* The maximum quantity to be executed.
*/
quantity: string;

/**
* The price to execute at-or-better for limit orders.
*/
price?: string;

/**
* The price at which stop orders become marketable.
*/
stop_price?: string;
}

export declare namespace Orders {
export {
type OrderCreateResponse as OrderCreateResponse,
Expand All @@ -240,5 +274,6 @@ export declare namespace Orders {
type OrderCreateParams as OrderCreateParams,
type OrderListParams as OrderListParams,
type OrderDeleteParams as OrderDeleteParams,
type OrderPatchParams as OrderPatchParams,
};
}
10 changes: 10 additions & 0 deletions src/resources/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@ export interface Order {
*/
quantity: string;

/**
* The position quantity at the time of this order.
*/
running_position: string;

/**
* Buy, sell, sell-short indicator.
*/
Expand Down Expand Up @@ -406,6 +411,11 @@ export interface Trade {
*/
quantity: string;

/**
* The position quantity at the time of this trade.
*/
running_position: string;

/**
* The side this trade occurred on.
*/
Expand Down
19 changes: 19 additions & 0 deletions tests/api-resources/accounts/orders.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,23 @@ describe('resource orders', () => {
client.accounts.orders.cancel('x', 'x', { path: '/_stainless_unknown_path' }),
).rejects.toThrow(StudioSDK.NotFoundError);
});

test('patch: only required params', async () => {
const responsePromise = client.accounts.orders.patch('x', 'x', { quantity: 'x' });
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('patch: required and optional params', async () => {
const response = await client.accounts.orders.patch('x', 'x', {
quantity: 'x',
price: 'x',
stop_price: 'x',
});
});
});

0 comments on commit 8e67f34

Please sign in to comment.