-
Notifications
You must be signed in to change notification settings - Fork 15
/
AccountAPI.ts
244 lines (217 loc) · 5.75 KB
/
AccountAPI.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
import {AxiosInstance} from 'axios';
import {Direction} from '../dealing/DealingAPI';
export enum AccountStatus {
DISABLED = 'DISABLED',
ENABLED = 'ENABLED',
SUSPENDED_FROM_DEALING = 'SUSPENDED_FROM_DEALING',
}
export enum AccountType {
CFD = 'CFD',
PHYSICAL = 'PHYSICAL',
SPREADBET = 'SPREADBET',
}
export enum TransactionType {
ALL = 'ALL',
ALL_DEAL = 'ALL_DEAL',
DEPOSIT = 'DEPOSIT',
WITHDRAWAL = 'WITHDRAWAL',
}
export enum Channel {
DEALER = 'DEALER',
MOBILE = 'MOBILE',
PUBLIC_FIX_API = 'PUBLIC_FIX_API',
PUBLIC_WEB_API = 'PUBLIC_WEB_API',
SYSTEM = 'SYSTEM',
WEB = 'WEB',
}
export enum ActionType {
LIMIT_ORDER_AMENDED = 'LIMIT_ORDER_AMENDED',
LIMIT_ORDER_DELETED = 'LIMIT_ORDER_DELETED',
LIMIT_ORDER_FILLED = 'LIMIT_ORDER_FILLED',
LIMIT_ORDER_OPENED = 'LIMIT_ORDER_OPENED',
LIMIT_ORDER_ROLLED = 'LIMIT_ORDER_ROLLED',
POSITION_CLOSED = 'POSITION_CLOSED',
POSITION_DELETED = 'POSITION_DELETED',
POSITION_OPENED = 'POSITION_OPENED',
POSITION_PARTIALLY_CLOSED = 'POSITION_PARTIALLY_CLOSED',
POSITION_ROLLED = 'POSITION_ROLLED',
STOP_LIMIT_AMENDED = 'STOP_LIMIT_AMENDED',
STOP_ORDER_AMENDED = 'STOP_ORDER_AMENDED',
STOP_ORDER_DELETED = 'STOP_ORDER_DELETED',
STOP_ORDER_FILLED = 'STOP_ORDER_FILLED',
STOP_ORDER_OPENED = 'STOP_ORDER_OPENED',
STOP_ORDER_ROLLED = 'STOP_ORDER_ROLLED',
UNKNOWN = 'UNKNOWN',
WORKING_ORDER_DELETED = 'WORKING_ORDER_DELETED',
}
export enum ActivityStatus {
ACCEPTED = 'ACCEPTED',
REJECTED = 'REJECTED',
UNKNOWN = 'UNKNOWN',
}
export enum ActivityType {
EDIT_STOP_AND_LIMIT = 'EDIT_STOP_AND_LIMIT',
POSITION = 'POSITION',
SYSTEM = 'SYSTEM',
WORKING_ORDER = 'WORKING_ORDER',
}
export interface Balance {
available: number;
balance: number;
deposit: number;
profitLoss: number;
}
export interface Account {
accountAlias?: any;
accountId: string;
accountName: string;
accountType: AccountType;
balance: Balance;
canTransferFrom: boolean;
canTransferTo: boolean;
currency: string;
preferred: boolean;
status: AccountStatus;
}
export interface AccountsResponse {
accounts: Account[];
}
export interface Action {
actionType: ActionType;
affectedDealId: string;
}
export interface Details {
actions: Action[];
currency: string;
dealReference: string;
direction: Direction;
goodTillDate: string;
guaranteedStop: boolean;
level: number;
limitDistance?: number;
limitLevel?: number;
marketName: string;
size: number;
stopDistance?: any;
stopLevel?: any;
trailingStep?: any;
trailingStopDistance?: any;
}
export interface Activity {
channel: Channel;
date: Date;
dealId: string;
description: string;
details?: Details;
epic: string;
period: string;
status: ActivityStatus;
type: ActivityType;
}
export interface ActivityPaging {
next: string;
size: number;
}
export interface ActivityMetadata {
paging: ActivityPaging;
}
export interface ActivityHistoryRequest {
dealId?: string;
detailed?: boolean;
filter?: string;
from?: string;
pageSize?: number;
to?: string;
}
export interface ActivityHistoryResponse {
activities: Activity[];
metadata: ActivityMetadata;
}
export interface Transaction {
cashTransaction: boolean;
closeLevel: string;
currency: string;
date: string;
dateUtc: Date;
instrumentName: string;
openDateUtc: Date;
openLevel: string;
period: string;
profitAndLoss: string;
reference: string;
size: string;
transactionType: string;
}
export interface TransactionPaging {
pageNumber: number;
pageSize: number;
totalPages: number;
}
export interface TransactionMetadata {
pageData: TransactionPaging;
size: number;
}
export interface TransactionHistoryRequest {
from?: string;
maxSpanSeconds?: number;
pageNumber?: number;
pageSize?: number;
to?: string;
type?: TransactionType;
}
export interface TransactionHistoryResponse {
metadata: TransactionMetadata;
transactions: Transaction[];
}
export class AccountAPI {
static readonly URL = {
ACCOUNTS: '/accounts/',
HISTORY_ACTIVITY: '/history/activity/',
HISTORY_TRANSACTIONS: '/history/transactions',
};
constructor(private readonly apiClient: AxiosInstance) {}
/**
* Returns a list of accounts belonging to the logged-in client.
*
* @see https://labs.ig.com/rest-trading-api-reference/service-detail?id=553
*/
async getAccounts(): Promise<AccountsResponse> {
const resource = AccountAPI.URL.ACCOUNTS;
const response = await this.apiClient.get<AccountsResponse>(resource);
return response.data;
}
/**
* Returns the account activity history. The first element in the array is the latest activity. The last element is the oldest activity.
*
* @param PositionCreateRequest - The Information to create the Position
* @see https://labs.ig.com/rest-trading-api-reference/service-detail?id=543
*/
async getActivityHistory(activityHistoryRequest: ActivityHistoryRequest): Promise<ActivityHistoryResponse> {
const resource = AccountAPI.URL.HISTORY_ACTIVITY;
const response = await this.apiClient.get<ActivityHistoryResponse>(resource, {
headers: {
VERSION: '3',
},
params: activityHistoryRequest,
});
return response.data;
}
/**
* Returns the account transaction history.
*
* @param PositionCreateRequest - The Information to create the Position
* @see https://labs.ig.com/rest-trading-api-reference/service-detail?id=525
*/
async getTransactionHistory(
transactionHistoryRequest: TransactionHistoryRequest
): Promise<TransactionHistoryResponse> {
const resource = AccountAPI.URL.HISTORY_TRANSACTIONS;
const response = await this.apiClient.get<TransactionHistoryResponse>(resource, {
headers: {
VERSION: '2',
},
params: transactionHistoryRequest,
});
return response.data;
}
}