ctrader-ts 0.1.11 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +259 -91
- package/dist/bin/auth.js +8 -8
- package/dist/bin/auth.js.map +1 -1
- package/dist/cli/index.js +169 -26
- package/dist/cli/index.js.map +1 -1
- package/dist/src/{client.d.ts → core/client.d.ts} +57 -15
- package/dist/src/core/client.d.ts.map +1 -0
- package/dist/src/{client.js → core/client.js} +306 -49
- package/dist/src/core/client.js.map +1 -0
- package/dist/src/core/config.d.ts.map +1 -0
- package/dist/src/{config.js → core/config.js} +13 -13
- package/dist/src/core/config.js.map +1 -0
- package/dist/src/{connect.d.ts → core/connect.d.ts} +3 -3
- package/dist/src/core/connect.d.ts.map +1 -0
- package/dist/src/{connect.js → core/connect.js} +4 -6
- package/dist/src/core/connect.js.map +1 -0
- package/dist/src/{connection.d.ts → core/connection.d.ts} +48 -4
- package/dist/src/core/connection.d.ts.map +1 -0
- package/dist/src/{connection.js → core/connection.js} +70 -14
- package/dist/src/core/connection.js.map +1 -0
- package/dist/src/{errors.d.ts → core/errors.d.ts} +5 -0
- package/dist/src/core/errors.d.ts.map +1 -0
- package/dist/src/core/errors.js +85 -0
- package/dist/src/core/errors.js.map +1 -0
- package/dist/src/{helpers.d.ts → core/helpers.d.ts} +3 -3
- package/dist/src/core/helpers.d.ts.map +1 -0
- package/dist/src/{helpers.js → core/helpers.js} +9 -7
- package/dist/src/core/helpers.js.map +1 -0
- package/dist/src/{symbol-cache.d.ts → core/symbol-cache.d.ts} +2 -2
- package/dist/src/core/symbol-cache.d.ts.map +1 -0
- package/dist/src/core/symbol-cache.js.map +1 -0
- package/dist/src/index.d.ts +26 -11
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +24 -9
- package/dist/src/index.js.map +1 -1
- package/dist/src/modules/account.d.ts +68 -2
- package/dist/src/modules/account.d.ts.map +1 -1
- package/dist/src/modules/account.js +91 -34
- package/dist/src/modules/account.js.map +1 -1
- package/dist/src/modules/auth.d.ts +29 -2
- package/dist/src/modules/auth.d.ts.map +1 -1
- package/dist/src/modules/auth.js +42 -10
- package/dist/src/modules/auth.js.map +1 -1
- package/dist/src/modules/market.d.ts +51 -3
- package/dist/src/modules/market.d.ts.map +1 -1
- package/dist/src/modules/market.js +57 -16
- package/dist/src/modules/market.js.map +1 -1
- package/dist/src/modules/trading.d.ts +69 -3
- package/dist/src/modules/trading.d.ts.map +1 -1
- package/dist/src/modules/trading.js +74 -35
- package/dist/src/modules/trading.js.map +1 -1
- package/dist/src/protocol/codec.d.ts.map +1 -0
- package/dist/src/{codec.js → protocol/codec.js} +2 -2
- package/dist/src/protocol/codec.js.map +1 -0
- package/dist/src/{enums.d.ts → protocol/enums.d.ts} +177 -0
- package/dist/src/protocol/enums.d.ts.map +1 -0
- package/dist/src/{enums.js → protocol/enums.js} +177 -0
- package/dist/src/protocol/enums.js.map +1 -0
- package/dist/src/protocol/proto/messages.d.ts +7496 -0
- package/dist/src/protocol/proto/messages.js +21525 -0
- package/dist/src/protocol/proto/proto/messages.d.ts +7496 -0
- package/dist/src/protocol/proto/proto/messages.js +21525 -0
- package/dist/src/{types.d.ts → protocol/types.d.ts} +151 -3
- package/dist/src/protocol/types.d.ts.map +1 -0
- package/dist/src/{types.js.map → protocol/types.js.map} +1 -1
- package/llms.txt +280 -0
- package/package.json +89 -61
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/client.js.map +0 -1
- package/dist/src/codec.d.ts.map +0 -1
- package/dist/src/codec.js.map +0 -1
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js.map +0 -1
- package/dist/src/connect.d.ts.map +0 -1
- package/dist/src/connect.js.map +0 -1
- package/dist/src/connection.d.ts.map +0 -1
- package/dist/src/connection.js.map +0 -1
- package/dist/src/enums.d.ts.map +0 -1
- package/dist/src/enums.js.map +0 -1
- package/dist/src/errors.d.ts.map +0 -1
- package/dist/src/errors.js +0 -47
- package/dist/src/errors.js.map +0 -1
- package/dist/src/helpers.d.ts.map +0 -1
- package/dist/src/helpers.js.map +0 -1
- package/dist/src/proto/messages.d.ts +0 -7076
- package/dist/src/proto/messages.js +0 -23289
- package/dist/src/proto/proto/messages.d.ts +0 -7076
- package/dist/src/proto/proto/messages.js +0 -23289
- package/dist/src/symbol-cache.d.ts.map +0 -1
- package/dist/src/symbol-cache.js.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- /package/dist/src/{config.d.ts → core/config.d.ts} +0 -0
- /package/dist/src/{symbol-cache.js → core/symbol-cache.js} +0 -0
- /package/dist/src/{codec.d.ts → protocol/codec.d.ts} +0 -0
- /package/dist/src/{types.js → protocol/types.js} +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { CTraderConnection } from "../connection.js";
|
|
2
|
-
import { QuoteType, TrendbarPeriod } from "../enums.js";
|
|
3
|
-
import type { ArchivedSymbol, Asset, AssetClass, DepthEvent, FullSymbol, LightSymbol, SpotEvent, SymbolCategory, SymbolChangedEvent, TickData, Trendbar } from "../types.js";
|
|
1
|
+
import type { CTraderConnection } from "../core/connection.js";
|
|
2
|
+
import { type QuoteType, TrendbarPeriod } from "../protocol/enums.js";
|
|
3
|
+
import type { ArchivedSymbol, Asset, AssetClass, DepthEvent, FullSymbol, LightSymbol, SpotEvent, SymbolCategory, SymbolChangedEvent, TickData, Trendbar } from "../protocol/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for historical candlestick data request
|
|
6
|
+
*/
|
|
4
7
|
export interface GetTrendbarsParams {
|
|
5
8
|
symbolId: number;
|
|
6
9
|
period: TrendbarPeriod;
|
|
@@ -8,12 +11,18 @@ export interface GetTrendbarsParams {
|
|
|
8
11
|
toTimestamp?: number;
|
|
9
12
|
count?: number;
|
|
10
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* Parameters for historical tick data request
|
|
16
|
+
*/
|
|
11
17
|
export interface GetTickDataParams {
|
|
12
18
|
symbolId: number;
|
|
13
19
|
type: QuoteType;
|
|
14
20
|
fromTimestamp?: number;
|
|
15
21
|
toTimestamp?: number;
|
|
16
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Low-level market data operations — symbols, spot prices, trendbars, depth. Use CTrader (client.ts) for the high-level API.
|
|
25
|
+
*/
|
|
17
26
|
export declare class CTraderMarket {
|
|
18
27
|
private readonly connection;
|
|
19
28
|
private accountId;
|
|
@@ -24,29 +33,68 @@ export declare class CTraderMarket {
|
|
|
24
33
|
setAccountId(accountId: number): void;
|
|
25
34
|
getAssets(): Promise<Asset[]>;
|
|
26
35
|
getAssetClasses(): Promise<AssetClass[]>;
|
|
36
|
+
/**
|
|
37
|
+
* Get list of symbols, optionally including archived ones
|
|
38
|
+
*/
|
|
27
39
|
getSymbols(includeArchived?: boolean): Promise<{
|
|
28
40
|
symbols: LightSymbol[];
|
|
29
41
|
archivedSymbols: ArchivedSymbol[];
|
|
30
42
|
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Get full symbol info by IDs
|
|
45
|
+
*/
|
|
31
46
|
getSymbolsById(symbolIds: number[]): Promise<FullSymbol[]>;
|
|
32
47
|
getSymbolCategories(): Promise<SymbolCategory[]>;
|
|
33
48
|
getSymbolsForConversion(firstAssetId: number, lastAssetId: number): Promise<LightSymbol[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Subscribe to live spot prices
|
|
51
|
+
*/
|
|
34
52
|
subscribeSpots(symbolIds: number[], subscribeToSpotTimestamp?: boolean): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Unsubscribe from spot prices
|
|
55
|
+
*/
|
|
35
56
|
unsubscribeSpots(symbolIds: number[]): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Subscribe to live trendbar updates
|
|
59
|
+
*/
|
|
36
60
|
subscribeLiveTrendbar(symbolId: number, period: TrendbarPeriod): Promise<void>;
|
|
61
|
+
/**
|
|
62
|
+
* Unsubscribe from live trendbar updates
|
|
63
|
+
*/
|
|
37
64
|
unsubscribeLiveTrendbar(symbolId: number, period: TrendbarPeriod): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Subscribe to market depth
|
|
67
|
+
*/
|
|
38
68
|
subscribeDepth(symbolIds: number[]): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* Unsubscribe from market depth
|
|
71
|
+
*/
|
|
39
72
|
unsubscribeDepth(symbolIds: number[]): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Get historical trendbar/candle data
|
|
75
|
+
*/
|
|
40
76
|
getTrendbars(params: GetTrendbarsParams): Promise<{
|
|
41
77
|
trendbars: Trendbar[];
|
|
42
78
|
hasMore: boolean;
|
|
43
79
|
}>;
|
|
80
|
+
/**
|
|
81
|
+
* Get historical tick data
|
|
82
|
+
*/
|
|
44
83
|
getTickData(params: GetTickDataParams): Promise<{
|
|
45
84
|
ticks: TickData[];
|
|
46
85
|
hasMore: boolean;
|
|
47
86
|
}>;
|
|
87
|
+
/**
|
|
88
|
+
* Subscribe to spot price events
|
|
89
|
+
*/
|
|
48
90
|
onSpot(handler: (event: SpotEvent) => void): () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe to market depth events
|
|
93
|
+
*/
|
|
49
94
|
onDepth(handler: (event: DepthEvent) => void): () => void;
|
|
95
|
+
/**
|
|
96
|
+
* Subscribe to symbol change events
|
|
97
|
+
*/
|
|
50
98
|
onSymbolChanged(handler: (event: SymbolChangedEvent) => void): () => void;
|
|
51
99
|
restoreSubscriptions(): Promise<void>;
|
|
52
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/modules/market.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"market.d.ts","sourceRoot":"","sources":["../../../src/modules/market.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/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IAAI;IAMvD;;OAEG;IAEH,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,GAAG,MAAM,IAAI;IAMzD;;OAEG;IAEH,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,IAAI;IAMnE,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;CAuB3C"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PayloadType, TrendbarPeriod } from "../enums.js";
|
|
1
|
+
import { PayloadType, TrendbarPeriod } from "../protocol/enums.js";
|
|
2
2
|
/** Approximate milliseconds per trendbar period (used for fromTimestamp default). */
|
|
3
3
|
function periodMs(period) {
|
|
4
4
|
switch (period) {
|
|
@@ -34,6 +34,9 @@ function periodMs(period) {
|
|
|
34
34
|
return 3_600_000;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Low-level market data operations — symbols, spot prices, trendbars, depth. Use CTrader (client.ts) for the high-level API.
|
|
39
|
+
*/
|
|
37
40
|
export class CTraderMarket {
|
|
38
41
|
connection;
|
|
39
42
|
accountId;
|
|
@@ -51,36 +54,42 @@ export class CTraderMarket {
|
|
|
51
54
|
const res = await this.connection.request(PayloadType.ASSET_LIST_REQ, {
|
|
52
55
|
ctidTraderAccountId: this.accountId,
|
|
53
56
|
});
|
|
54
|
-
return res
|
|
57
|
+
return res.asset ?? [];
|
|
55
58
|
}
|
|
56
59
|
async getAssetClasses() {
|
|
57
60
|
const res = await this.connection.request(PayloadType.ASSET_CLASS_LIST_REQ, {
|
|
58
61
|
ctidTraderAccountId: this.accountId,
|
|
59
62
|
});
|
|
60
|
-
return res
|
|
63
|
+
return res.assetClass ?? [];
|
|
61
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Get list of symbols, optionally including archived ones
|
|
67
|
+
*/
|
|
62
68
|
async getSymbols(includeArchived = false) {
|
|
63
69
|
const res = await this.connection.request(PayloadType.SYMBOLS_LIST_REQ, {
|
|
64
70
|
ctidTraderAccountId: this.accountId,
|
|
65
71
|
includeArchivedSymbols: includeArchived,
|
|
66
72
|
});
|
|
67
73
|
return {
|
|
68
|
-
symbols: res
|
|
69
|
-
archivedSymbols: res
|
|
74
|
+
symbols: res.symbol ?? [],
|
|
75
|
+
archivedSymbols: res.archivedSymbol ?? [],
|
|
70
76
|
};
|
|
71
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Get full symbol info by IDs
|
|
80
|
+
*/
|
|
72
81
|
async getSymbolsById(symbolIds) {
|
|
73
82
|
const res = await this.connection.request(PayloadType.SYMBOL_BY_ID_REQ, {
|
|
74
83
|
ctidTraderAccountId: this.accountId,
|
|
75
84
|
symbolId: symbolIds,
|
|
76
85
|
});
|
|
77
|
-
return res
|
|
86
|
+
return res.symbol ?? [];
|
|
78
87
|
}
|
|
79
88
|
async getSymbolCategories() {
|
|
80
89
|
const res = await this.connection.request(PayloadType.SYMBOL_CATEGORY_LIST_REQ, {
|
|
81
90
|
ctidTraderAccountId: this.accountId,
|
|
82
91
|
});
|
|
83
|
-
return res
|
|
92
|
+
return res.symbolCategory ?? [];
|
|
84
93
|
}
|
|
85
94
|
async getSymbolsForConversion(firstAssetId, lastAssetId) {
|
|
86
95
|
const res = await this.connection.request(PayloadType.SYMBOLS_FOR_CONVERSION_REQ, {
|
|
@@ -88,19 +97,25 @@ export class CTraderMarket {
|
|
|
88
97
|
firstAssetId,
|
|
89
98
|
lastAssetId,
|
|
90
99
|
});
|
|
91
|
-
return res
|
|
100
|
+
return res.symbol ?? [];
|
|
92
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Subscribe to live spot prices
|
|
104
|
+
*/
|
|
93
105
|
async subscribeSpots(symbolIds, subscribeToSpotTimestamp) {
|
|
94
106
|
const payload = {
|
|
95
107
|
ctidTraderAccountId: this.accountId,
|
|
96
108
|
symbolId: symbolIds,
|
|
97
109
|
};
|
|
98
110
|
if (subscribeToSpotTimestamp !== undefined)
|
|
99
|
-
payload
|
|
111
|
+
payload.subscribeToSpotTimestamp = subscribeToSpotTimestamp;
|
|
100
112
|
await this.connection.request(PayloadType.SUBSCRIBE_SPOTS_REQ, payload);
|
|
101
113
|
for (const id of symbolIds)
|
|
102
114
|
this.activeSpotSubscriptions.add(id);
|
|
103
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Unsubscribe from spot prices
|
|
118
|
+
*/
|
|
104
119
|
async unsubscribeSpots(symbolIds) {
|
|
105
120
|
await this.connection.request(PayloadType.UNSUBSCRIBE_SPOTS_REQ, {
|
|
106
121
|
ctidTraderAccountId: this.accountId,
|
|
@@ -109,6 +124,9 @@ export class CTraderMarket {
|
|
|
109
124
|
for (const id of symbolIds)
|
|
110
125
|
this.activeSpotSubscriptions.delete(id);
|
|
111
126
|
}
|
|
127
|
+
/**
|
|
128
|
+
* Subscribe to live trendbar updates
|
|
129
|
+
*/
|
|
112
130
|
async subscribeLiveTrendbar(symbolId, period) {
|
|
113
131
|
await this.connection.request(PayloadType.SUBSCRIBE_LIVE_TRENDBAR_REQ, {
|
|
114
132
|
ctidTraderAccountId: this.accountId,
|
|
@@ -122,6 +140,9 @@ export class CTraderMarket {
|
|
|
122
140
|
}
|
|
123
141
|
periods.add(period);
|
|
124
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Unsubscribe from live trendbar updates
|
|
145
|
+
*/
|
|
125
146
|
async unsubscribeLiveTrendbar(symbolId, period) {
|
|
126
147
|
await this.connection.request(PayloadType.UNSUBSCRIBE_LIVE_TRENDBAR_REQ, {
|
|
127
148
|
ctidTraderAccountId: this.accountId,
|
|
@@ -135,6 +156,9 @@ export class CTraderMarket {
|
|
|
135
156
|
this.activeTrendbarSubscriptions.delete(symbolId);
|
|
136
157
|
}
|
|
137
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Subscribe to market depth
|
|
161
|
+
*/
|
|
138
162
|
async subscribeDepth(symbolIds) {
|
|
139
163
|
await this.connection.request(PayloadType.SUBSCRIBE_DEPTH_REQ, {
|
|
140
164
|
ctidTraderAccountId: this.accountId,
|
|
@@ -143,6 +167,9 @@ export class CTraderMarket {
|
|
|
143
167
|
for (const id of symbolIds)
|
|
144
168
|
this.activeDepthSubscriptions.add(id);
|
|
145
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Unsubscribe from market depth
|
|
172
|
+
*/
|
|
146
173
|
async unsubscribeDepth(symbolIds) {
|
|
147
174
|
await this.connection.request(PayloadType.UNSUBSCRIBE_DEPTH_REQ, {
|
|
148
175
|
ctidTraderAccountId: this.accountId,
|
|
@@ -151,10 +178,12 @@ export class CTraderMarket {
|
|
|
151
178
|
for (const id of symbolIds)
|
|
152
179
|
this.activeDepthSubscriptions.delete(id);
|
|
153
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Get historical trendbar/candle data
|
|
183
|
+
*/
|
|
154
184
|
async getTrendbars(params) {
|
|
155
185
|
const toTimestamp = params.toTimestamp ?? Date.now();
|
|
156
|
-
const fromTimestamp = params.fromTimestamp ??
|
|
157
|
-
toTimestamp - periodMs(params.period) * (params.count ?? 300) * 1.5;
|
|
186
|
+
const fromTimestamp = params.fromTimestamp ?? toTimestamp - periodMs(params.period) * (params.count ?? 300) * 1.5;
|
|
158
187
|
const payload = {
|
|
159
188
|
ctidTraderAccountId: this.accountId,
|
|
160
189
|
symbolId: params.symbolId,
|
|
@@ -163,13 +192,16 @@ export class CTraderMarket {
|
|
|
163
192
|
toTimestamp,
|
|
164
193
|
};
|
|
165
194
|
if (params.count !== undefined)
|
|
166
|
-
payload
|
|
195
|
+
payload.count = params.count;
|
|
167
196
|
const res = await this.connection.request(PayloadType.GET_TRENDBARS_REQ, payload);
|
|
168
197
|
return {
|
|
169
|
-
trendbars: res
|
|
170
|
-
hasMore: res
|
|
198
|
+
trendbars: res.trendbar ?? [],
|
|
199
|
+
hasMore: res.hasMore ?? false,
|
|
171
200
|
};
|
|
172
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Get historical tick data
|
|
204
|
+
*/
|
|
173
205
|
async getTickData(params) {
|
|
174
206
|
const toTimestamp = params.toTimestamp ?? Date.now();
|
|
175
207
|
const fromTimestamp = params.fromTimestamp ?? toTimestamp - 3_600_000; // default 1 hour
|
|
@@ -182,20 +214,29 @@ export class CTraderMarket {
|
|
|
182
214
|
};
|
|
183
215
|
const res = await this.connection.request(PayloadType.GET_TICK_DATA_REQ, payload);
|
|
184
216
|
return {
|
|
185
|
-
ticks: res
|
|
186
|
-
hasMore: res
|
|
217
|
+
ticks: res.tickData ?? [],
|
|
218
|
+
hasMore: res.hasMore ?? false,
|
|
187
219
|
};
|
|
188
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Subscribe to spot price events
|
|
223
|
+
*/
|
|
189
224
|
onSpot(handler) {
|
|
190
225
|
return this.connection.on(PayloadType.SPOT_EVENT, (payload) => {
|
|
191
226
|
handler(payload);
|
|
192
227
|
});
|
|
193
228
|
}
|
|
229
|
+
/**
|
|
230
|
+
* Subscribe to market depth events
|
|
231
|
+
*/
|
|
194
232
|
onDepth(handler) {
|
|
195
233
|
return this.connection.on(PayloadType.DEPTH_EVENT, (payload) => {
|
|
196
234
|
handler(payload);
|
|
197
235
|
});
|
|
198
236
|
}
|
|
237
|
+
/**
|
|
238
|
+
* Subscribe to symbol change events
|
|
239
|
+
*/
|
|
199
240
|
onSymbolChanged(handler) {
|
|
200
241
|
return this.connection.on(PayloadType.SYMBOL_CHANGED_EVENT, (payload) => {
|
|
201
242
|
handler(payload);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/modules/market.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"market.js","sourceRoot":"","sources":["../../../src/modules/market.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAkB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAoCnF,qFAAqF;AACrF,SAAS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AC,OAA4C;QAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,oBAAoB,EAAE,CAAC,OAAO,EAAE,EAAE;YACvE,OAAO,CAAC,OAAwC,CAAC,CAAC;QACnD,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,oBAAoB;QACzB,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE;gBAC9D,mBAAmB,EAAE,IAAI,CAAC,SAAS;gBACnC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,uBAAuB,CAAC;aAC3C,CAAC,CAAC;QACJ,CAAC;QACD,KAAK,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,2BAA2B,EAAE,CAAC;YACpE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC9B,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,2BAA2B,EAAE;oBACtE,mBAAmB,EAAE,IAAI,CAAC,SAAS;oBACnC,QAAQ;oBACR,MAAM;iBACN,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;QACD,IAAI,IAAI,CAAC,wBAAwB,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,mBAAmB,EAAE;gBAC9D,mBAAmB,EAAE,IAAI,CAAC,SAAS;gBACnC,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC;aAC5C,CAAC,CAAC;QACJ,CAAC;IACF,CAAC;CACD"}
|
|
@@ -1,42 +1,66 @@
|
|
|
1
|
-
import type { CTraderConnection } from "../connection.js";
|
|
2
|
-
import { OrderTriggerMethod, TimeInForce, TradeSide } from "../enums.js";
|
|
3
|
-
import type { ExecutionEvent, OrderErrorEvent, TrailingSLChangedEvent } from "../types.js";
|
|
1
|
+
import type { CTraderConnection } from "../core/connection.js";
|
|
2
|
+
import { type OrderTriggerMethod, type TimeInForce, type TradeSide } from "../protocol/enums.js";
|
|
3
|
+
import type { ExecutionEvent, OrderErrorEvent, TrailingSLChangedEvent } from "../protocol/types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Parameters for creating a new order via the cTrader protocol. Volume is in protocol units (1 lot = 100,000).
|
|
6
|
+
*/
|
|
4
7
|
export interface NewOrderParams {
|
|
8
|
+
/** Numeric symbol identifier */
|
|
5
9
|
symbolId: number;
|
|
10
|
+
/** BUY or SELL */
|
|
6
11
|
tradeSide: TradeSide;
|
|
12
|
+
/** Volume in protocol units (1 lot = 100,000 units). Use lotsToUnits() to convert. */
|
|
7
13
|
volume: number;
|
|
8
14
|
label?: string;
|
|
9
15
|
comment?: string;
|
|
10
16
|
clientOrderId?: string;
|
|
17
|
+
/** Existing position ID — set this to add volume to an existing position */
|
|
11
18
|
positionId?: number;
|
|
12
19
|
stopLoss?: number;
|
|
13
20
|
takeProfit?: number;
|
|
21
|
+
/** Relative SL/TP distance in protocol units (use resolveSlTp helper for human-friendly conversion) */
|
|
14
22
|
relativeStopLoss?: number;
|
|
23
|
+
/** Relative SL/TP distance in protocol units (use resolveSlTp helper for human-friendly conversion) */
|
|
15
24
|
relativeTakeProfit?: number;
|
|
16
25
|
guaranteedStopLoss?: boolean;
|
|
17
26
|
trailingStopLoss?: boolean;
|
|
18
27
|
stopTriggerMethod?: OrderTriggerMethod;
|
|
19
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* Parameters for a limit order (fill at price or better)
|
|
31
|
+
*/
|
|
20
32
|
export interface LimitOrderParams extends NewOrderParams {
|
|
21
33
|
limitPrice: number;
|
|
22
34
|
timeInForce?: TimeInForce;
|
|
23
35
|
expirationTimestamp?: number;
|
|
24
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Parameters for a stop order (triggers at price)
|
|
39
|
+
*/
|
|
25
40
|
export interface StopOrderParams extends NewOrderParams {
|
|
26
41
|
stopPrice: number;
|
|
27
42
|
timeInForce?: TimeInForce;
|
|
28
43
|
expirationTimestamp?: number;
|
|
29
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Parameters for a market range order (market with slippage control)
|
|
47
|
+
*/
|
|
30
48
|
export interface MarketRangeOrderParams extends NewOrderParams {
|
|
31
49
|
baseSlippagePrice: number;
|
|
32
50
|
slippageInPoints: number;
|
|
33
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Parameters for a stop-limit order (stop trigger → limit order)
|
|
54
|
+
*/
|
|
34
55
|
export interface StopLimitOrderParams extends NewOrderParams {
|
|
35
56
|
stopPrice: number;
|
|
36
57
|
slippageInPoints: number;
|
|
37
58
|
timeInForce?: TimeInForce;
|
|
38
59
|
expirationTimestamp?: number;
|
|
39
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* Fields to modify on an existing pending order. Only set the fields you want to change.
|
|
63
|
+
*/
|
|
40
64
|
export interface AmendOrderParams {
|
|
41
65
|
volume?: number;
|
|
42
66
|
limitPrice?: number;
|
|
@@ -51,6 +75,9 @@ export interface AmendOrderParams {
|
|
|
51
75
|
trailingStopLoss?: boolean;
|
|
52
76
|
stopTriggerMethod?: OrderTriggerMethod;
|
|
53
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Fields to modify SL/TP on an open position
|
|
80
|
+
*/
|
|
54
81
|
export interface AmendSltpParams {
|
|
55
82
|
stopLoss?: number;
|
|
56
83
|
takeProfit?: number;
|
|
@@ -58,22 +85,61 @@ export interface AmendSltpParams {
|
|
|
58
85
|
trailingStopLoss?: boolean;
|
|
59
86
|
stopLossTriggerMethod?: OrderTriggerMethod;
|
|
60
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Low-level trading operations — direct protocol wrappers for order management. Use CTrader (client.ts) for the high-level API with human-friendly units.
|
|
90
|
+
*/
|
|
61
91
|
export declare class CTraderTrading {
|
|
62
92
|
private readonly connection;
|
|
63
93
|
private accountId;
|
|
64
94
|
constructor(connection: CTraderConnection, accountId: number);
|
|
65
95
|
setAccountId(accountId: number): void;
|
|
96
|
+
/**
|
|
97
|
+
* Execute a market order
|
|
98
|
+
*/
|
|
66
99
|
marketOrder(params: NewOrderParams): Promise<ExecutionEvent>;
|
|
100
|
+
/**
|
|
101
|
+
* Place a limit order
|
|
102
|
+
*/
|
|
67
103
|
limitOrder(params: LimitOrderParams): Promise<ExecutionEvent>;
|
|
104
|
+
/**
|
|
105
|
+
* Place a stop order
|
|
106
|
+
*/
|
|
68
107
|
stopOrder(params: StopOrderParams): Promise<ExecutionEvent>;
|
|
108
|
+
/**
|
|
109
|
+
* Place a stop-limit order
|
|
110
|
+
*/
|
|
69
111
|
stopLimitOrder(params: StopLimitOrderParams): Promise<ExecutionEvent>;
|
|
112
|
+
/**
|
|
113
|
+
* Place a market range order
|
|
114
|
+
*/
|
|
70
115
|
marketRangeOrder(params: MarketRangeOrderParams): Promise<ExecutionEvent>;
|
|
116
|
+
/**
|
|
117
|
+
* Close a position partially or fully
|
|
118
|
+
*/
|
|
71
119
|
closePosition(positionId: number, volume: number): Promise<ExecutionEvent>;
|
|
120
|
+
/**
|
|
121
|
+
* Modify SL/TP on an existing position
|
|
122
|
+
*/
|
|
72
123
|
amendPositionSltp(positionId: number, params: AmendSltpParams): Promise<void>;
|
|
124
|
+
/**
|
|
125
|
+
* Modify an existing pending order
|
|
126
|
+
*/
|
|
73
127
|
amendOrder(orderId: number, params: AmendOrderParams): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Cancel a pending order
|
|
130
|
+
*/
|
|
74
131
|
cancelOrder(orderId: number): Promise<void>;
|
|
132
|
+
/**
|
|
133
|
+
* Subscribe to order execution events
|
|
134
|
+
*/
|
|
75
135
|
onExecution(handler: (event: ExecutionEvent) => void): () => void;
|
|
136
|
+
/**
|
|
137
|
+
* Subscribe to order error events
|
|
138
|
+
*/
|
|
76
139
|
onOrderError(handler: (event: OrderErrorEvent) => void): () => void;
|
|
140
|
+
/**
|
|
141
|
+
* Subscribe to trailing stop loss change events
|
|
142
|
+
*/
|
|
77
143
|
onTrailingSLChanged(handler: (event: TrailingSLChangedEvent) => void): () => void;
|
|
78
144
|
private sendNewOrder;
|
|
79
145
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trading.d.ts","sourceRoot":"","sources":["../../../src/modules/trading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"trading.d.ts","sourceRoot":"","sources":["../../../src/modules/trading.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC/D,OAAO,EACN,KAAK,kBAAkB,EAGvB,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAEpG;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB;IAClB,SAAS,EAAE,SAAS,CAAC;IACrB,sFAAsF;IACtF,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,4EAA4E;IAC5E,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,uGAAuG;IACvG,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,uGAAuG;IACvG,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,gBAAgB,CA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