-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaccounts-client.ts
39 lines (30 loc) · 1.16 KB
/
accounts-client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { Account } from '@morpheusnephew/td-ameritrade-models';
import Axios, { AxiosResponse } from 'axios';
import qs from 'qs';
import TdAmeritradeClient from '.';
import { queryStringOptions } from '../config';
import { getAccountUrl, getAllAccountsUrl, numberOrString } from '../urls';
export type Fields = 'positions' | 'orders';
export default class AccountsClient {
private _client: TdAmeritradeClient;
constructor(client: TdAmeritradeClient) {
this._client = client;
}
getAllAccounts = (fields?: Fields[]): Promise<AxiosResponse<Account[]>> => {
const queryString = qs.stringify({ fields }, queryStringOptions);
const url = `${getAllAccountsUrl()}${queryString}`;
return this._client._makeRequest(
async (authConfig) => await Axios.get<Account[]>(url, authConfig)
);
};
getAccount = (
accountId: numberOrString,
fields?: Fields[]
): Promise<AxiosResponse<Account>> => {
const queryString = qs.stringify({ fields }, queryStringOptions);
const url = `${getAccountUrl(accountId)}${queryString}`;
return this._client._makeRequest(
async (authConfig) => await Axios.get<Account>(url, authConfig)
);
};
}