ctrader-ts 0.1.10 → 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} +53 -4
- package/dist/src/core/connection.d.ts.map +1 -0
- package/dist/src/{connection.js → core/connection.js} +152 -18
- 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
package/dist/src/index.d.ts
CHANGED
|
@@ -1,13 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ctrader-ts — TypeScript client for the cTrader Open API.
|
|
3
|
+
*
|
|
4
|
+
* Quick start:
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { connect } from "ctrader-ts";
|
|
7
|
+
* const ct = await connect();
|
|
8
|
+
* const pos = await ct.buy("EURUSD", { lots: 0.1, sl: { pips: 50 } });
|
|
9
|
+
* await ct.close(pos.positionId);
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @see {@link connect} for the recommended entry point.
|
|
13
|
+
* @see {@link CTrader} for the full high-level API.
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
export { CTrader, type CTraderClientConfig, type LimitOrderOptions, type Lots, lotsToUnits, type MarketOrderOptions, type ModifyOptions, pipsToRelative, type SpotPrice, type StopLimitOptions, type StopOrderOptions, type Symbol, unitsToLots, } from "./core/client.js";
|
|
17
|
+
export { type CTraderConfig, getConfigPath, loadStoredConfig, type PartialConfig, resolveConfig, saveConfig, } from "./core/config.js";
|
|
18
|
+
export { type ConnectOptions, connect, DEMO_ENDPOINT, LIVE_ENDPOINT, } from "./core/connect.js";
|
|
19
|
+
export { type ConnectionEvent, CTraderConnection, type CTraderConnectionConfig, } from "./core/connection.js";
|
|
20
|
+
export { CTraderError, NotConnectedError, RequestTimeoutError, } from "./core/errors.js";
|
|
7
21
|
export { CTraderAccount, type DealListParams, type OrderListParams, type TimeRangeParams, } from "./modules/account.js";
|
|
8
|
-
export {
|
|
9
|
-
export {
|
|
10
|
-
export { type
|
|
11
|
-
export {
|
|
12
|
-
export
|
|
22
|
+
export { CTraderAuth } from "./modules/auth.js";
|
|
23
|
+
export { CTraderMarket, type GetTickDataParams, type GetTrendbarsParams, } from "./modules/market.js";
|
|
24
|
+
export { type AmendOrderParams, type AmendSltpParams, CTraderTrading, type LimitOrderParams, type MarketRangeOrderParams, type NewOrderParams, type StopLimitOrderParams, type StopOrderParams, } from "./modules/trading.js";
|
|
25
|
+
export { type DecodedMessage, getMessageClass } from "./protocol/codec.js";
|
|
26
|
+
export { AccessRights, AccountType, ChangeBalanceType, ChangeBonusType, ClientPermissionScope, CommissionType, DayOfWeek, DealStatus, ExecutionType, LimitedRiskMarginCalculationStrategy, MinCommissionType, NotificationType, OrderStatus, OrderTriggerMethod, OrderType, PayloadType, PositionStatus, ProtoErrorCode, ProtoOAErrorCode, QuoteType, StopOutStrategy, SwapCalculationType, SymbolDistanceType, TimeInForce, TotalMarginCalculationType, TradeSide, TradingMode, TrendbarPeriod, } from "./protocol/enums.js";
|
|
27
|
+
export type { AccountDisconnectEvent, AccountState, ArchivedSymbol, Asset, AssetClass, BonusDepositWithdraw, ClientDisconnectEvent, ClosePositionDetail, ConnectionState, CtidProfile, CtidTraderAccount, Deal, DealOffset, DepositWithdraw, DepthEvent, DepthQuote, DynamicLeverage, DynamicLeverageTier, EnrichedPosition, EnrichedTrader, ExecutionEvent, ExpectedMargin, FullSymbol, GetDealsOptions, GetOrdersOptions, Holiday, Interval, LightSymbol, LiveAccountState, MarginCall, MarginCallEvent, MarginChangedEvent, OAErrorPayload, Order, OrderErrorEvent, Position, PositionUnrealizedPnL, SlTpSpec, SpotEvent, SymbolCategory, SymbolChangedEvent, TickData, TokenInvalidatedEvent, TokenPair, TradeData, Trader, TraderUpdatedEvent, TrailingSLChangedEvent, Trendbar, WatchStateOptions, } from "./protocol/types.js";
|
|
13
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACN,OAAO,EACP,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,IAAI,EACT,WAAW,EACX,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAClB,cAAc,EACd,KAAK,SAAS,EACd,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,WAAW,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,KAAK,aAAa,EAClB,aAAa,EACb,gBAAgB,EAChB,KAAK,aAAa,EAClB,aAAa,EACb,UAAU,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,KAAK,cAAc,EACnB,OAAO,EACP,aAAa,EACb,aAAa,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,KAAK,eAAe,EACpB,iBAAiB,EACjB,KAAK,uBAAuB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,cAAc,EACd,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,eAAe,GACpB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE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,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,qBAAqB,EACrB,SAAS,EACT,SAAS,EACT,MAAM,EACN,kBAAkB,EAClB,sBAAsB,EACtB,QAAQ,EACR,iBAAiB,GACjB,MAAM,qBAAqB,CAAC"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
/**
|
|
2
|
+
* ctrader-ts — TypeScript client for the cTrader Open API.
|
|
3
|
+
*
|
|
4
|
+
* Quick start:
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { connect } from "ctrader-ts";
|
|
7
|
+
* const ct = await connect();
|
|
8
|
+
* const pos = await ct.buy("EURUSD", { lots: 0.1, sl: { pips: 50 } });
|
|
9
|
+
* await ct.close(pos.positionId);
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @see {@link connect} for the recommended entry point.
|
|
13
|
+
* @see {@link CTrader} for the full high-level API.
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
export { CTrader, lotsToUnits, pipsToRelative, unitsToLots, } from "./core/client.js";
|
|
17
|
+
export { getConfigPath, loadStoredConfig, resolveConfig, saveConfig, } from "./core/config.js";
|
|
18
|
+
export { connect, DEMO_ENDPOINT, LIVE_ENDPOINT, } from "./core/connect.js";
|
|
19
|
+
export { CTraderConnection, } from "./core/connection.js";
|
|
20
|
+
export { CTraderError, NotConnectedError, RequestTimeoutError, } from "./core/errors.js";
|
|
7
21
|
export { CTraderAccount, } from "./modules/account.js";
|
|
22
|
+
export { CTraderAuth } from "./modules/auth.js";
|
|
8
23
|
export { CTraderMarket, } from "./modules/market.js";
|
|
9
|
-
export {
|
|
10
|
-
export { getMessageClass } from "./codec.js";
|
|
11
|
-
export {
|
|
24
|
+
export { CTraderTrading, } from "./modules/trading.js";
|
|
25
|
+
export { getMessageClass } from "./protocol/codec.js";
|
|
26
|
+
export { AccessRights, AccountType, ChangeBalanceType, ChangeBonusType, ClientPermissionScope, CommissionType, DayOfWeek, DealStatus, ExecutionType, LimitedRiskMarginCalculationStrategy, MinCommissionType, NotificationType, OrderStatus, OrderTriggerMethod, OrderType, PayloadType, PositionStatus, ProtoErrorCode, ProtoOAErrorCode, QuoteType, StopOutStrategy, SwapCalculationType, SymbolDistanceType, TimeInForce, TotalMarginCalculationType, TradeSide, TradingMode, TrendbarPeriod, } from "./protocol/enums.js";
|
|
12
27
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACN,OAAO,EAIP,WAAW,EAGX,cAAc,EAKd,WAAW,GACX,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,aAAa,EACb,gBAAgB,EAEhB,aAAa,EACb,UAAU,GACV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,OAAO,EACP,aAAa,EACb,aAAa,GACb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEN,iBAAiB,GAEjB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,cAAc,GAId,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACN,aAAa,GAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAGN,cAAc,GAMd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAuB,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3E,OAAO,EACN,YAAY,EACZ,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,cAAc,EACd,SAAS,EACT,UAAU,EACV,aAAa,EACb,oCAAoC,EACpC,iBAAiB,EACjB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,cAAc,EACd,cAAc,EACd,gBAAgB,EAChB,SAAS,EACT,eAAe,EACf,mBAAmB,EACnB,kBAAkB,EAClB,WAAW,EACX,0BAA0B,EAC1B,SAAS,EACT,WAAW,EACX,cAAc,GACd,MAAM,qBAAqB,CAAC"}
|
|
@@ -1,67 +1,133 @@
|
|
|
1
|
-
import type { CTraderConnection } from "../connection.js";
|
|
2
|
-
import type { Deal, DealOffset, DepositWithdraw, DynamicLeverage, ExpectedMargin, MarginCall, MarginCallEvent, MarginChangedEvent, Order, Position, PositionUnrealizedPnL, Trader, TraderUpdatedEvent } from "../types.js";
|
|
1
|
+
import type { CTraderConnection } from "../core/connection.js";
|
|
2
|
+
import type { Deal, DealOffset, DepositWithdraw, DynamicLeverage, ExpectedMargin, MarginCall, MarginCallEvent, MarginChangedEvent, Order, Position, PositionUnrealizedPnL, Trader, TraderUpdatedEvent } from "../protocol/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Parameters for querying deal history
|
|
5
|
+
*/
|
|
3
6
|
export interface DealListParams {
|
|
4
7
|
fromTimestamp?: number;
|
|
5
8
|
toTimestamp?: number;
|
|
6
9
|
maxRows?: number;
|
|
7
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Parameters for querying order history
|
|
13
|
+
*/
|
|
8
14
|
export interface OrderListParams {
|
|
9
15
|
fromTimestamp?: number;
|
|
10
16
|
toTimestamp?: number;
|
|
11
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* Optional time range filter
|
|
20
|
+
*/
|
|
12
21
|
export interface TimeRangeParams {
|
|
13
22
|
fromTimestamp?: number;
|
|
14
23
|
toTimestamp?: number;
|
|
15
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Low-level account operations — reconcile, history, margin queries. Use CTrader (client.ts) for the high-level API.
|
|
27
|
+
*/
|
|
16
28
|
export declare class CTraderAccount {
|
|
17
29
|
private readonly connection;
|
|
18
30
|
private accountId;
|
|
19
31
|
constructor(connection: CTraderConnection, accountId: number);
|
|
20
32
|
setAccountId(accountId: number): void;
|
|
33
|
+
/**
|
|
34
|
+
* Get current trader account info
|
|
35
|
+
*/
|
|
21
36
|
getTrader(): Promise<Trader>;
|
|
37
|
+
/**
|
|
38
|
+
* Sync local state with server — get current positions and orders
|
|
39
|
+
*/
|
|
22
40
|
reconcile(returnProtectionOrders?: boolean): Promise<{
|
|
23
41
|
positions: Position[];
|
|
24
42
|
orders: Order[];
|
|
25
43
|
}>;
|
|
44
|
+
/**
|
|
45
|
+
* Get deal history
|
|
46
|
+
*/
|
|
26
47
|
getDeals(params?: DealListParams): Promise<{
|
|
27
48
|
deals: Deal[];
|
|
28
49
|
hasMore: boolean;
|
|
29
50
|
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Get deals for a specific position
|
|
53
|
+
*/
|
|
30
54
|
getDealsByPosition(positionId: number, params?: TimeRangeParams): Promise<{
|
|
31
55
|
deals: Deal[];
|
|
32
56
|
hasMore: boolean;
|
|
33
57
|
}>;
|
|
58
|
+
/**
|
|
59
|
+
* Get offset information for a specific deal
|
|
60
|
+
*/
|
|
34
61
|
getDealOffsets(dealId: number): Promise<{
|
|
35
62
|
offsetBy: DealOffset[];
|
|
36
63
|
offsetting: DealOffset[];
|
|
37
64
|
}>;
|
|
65
|
+
/**
|
|
66
|
+
* Get order history
|
|
67
|
+
*/
|
|
38
68
|
getOrders(params?: OrderListParams): Promise<{
|
|
39
69
|
orders: Order[];
|
|
40
70
|
hasMore: boolean;
|
|
41
71
|
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Get details for a specific order
|
|
74
|
+
*/
|
|
42
75
|
getOrderDetails(orderId: number): Promise<{
|
|
43
76
|
order: Order;
|
|
44
77
|
deals: Deal[];
|
|
45
78
|
}>;
|
|
79
|
+
/**
|
|
80
|
+
* Get orders for a specific position
|
|
81
|
+
*/
|
|
46
82
|
getOrdersByPosition(positionId: number, params?: TimeRangeParams): Promise<{
|
|
47
83
|
orders: Order[];
|
|
48
84
|
hasMore: boolean;
|
|
49
85
|
}>;
|
|
86
|
+
/**
|
|
87
|
+
* Get cash flow history (deposits/withdrawals)
|
|
88
|
+
*/
|
|
50
89
|
getCashFlowHistory(fromTimestamp: number, toTimestamp: number): Promise<DepositWithdraw[]>;
|
|
90
|
+
/**
|
|
91
|
+
* Get expected margin for volumes on a symbol
|
|
92
|
+
*/
|
|
51
93
|
getExpectedMargin(symbolId: number, volumes: number[]): Promise<{
|
|
52
94
|
margins: ExpectedMargin[];
|
|
53
95
|
moneyDigits?: number;
|
|
54
96
|
}>;
|
|
97
|
+
/**
|
|
98
|
+
* Get unrealized PnL for all open positions
|
|
99
|
+
*/
|
|
55
100
|
getPositionUnrealizedPnl(): Promise<{
|
|
56
101
|
pnls: PositionUnrealizedPnL[];
|
|
57
102
|
moneyDigits: number;
|
|
58
103
|
}>;
|
|
104
|
+
/**
|
|
105
|
+
* Get dynamic leverage information
|
|
106
|
+
*/
|
|
59
107
|
getDynamicLeverage(leverageId: number): Promise<DynamicLeverage>;
|
|
108
|
+
/**
|
|
109
|
+
* Get margin call list
|
|
110
|
+
*/
|
|
60
111
|
getMarginCalls(): Promise<MarginCall[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Update a margin call
|
|
114
|
+
*/
|
|
61
115
|
updateMarginCall(marginCall: MarginCall): Promise<void>;
|
|
116
|
+
/**
|
|
117
|
+
* Subscribe to trader account update events
|
|
118
|
+
*/
|
|
62
119
|
onTraderUpdated(handler: (event: TraderUpdatedEvent) => void): () => void;
|
|
120
|
+
/**
|
|
121
|
+
* Subscribe to margin change events
|
|
122
|
+
*/
|
|
63
123
|
onMarginChanged(handler: (event: MarginChangedEvent) => void): () => void;
|
|
124
|
+
/**
|
|
125
|
+
* Subscribe to margin call update events
|
|
126
|
+
*/
|
|
64
127
|
onMarginCallUpdate(handler: (event: MarginCallEvent) => void): () => void;
|
|
128
|
+
/**
|
|
129
|
+
* Subscribe to margin call trigger events
|
|
130
|
+
*/
|
|
65
131
|
onMarginCallTrigger(handler: (event: MarginCallEvent) => void): () => void;
|
|
66
132
|
}
|
|
67
133
|
//# sourceMappingURL=account.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/modules/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../src/modules/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,KAAK,EACX,IAAI,EACJ,UAAU,EACV,eAAe,EACf,eAAe,EACf,cAAc,EACd,UAAU,EACV,eAAe,EACf,kBAAkB,EAClB,KAAK,EACL,QAAQ,EACR,qBAAqB,EACrB,MAAM,EACN,kBAAkB,EAClB,MAAM,sBAAsB,CAAC;AAE9B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,WAAW,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,SAAS,CAAS;gBAEd,UAAU,EA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KAAE,CAAC;IAWjD;;OAEG;IACG,kBAAkB,CAAC,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAShG;;OAEG;IACG,iBAAiB,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EAAE,GACf,OAAO,CAAC;QAAE,OAAO,EAAE,cAAc,EAAE,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAa/D;;OAEG;IACG,wBAAwB,IAAI,OAAO,CAAC;QACzC,IAAI,EAAE,qBAAqB,EAAE,CAAC;QAC9B,WAAW,EAAE,MAAM,CAAC;KACpB,CAAC;IAUF;;OAEG;IACG,kBAAkB,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC;IAQtE;;OAEG;IACG,cAAc,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAO7C;;OAEG;IACG,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAO7D;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,IAAI;IAMzE;;OAEG;IACH,eAAe,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,GAAG,MAAM,IAAI;IAMzE;;OAEG;IACH,kBAAkB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI;IAMzE;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,GAAG,MAAM,IAAI;CAK1E"}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import { PayloadType } from "../enums.js";
|
|
1
|
+
import { PayloadType } from "../protocol/enums.js";
|
|
2
|
+
/**
|
|
3
|
+
* Low-level account operations — reconcile, history, margin queries. Use CTrader (client.ts) for the high-level API.
|
|
4
|
+
*/
|
|
2
5
|
export class CTraderAccount {
|
|
3
6
|
connection;
|
|
4
7
|
accountId;
|
|
@@ -9,100 +12,130 @@ export class CTraderAccount {
|
|
|
9
12
|
setAccountId(accountId) {
|
|
10
13
|
this.accountId = accountId;
|
|
11
14
|
}
|
|
15
|
+
/**
|
|
16
|
+
* Get current trader account info
|
|
17
|
+
*/
|
|
12
18
|
async getTrader() {
|
|
13
19
|
const res = await this.connection.request(PayloadType.TRADER_REQ, {
|
|
14
20
|
ctidTraderAccountId: this.accountId,
|
|
15
21
|
});
|
|
16
|
-
return res
|
|
22
|
+
return res.trader;
|
|
17
23
|
}
|
|
24
|
+
/**
|
|
25
|
+
* Sync local state with server — get current positions and orders
|
|
26
|
+
*/
|
|
18
27
|
async reconcile(returnProtectionOrders) {
|
|
19
28
|
const payload = { ctidTraderAccountId: this.accountId };
|
|
20
29
|
if (returnProtectionOrders !== undefined)
|
|
21
|
-
payload
|
|
30
|
+
payload.returnProtectionOrders = returnProtectionOrders;
|
|
22
31
|
const res = await this.connection.request(PayloadType.RECONCILE_REQ, payload);
|
|
23
32
|
return {
|
|
24
|
-
positions: res
|
|
25
|
-
orders: res
|
|
33
|
+
positions: res.position ?? [],
|
|
34
|
+
orders: res.order ?? [],
|
|
26
35
|
};
|
|
27
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* Get deal history
|
|
39
|
+
*/
|
|
28
40
|
async getDeals(params = {}) {
|
|
29
41
|
const payload = { ctidTraderAccountId: this.accountId };
|
|
30
42
|
if (params.fromTimestamp !== undefined)
|
|
31
|
-
payload
|
|
43
|
+
payload.fromTimestamp = params.fromTimestamp;
|
|
32
44
|
if (params.toTimestamp !== undefined)
|
|
33
|
-
payload
|
|
45
|
+
payload.toTimestamp = params.toTimestamp;
|
|
34
46
|
if (params.maxRows !== undefined)
|
|
35
|
-
payload
|
|
47
|
+
payload.maxRows = params.maxRows;
|
|
36
48
|
const res = await this.connection.request(PayloadType.DEAL_LIST_REQ, payload);
|
|
37
49
|
return {
|
|
38
|
-
deals: res
|
|
39
|
-
hasMore: res
|
|
50
|
+
deals: res.deal ?? [],
|
|
51
|
+
hasMore: res.hasMore ?? false,
|
|
40
52
|
};
|
|
41
53
|
}
|
|
54
|
+
/**
|
|
55
|
+
* Get deals for a specific position
|
|
56
|
+
*/
|
|
42
57
|
async getDealsByPosition(positionId, params = {}) {
|
|
43
58
|
const payload = { ctidTraderAccountId: this.accountId, positionId };
|
|
44
59
|
if (params.fromTimestamp !== undefined)
|
|
45
|
-
payload
|
|
60
|
+
payload.fromTimestamp = params.fromTimestamp;
|
|
46
61
|
if (params.toTimestamp !== undefined)
|
|
47
|
-
payload
|
|
62
|
+
payload.toTimestamp = params.toTimestamp;
|
|
48
63
|
const res = await this.connection.request(PayloadType.DEAL_LIST_BY_POSITION_REQ, payload);
|
|
49
64
|
return {
|
|
50
|
-
deals: res
|
|
51
|
-
hasMore: res
|
|
65
|
+
deals: res.deal ?? [],
|
|
66
|
+
hasMore: res.hasMore ?? false,
|
|
52
67
|
};
|
|
53
68
|
}
|
|
69
|
+
/**
|
|
70
|
+
* Get offset information for a specific deal
|
|
71
|
+
*/
|
|
54
72
|
async getDealOffsets(dealId) {
|
|
55
73
|
const res = await this.connection.request(PayloadType.DEAL_OFFSET_LIST_REQ, {
|
|
56
74
|
ctidTraderAccountId: this.accountId,
|
|
57
75
|
dealId,
|
|
58
76
|
});
|
|
59
77
|
return {
|
|
60
|
-
offsetBy: res
|
|
61
|
-
offsetting: res
|
|
78
|
+
offsetBy: res.offsetBy ?? [],
|
|
79
|
+
offsetting: res.offsetting ?? [],
|
|
62
80
|
};
|
|
63
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Get order history
|
|
84
|
+
*/
|
|
64
85
|
async getOrders(params = {}) {
|
|
65
86
|
const payload = { ctidTraderAccountId: this.accountId };
|
|
66
87
|
if (params.fromTimestamp !== undefined)
|
|
67
|
-
payload
|
|
88
|
+
payload.fromTimestamp = params.fromTimestamp;
|
|
68
89
|
if (params.toTimestamp !== undefined)
|
|
69
|
-
payload
|
|
90
|
+
payload.toTimestamp = params.toTimestamp;
|
|
70
91
|
const res = await this.connection.request(PayloadType.ORDER_LIST_REQ, payload);
|
|
71
92
|
return {
|
|
72
|
-
orders: res
|
|
73
|
-
hasMore: res
|
|
93
|
+
orders: res.order ?? [],
|
|
94
|
+
hasMore: res.hasMore ?? false,
|
|
74
95
|
};
|
|
75
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Get details for a specific order
|
|
99
|
+
*/
|
|
76
100
|
async getOrderDetails(orderId) {
|
|
77
101
|
const res = await this.connection.request(PayloadType.ORDER_DETAILS_REQ, {
|
|
78
102
|
ctidTraderAccountId: this.accountId,
|
|
79
103
|
orderId,
|
|
80
104
|
});
|
|
81
105
|
return {
|
|
82
|
-
order: res
|
|
83
|
-
deals: res
|
|
106
|
+
order: res.order,
|
|
107
|
+
deals: res.deal ?? [],
|
|
84
108
|
};
|
|
85
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Get orders for a specific position
|
|
112
|
+
*/
|
|
86
113
|
async getOrdersByPosition(positionId, params = {}) {
|
|
87
114
|
const payload = { ctidTraderAccountId: this.accountId, positionId };
|
|
88
115
|
if (params.fromTimestamp !== undefined)
|
|
89
|
-
payload
|
|
116
|
+
payload.fromTimestamp = params.fromTimestamp;
|
|
90
117
|
if (params.toTimestamp !== undefined)
|
|
91
|
-
payload
|
|
118
|
+
payload.toTimestamp = params.toTimestamp;
|
|
92
119
|
const res = await this.connection.request(PayloadType.ORDER_LIST_BY_POSITION_REQ, payload);
|
|
93
120
|
return {
|
|
94
|
-
orders: res
|
|
95
|
-
hasMore: res
|
|
121
|
+
orders: res.order ?? [],
|
|
122
|
+
hasMore: res.hasMore ?? false,
|
|
96
123
|
};
|
|
97
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Get cash flow history (deposits/withdrawals)
|
|
127
|
+
*/
|
|
98
128
|
async getCashFlowHistory(fromTimestamp, toTimestamp) {
|
|
99
129
|
const res = await this.connection.request(PayloadType.CASH_FLOW_HISTORY_REQ, {
|
|
100
130
|
ctidTraderAccountId: this.accountId,
|
|
101
131
|
fromTimestamp,
|
|
102
132
|
toTimestamp,
|
|
103
133
|
});
|
|
104
|
-
return res
|
|
134
|
+
return res.depositWithdraw ?? [];
|
|
105
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Get expected margin for volumes on a symbol
|
|
138
|
+
*/
|
|
106
139
|
async getExpectedMargin(symbolId, volumes) {
|
|
107
140
|
const res = await this.connection.request(PayloadType.EXPECTED_MARGIN_REQ, {
|
|
108
141
|
ctidTraderAccountId: this.accountId,
|
|
@@ -110,55 +143,79 @@ export class CTraderAccount {
|
|
|
110
143
|
volume: volumes,
|
|
111
144
|
});
|
|
112
145
|
const result = {
|
|
113
|
-
margins: res
|
|
146
|
+
margins: res.margin ?? [],
|
|
114
147
|
};
|
|
115
|
-
if (res
|
|
116
|
-
result.moneyDigits = res
|
|
148
|
+
if (res.moneyDigits !== undefined)
|
|
149
|
+
result.moneyDigits = res.moneyDigits;
|
|
117
150
|
return result;
|
|
118
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Get unrealized PnL for all open positions
|
|
154
|
+
*/
|
|
119
155
|
async getPositionUnrealizedPnl() {
|
|
120
156
|
const res = await this.connection.request(PayloadType.GET_POSITION_UNREALIZED_PNL_REQ, {
|
|
121
157
|
ctidTraderAccountId: this.accountId,
|
|
122
158
|
});
|
|
123
159
|
return {
|
|
124
|
-
pnls: res
|
|
125
|
-
moneyDigits: res
|
|
160
|
+
pnls: res.positionUnrealizedPnL ?? [],
|
|
161
|
+
moneyDigits: res.moneyDigits,
|
|
126
162
|
};
|
|
127
163
|
}
|
|
164
|
+
/**
|
|
165
|
+
* Get dynamic leverage information
|
|
166
|
+
*/
|
|
128
167
|
async getDynamicLeverage(leverageId) {
|
|
129
168
|
const res = await this.connection.request(PayloadType.GET_DYNAMIC_LEVERAGE_REQ, {
|
|
130
169
|
ctidTraderAccountId: this.accountId,
|
|
131
170
|
leverageId,
|
|
132
171
|
});
|
|
133
|
-
return res
|
|
172
|
+
return res.leverage;
|
|
134
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Get margin call list
|
|
176
|
+
*/
|
|
135
177
|
async getMarginCalls() {
|
|
136
178
|
const res = await this.connection.request(PayloadType.MARGIN_CALL_LIST_REQ, {
|
|
137
179
|
ctidTraderAccountId: this.accountId,
|
|
138
180
|
});
|
|
139
|
-
return res
|
|
181
|
+
return res.marginCall ?? [];
|
|
140
182
|
}
|
|
183
|
+
/**
|
|
184
|
+
* Update a margin call
|
|
185
|
+
*/
|
|
141
186
|
async updateMarginCall(marginCall) {
|
|
142
187
|
await this.connection.request(PayloadType.MARGIN_CALL_UPDATE_REQ, {
|
|
143
188
|
ctidTraderAccountId: this.accountId,
|
|
144
189
|
marginCall: marginCall,
|
|
145
190
|
});
|
|
146
191
|
}
|
|
192
|
+
/**
|
|
193
|
+
* Subscribe to trader account update events
|
|
194
|
+
*/
|
|
147
195
|
onTraderUpdated(handler) {
|
|
148
196
|
return this.connection.on(PayloadType.TRADER_UPDATED_EVENT, (payload) => {
|
|
149
197
|
handler(payload);
|
|
150
198
|
});
|
|
151
199
|
}
|
|
200
|
+
/**
|
|
201
|
+
* Subscribe to margin change events
|
|
202
|
+
*/
|
|
152
203
|
onMarginChanged(handler) {
|
|
153
204
|
return this.connection.on(PayloadType.MARGIN_CHANGED_EVENT, (payload) => {
|
|
154
205
|
handler(payload);
|
|
155
206
|
});
|
|
156
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Subscribe to margin call update events
|
|
210
|
+
*/
|
|
157
211
|
onMarginCallUpdate(handler) {
|
|
158
212
|
return this.connection.on(PayloadType.MARGIN_CALL_UPDATE_EVENT, (payload) => {
|
|
159
213
|
handler(payload);
|
|
160
214
|
});
|
|
161
215
|
}
|
|
216
|
+
/**
|
|
217
|
+
* Subscribe to margin call trigger events
|
|
218
|
+
*/
|
|
162
219
|
onMarginCallTrigger(handler) {
|
|
163
220
|
return this.connection.on(PayloadType.MARGIN_CALL_TRIGGER_EVENT, (payload) => {
|
|
164
221
|
handler(payload);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/modules/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../src/modules/account.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AA0CnD;;GAEG;AACH,MAAM,OAAO,cAAc;IACT,UAAU,CAAoB;IACvC,SAAS,CAAS;IAE1B,YAAY,UAA6B,EAAE,SAAiB;QAC3D,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,YAAY,CAAC,SAAiB;QAC7B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS;QACd,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,UAAU,EAAE;YACjE,mBAAmB,EAAE,IAAI,CAAC,SAAS;SACnC,CAAC,CAAC;QACH,OAAO,GAAG,CAAC,MAAgB,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,SAAS,CACd,sBAAgC;QAEhC,MAAM,OAAO,GAA4B,EAAE,mBAAmB,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC;QACjF,IAAI,sBAAsB,KAAK,SAAS;YACvC,OAAO,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;QACzD,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QAC9E,OAAO;YACN,SA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AAmB,EAAE,IAAI,CAAC,SAAS;YACnC,UAAU,EAAE,UAAgD;SAC5D,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,eAAe,CAAC,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;;OAEG;IACH,eAAe,CAAC,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;;OAEG;IACH,kBAAkB,CAAC,OAAyC;QAC3D,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,wBAAwB,EAAE,CAAC,OAAO,EAAE,EAAE;YAC3E,OAAO,CAAC,OAAqC,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,mBAAmB,CAAC,OAAyC;QAC5D,OAAO,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC,WAAW,CAAC,yBAAyB,EAAE,CAAC,OAAO,EAAE,EAAE;YAC5E,OAAO,CAAC,OAAqC,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|
|
@@ -1,20 +1,47 @@
|
|
|
1
|
-
import type { CTraderConnection } from "../connection.js";
|
|
2
|
-
import type { CtidProfile, CtidTraderAccount, TokenPair } from "../types.js";
|
|
1
|
+
import type { CTraderConnection } from "../core/connection.js";
|
|
2
|
+
import type { CtidProfile, CtidTraderAccount, TokenPair } from "../protocol/types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Authentication module — app auth, account auth, token management. Used internally by connect() and available via ct.raw.auth for manual auth flows.
|
|
5
|
+
*/
|
|
3
6
|
export declare class CTraderAuth {
|
|
4
7
|
private readonly connection;
|
|
5
8
|
constructor(connection: CTraderConnection);
|
|
9
|
+
/**
|
|
10
|
+
* Authenticate the application with cTrader backend. Must be called before account auth.
|
|
11
|
+
*/
|
|
6
12
|
authenticateApp(clientId: string, clientSecret: string): Promise<void>;
|
|
13
|
+
/**
|
|
14
|
+
* Authenticate a specific trading account. Requires app auth first.
|
|
15
|
+
*/
|
|
7
16
|
authenticateAccount(ctidTraderAccountId: number, accessToken: string): Promise<void>;
|
|
17
|
+
/**
|
|
18
|
+
* Convenience: app auth + account auth in one call
|
|
19
|
+
*/
|
|
8
20
|
authenticate(opts: {
|
|
9
21
|
clientId: string;
|
|
10
22
|
clientSecret: string;
|
|
11
23
|
ctidTraderAccountId: number;
|
|
12
24
|
accessToken: string;
|
|
13
25
|
}): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get all trading accounts associated with an access token
|
|
28
|
+
*/
|
|
14
29
|
getAccountsByToken(accessToken: string): Promise<CtidTraderAccount[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Get the cTrader ID profile for a token
|
|
32
|
+
*/
|
|
15
33
|
getCtidProfile(accessToken: string): Promise<CtidProfile>;
|
|
34
|
+
/**
|
|
35
|
+
* Exchange a refresh token for a new access/refresh token pair
|
|
36
|
+
*/
|
|
16
37
|
refreshToken(refreshToken: string): Promise<TokenPair>;
|
|
38
|
+
/**
|
|
39
|
+
* Disconnect a specific account from the session
|
|
40
|
+
*/
|
|
17
41
|
logout(ctidTraderAccountId: number): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Get the cTrader Open API protocol version
|
|
44
|
+
*/
|
|
18
45
|
getApiVersion(): Promise<string>;
|
|
19
46
|
}
|
|
20
47
|
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/modules/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../../src/modules/auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE/D,OAAO,KAAK,EAAE,WAAW,EAAE,iBAAiB,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtF;;GAEG;AACH,qBAAa,WAAW;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;gBAEnC,UAAU,EAAE,iBAAiB;IAIzC;;OAEG;IACG,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E;;OAEG;IACG,mBAAmB,CAAC,mBAAmB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO1F;;OAEG;IACG,YAAY,CAAC,IAAI,EAAE;QACxB,QAAQ,EAAE,MAAM,CAAC;QACjB,YAAY,EAAE,MAAM,CAAC;QACrB,mBAAmB,EAAE,MAAM,CAAC;QAC5B,WAAW,EAAE,MAAM,CAAC;KACpB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKjB;;OAEG;IACG,kBAAkB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAQ3E;;OAEG;IACG,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAK/D;;OAEG;IACG,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAU5D;;OAEG;IACG,MAAM,CAAC,mBAAmB,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;CAItC"}
|