This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
407 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,208 @@ | ||
import type { | ||
Account, | ||
NonTradeActivities, | ||
TradingActivities, | ||
CancelablePromise, | ||
BaseHttpRequest, | ||
AccountConfigurations, | ||
PortfolioHistory, | ||
} from "../"; | ||
|
||
const activities = { | ||
/** | ||
* Get account activities of one type | ||
* Returns account activity entries for many types of activities. | ||
* @returns any returns an array of Account activities | ||
* @throws ApiError | ||
*/ | ||
get: ( | ||
httpRequest: BaseHttpRequest, | ||
{ | ||
activityTypes, | ||
}: { | ||
/** | ||
* A comma-separated list of the activity types to include in the response. If unspecified, activities of all types will be returned. (Cannot be used with category) | ||
*/ | ||
activityTypes?: "trade_activity" | "non_trade_activity"; | ||
} | ||
): CancelablePromise<Array<TradingActivities | NonTradeActivities>> => { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/account/activities", | ||
query: { | ||
activity_types: activityTypes, | ||
}, | ||
}); | ||
}, | ||
/** | ||
* Get account activities of one type | ||
* Returns account activity entries for a specific type of activity. | ||
* @returns any returns an array of Account activities | ||
* @throws ApiError | ||
*/ | ||
getByType: ( | ||
httpRequest: BaseHttpRequest, | ||
{ | ||
activityType, | ||
date, | ||
until, | ||
after, | ||
direction, | ||
pageSize, | ||
pageToken, | ||
category, | ||
}: { | ||
/** | ||
* The activity type you want to view entries for. A list of valid activity types can be found at the bottom of this page. | ||
*/ | ||
activityType: string; | ||
/** | ||
* The date for which you want to see activities. | ||
*/ | ||
date?: string; | ||
/** | ||
* The response will contain only activities submitted before this date. (Cannot be used with date.) | ||
*/ | ||
until?: string; | ||
/** | ||
* The response will contain only activities submitted after this date. (Cannot be used with date.) | ||
*/ | ||
after?: string; | ||
/** | ||
* asc or desc (default desc if unspecified.) | ||
*/ | ||
direction?: "asc" | "desc"; | ||
/** | ||
* The maximum number of entries to return in the response. (See the section on paging above.) | ||
*/ | ||
pageSize?: number; | ||
/** | ||
* The ID of the end of your current page of results. | ||
*/ | ||
pageToken?: string; | ||
/** | ||
* trade_activity or non_trade_activity, to specify the kind of results the server should return. (Cannot be used with /{activity_type} or ?activity_types=...) | ||
*/ | ||
category?: string; | ||
} | ||
): CancelablePromise<Array<TradingActivities | NonTradeActivities>> => { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/account/activities/{activity_type}", | ||
path: { | ||
activity_type: activityType, | ||
}, | ||
query: { | ||
date: date, | ||
until: until, | ||
after: after, | ||
direction: direction, | ||
page_size: pageSize, | ||
page_token: pageToken, | ||
category: category, | ||
}, | ||
}); | ||
}, | ||
}; | ||
|
||
/** | ||
* Get account | ||
* Returns the account associated with the API key. | ||
* @returns Account OK | ||
* @throws ApiError | ||
*/ | ||
function get(httpRequest: BaseHttpRequest): CancelablePromise<Account> { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/account", | ||
}); | ||
} | ||
|
||
/** | ||
* Account Portfolio History | ||
* Returns timeseries data about equity and profit/loss (P/L) of the account in requested timespan. | ||
* @returns PortfolioHistory Successful response | ||
* @throws ApiError | ||
*/ | ||
function portfolioHistory( | ||
httpRequest: BaseHttpRequest, | ||
{ | ||
period, | ||
timeframe, | ||
dateEnd, | ||
extendedHours, | ||
}: { | ||
/** | ||
* The duration of the data in <number> + <unit>, such as 1D, where <unit> can be D for day, W for week, M for month and A for year. Defaults to 1M. | ||
*/ | ||
period?: string; | ||
/** | ||
* The resolution of time window. 1Min, 5Min, 15Min, 1H, or 1D. If omitted, 1Min for less than 7 days period, 15Min for less than 30 days, or otherwise 1D. | ||
*/ | ||
timeframe?: string; | ||
/** | ||
* The date the data is returned up to, in “YYYY-MM-DD” format. Defaults to the current market date (rolls over at the market open if extended_hours is false, otherwise at 7am ET) | ||
*/ | ||
dateEnd?: string; | ||
/** | ||
* If true, include extended hours in the result. This is effective only for timeframe less than 1D. | ||
*/ | ||
extendedHours?: string; | ||
} | ||
): CancelablePromise<PortfolioHistory> { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/account/portfolio/history", | ||
query: { | ||
period: period, | ||
timeframe: timeframe, | ||
date_end: dateEnd, | ||
extended_hours: extendedHours, | ||
}, | ||
}); | ||
} | ||
|
||
const config = { | ||
/** | ||
* Account Configurations | ||
* gets the current account configuration values | ||
* @returns AccountConfigurations Successful response | ||
* @throws ApiError | ||
*/ | ||
get: ( | ||
httpRequest: BaseHttpRequest | ||
): CancelablePromise<AccountConfigurations> => { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/account/configurations", | ||
}); | ||
}, | ||
/** | ||
* Account Configurations | ||
* Updates and returns the current account configuration values | ||
* @returns AccountConfigurations Successful response | ||
* @throws ApiError | ||
*/ | ||
patch: ( | ||
httpRequest: BaseHttpRequest, | ||
{ | ||
requestBody, | ||
}: { | ||
requestBody?: AccountConfigurations; | ||
} | ||
): CancelablePromise<AccountConfigurations> => { | ||
return httpRequest.request({ | ||
method: "PATCH", | ||
url: "/v2/account/configurations", | ||
body: requestBody, | ||
mediaType: "application/json", | ||
}); | ||
}, | ||
}; | ||
|
||
export default { | ||
get, | ||
config, | ||
activities, | ||
portfolioHistory, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import type { Assets } from "../entities/Assets.js"; | ||
import type { CancelablePromise } from "../rest/CancelablePromise"; | ||
import { BaseHttpRequest } from "../rest/BaseHttpRequest"; | ||
|
||
/** | ||
* Get Assets | ||
* The assets API serves as the master list of assets available for trade and data consumption from Alpaca. Assets are sorted by asset class, exchange and symbol. | ||
* @returns Assets An array of asset objects | ||
* @throws ApiError | ||
*/ | ||
function get( | ||
httpRequest: BaseHttpRequest, | ||
{ | ||
status, | ||
assetClass, | ||
exchange, | ||
attributes, | ||
}: { | ||
/** | ||
* e.g. “active”. By default, all statuses are included. | ||
*/ | ||
status?: string; | ||
/** | ||
* Defaults to us_equity. | ||
*/ | ||
assetClass?: string; | ||
/** | ||
* Optional AMEX, ARCA, BATS, NYSE, NASDAQ, NYSEARCA or OTC | ||
*/ | ||
exchange?: string; | ||
/** | ||
* Comma separated values to query for more than one attribute. | ||
*/ | ||
attributes?: string; | ||
} | ||
): CancelablePromise<Array<Assets>> { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/assets", | ||
query: { | ||
status: status, | ||
asset_class: assetClass, | ||
exchange: exchange, | ||
attributes: attributes, | ||
}, | ||
}); | ||
} | ||
|
||
/** | ||
* Get an Asset by ID or Symbol | ||
* Get the asset model for a given symbol or asset_id. The symbol or asset_id should be passed in as a path parameter. | ||
* | ||
* **Note**: For crypto, the symbol has to follow old symbology, e.g. BTCUSD. | ||
* | ||
* **Note**: For coin pairs, the symbol should be separated by spare symbol (/), e.g. BTC/USDT. Since spare is a special character in HTTP, use the URL encoded version instead, e.g. /v2/assets/BTC%2FUSDT | ||
* @returns Assets An Asset object | ||
* @throws ApiError | ||
*/ | ||
function getBySymbolOrAssetId( | ||
httpRequest: BaseHttpRequest, | ||
{ | ||
symbolOrAssetId, | ||
}: { | ||
/** | ||
* symbol or assetId | ||
*/ | ||
symbolOrAssetId: string; | ||
} | ||
): CancelablePromise<Assets> { | ||
return httpRequest.request({ | ||
method: "GET", | ||
url: "/v2/assets/{symbol_or_asset_id}", | ||
path: { | ||
symbol_or_asset_id: symbolOrAssetId, | ||
}, | ||
errors: { | ||
404: `Not Found`, | ||
}, | ||
}); | ||
} | ||
|
||
export default { | ||
get, | ||
getBySymbolOrAssetId, | ||
}; |
Oops, something went wrong.