@trade-it/react 0.1.1 → 0.3.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/CHANGELOG.md +20 -0
- package/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/index.cjs +1296 -71
- package/dist/index.d.cts +49 -71
- package/dist/index.d.ts +49 -71
- package/dist/index.js +1293 -74
- package/package.json +16 -5
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as react0 from "react";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
|
|
4
3
|
//#region ../../lib/types/src/enums/trading.enums.d.ts
|
|
5
4
|
declare enum TradeAction {
|
|
@@ -19,6 +18,7 @@ declare enum OrderType {
|
|
|
19
18
|
declare enum OrderDirection {
|
|
20
19
|
Debit = "debit",
|
|
21
20
|
Credit = "credit",
|
|
21
|
+
Even = "even",
|
|
22
22
|
}
|
|
23
23
|
declare enum TimeInForce {
|
|
24
24
|
Day = "day",
|
|
@@ -30,6 +30,15 @@ declare enum TradeUnit {
|
|
|
30
30
|
Dollars = "dollars",
|
|
31
31
|
Shares = "shares",
|
|
32
32
|
}
|
|
33
|
+
/** How an exit trigger (take-profit / stop-loss) value is expressed */
|
|
34
|
+
declare enum TriggerUnit {
|
|
35
|
+
/** An absolute price level */
|
|
36
|
+
Price = "$",
|
|
37
|
+
/** A percentage offset from the entry price */
|
|
38
|
+
Percent = "%",
|
|
39
|
+
}
|
|
40
|
+
/** Which exit an attached trigger represents */
|
|
41
|
+
|
|
33
42
|
declare enum LegType {
|
|
34
43
|
Option = "option",
|
|
35
44
|
Equity = "equity",
|
|
@@ -38,94 +47,61 @@ declare enum TradeType {
|
|
|
38
47
|
Simple = 0,
|
|
39
48
|
MultiLeg = 1,
|
|
40
49
|
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region ../../lib/types/src/schemas/trade-link.schemas.d.ts
|
|
43
50
|
/**
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
declare const zTradeLinkLegConfig: z.ZodObject<Omit<{
|
|
47
|
-
type: z.ZodNativeEnum<typeof LegType>;
|
|
48
|
-
action: z.ZodNativeEnum<typeof TradeAction>;
|
|
49
|
-
position_effect: z.ZodNullable<z.ZodNativeEnum<typeof PositionEffect>>;
|
|
50
|
-
occ: z.ZodNullable<z.ZodString>;
|
|
51
|
-
quantity: z.ZodNumber;
|
|
52
|
-
execution_price: z.ZodNullable<z.ZodObject<{
|
|
53
|
-
amount: z.ZodNumber;
|
|
54
|
-
currency: z.ZodString;
|
|
55
|
-
}, "strip", z.ZodTypeAny, {
|
|
56
|
-
amount: number;
|
|
57
|
-
currency: string;
|
|
58
|
-
}, {
|
|
59
|
-
amount: number;
|
|
60
|
-
currency: string;
|
|
61
|
-
}>>;
|
|
62
|
-
}, "execution_price">, "strip", z.ZodTypeAny, {
|
|
63
|
-
type: LegType;
|
|
64
|
-
action: TradeAction;
|
|
65
|
-
position_effect: PositionEffect | null;
|
|
66
|
-
occ: string | null;
|
|
67
|
-
quantity: number;
|
|
68
|
-
}, {
|
|
69
|
-
type: LegType;
|
|
70
|
-
action: TradeAction;
|
|
71
|
-
position_effect: PositionEffect | null;
|
|
72
|
-
occ: string | null;
|
|
73
|
-
quantity: number;
|
|
74
|
-
}>;
|
|
75
|
-
/**
|
|
76
|
-
* Full Trade Link Config - stored in database as JSONB
|
|
77
|
-
* Supports both simple trades and multi-leg options trades
|
|
51
|
+
* A brokerage-reported option lifecycle event. Rows carrying an event describe
|
|
52
|
+
* what happened to a contract, so `action` is not meaningful on them.
|
|
78
53
|
*/
|
|
79
54
|
//#endregion
|
|
80
|
-
//#region
|
|
81
|
-
type
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Short query parameter keys for trade link URLs
|
|
92
|
-
*/
|
|
55
|
+
//#region ../trade-it-core/src/types.d.ts
|
|
56
|
+
type TradeItEventType = 'tradeit.ready' | 'tradeit.close_requested' | 'tradeit.brokerage_connected' | 'tradeit.trade_submitted' | 'tradeit.trade_executed' | 'tradeit.error' | 'tradeit.login_required';
|
|
57
|
+
interface TradeItEvent<TPayload = Record<string, unknown>> {
|
|
58
|
+
source: 'tradeit';
|
|
59
|
+
version: 1;
|
|
60
|
+
type: TradeItEventType;
|
|
61
|
+
payload?: TPayload;
|
|
62
|
+
}
|
|
63
|
+
type TradeItMode = 'connect' | 'trade';
|
|
64
|
+
/** Compact query keys accepted by Trade It trade URLs. */
|
|
93
65
|
declare enum TradeLinkParam {
|
|
94
66
|
TradeType = "tt",
|
|
95
|
-
// s (simple), m (multi_leg)
|
|
96
67
|
Action = "t",
|
|
97
|
-
|
|
68
|
+
Direction = "dir",
|
|
98
69
|
OrderType = "ot",
|
|
99
|
-
// m, l, st, sl
|
|
100
70
|
Amount = "a",
|
|
101
|
-
// number
|
|
102
71
|
Unit = "u",
|
|
103
|
-
// d, s
|
|
104
72
|
LimitPrice = "lp",
|
|
105
|
-
// number
|
|
106
73
|
StopPrice = "sp",
|
|
107
|
-
// number
|
|
108
74
|
TimeInForce = "tif",
|
|
109
|
-
|
|
75
|
+
TakeProfit = "tp",
|
|
76
|
+
StopLoss = "sl",
|
|
110
77
|
UtmReferred = "ref",
|
|
111
|
-
// string
|
|
112
78
|
Legs = "legs",
|
|
113
79
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
type
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
80
|
+
/** Canonical snake_case leg shape used by Trade Link APIs. */
|
|
81
|
+
interface TradeLinkLegConfig {
|
|
82
|
+
type: LegType;
|
|
83
|
+
action: TradeAction;
|
|
84
|
+
position_effect: PositionEffect | null;
|
|
85
|
+
occ: string | null;
|
|
86
|
+
quantity: number;
|
|
87
|
+
}
|
|
88
|
+
/** User-facing camelCase leg shape accepted by the embedded SDK. */
|
|
89
|
+
interface TradeItMultiLegTradeLegConfig {
|
|
90
|
+
type?: LegType;
|
|
91
|
+
action?: TradeAction;
|
|
92
|
+
positionEffect?: PositionEffect | null;
|
|
93
|
+
occ?: string | null;
|
|
94
|
+
quantity?: number;
|
|
95
|
+
}
|
|
96
|
+
/** Attached take-profit or stop-loss trigger. */
|
|
97
|
+
interface TradeItExitTrigger {
|
|
98
|
+
value: number;
|
|
99
|
+
unit: '$' | '%';
|
|
122
100
|
}
|
|
123
|
-
type TradeItMode = 'connect' | 'trade';
|
|
124
|
-
type TradeItMultiLegTradeLegConfig = Partial<Camelize<TradeLinkLegConfig>>;
|
|
125
101
|
/**
|
|
126
102
|
* Query params accepted by Trade It's /t/[ticker] page.
|
|
127
103
|
* User-facing config uses descriptive keys; core converts them to the short-key
|
|
128
|
-
* query format used by the page parser (tt, t, ot, a, u, lp, sp, tif, ref, legs).
|
|
104
|
+
* query format used by the page parser (tt, t, dir, ot, a, u, lp, sp, tif, tp, sl, ref, legs).
|
|
129
105
|
*/
|
|
130
106
|
interface TradeItTradeConfigBase {
|
|
131
107
|
ticker: string;
|
|
@@ -140,6 +116,8 @@ interface TradeItSimpleTradeConfig extends TradeItTradeConfigBase {
|
|
|
140
116
|
action?: TradeAction;
|
|
141
117
|
amount?: number;
|
|
142
118
|
unit?: TradeUnit;
|
|
119
|
+
takeProfit?: TradeItExitTrigger;
|
|
120
|
+
stopLoss?: TradeItExitTrigger;
|
|
143
121
|
}
|
|
144
122
|
interface TradeItMultiLegTradeConfig extends TradeItTradeConfigBase {
|
|
145
123
|
tradeType: TradeType.MultiLeg;
|
|
@@ -219,4 +197,4 @@ interface UseTradeItReturn {
|
|
|
219
197
|
}
|
|
220
198
|
declare function useTradeIt(defaults?: UseTradeItOptions): UseTradeItReturn;
|
|
221
199
|
//#endregion
|
|
222
|
-
export { LegType, type OpenConnectOptions, type OpenTradeOptions, OrderDirection, OrderType, PositionEffect, TimeInForce, TradeAction, type TradeItConnectLaunch, type TradeItEvent, type TradeItEventType, type TradeItLaunch, TradeItModal, type TradeItModalAppearance, type TradeItModalProps, type TradeItMultiLegTradeConfig, type TradeItMultiLegTradeLegConfig, type TradeItSimpleTradeConfig, type TradeItTradeConfig, type TradeItTradeLaunch, type TradeLinkLegConfig, TradeLinkParam, TradeType, TradeUnit, type UseTradeItOptions, getTradeItErrorMessage, getUrlOrigin, isTradeItEvent, resolveLaunchUrl, useTradeIt };
|
|
200
|
+
export { LegType, type OpenConnectOptions, type OpenTradeOptions, OrderDirection, OrderType, PositionEffect, TimeInForce, TradeAction, type TradeItConnectLaunch, type TradeItEvent, type TradeItEventType, type TradeItExitTrigger, type TradeItLaunch, TradeItModal, type TradeItModalAppearance, type TradeItModalProps, type TradeItMultiLegTradeConfig, type TradeItMultiLegTradeLegConfig, type TradeItSimpleTradeConfig, type TradeItTradeConfig, type TradeItTradeLaunch, type TradeLinkLegConfig, TradeLinkParam, TradeType, TradeUnit, TriggerUnit, type UseTradeItOptions, getTradeItErrorMessage, getUrlOrigin, isTradeItEvent, resolveLaunchUrl, useTradeIt };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import * as react0 from "react";
|
|
2
|
-
import { z } from "zod";
|
|
3
2
|
|
|
4
3
|
//#region ../../lib/types/src/enums/trading.enums.d.ts
|
|
5
4
|
declare enum TradeAction {
|
|
@@ -19,6 +18,7 @@ declare enum OrderType {
|
|
|
19
18
|
declare enum OrderDirection {
|
|
20
19
|
Debit = "debit",
|
|
21
20
|
Credit = "credit",
|
|
21
|
+
Even = "even",
|
|
22
22
|
}
|
|
23
23
|
declare enum TimeInForce {
|
|
24
24
|
Day = "day",
|
|
@@ -30,6 +30,15 @@ declare enum TradeUnit {
|
|
|
30
30
|
Dollars = "dollars",
|
|
31
31
|
Shares = "shares",
|
|
32
32
|
}
|
|
33
|
+
/** How an exit trigger (take-profit / stop-loss) value is expressed */
|
|
34
|
+
declare enum TriggerUnit {
|
|
35
|
+
/** An absolute price level */
|
|
36
|
+
Price = "$",
|
|
37
|
+
/** A percentage offset from the entry price */
|
|
38
|
+
Percent = "%",
|
|
39
|
+
}
|
|
40
|
+
/** Which exit an attached trigger represents */
|
|
41
|
+
|
|
33
42
|
declare enum LegType {
|
|
34
43
|
Option = "option",
|
|
35
44
|
Equity = "equity",
|
|
@@ -38,94 +47,61 @@ declare enum TradeType {
|
|
|
38
47
|
Simple = 0,
|
|
39
48
|
MultiLeg = 1,
|
|
40
49
|
}
|
|
41
|
-
//#endregion
|
|
42
|
-
//#region ../../lib/types/src/schemas/trade-link.schemas.d.ts
|
|
43
50
|
/**
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
declare const zTradeLinkLegConfig: z.ZodObject<Omit<{
|
|
47
|
-
type: z.ZodNativeEnum<typeof LegType>;
|
|
48
|
-
action: z.ZodNativeEnum<typeof TradeAction>;
|
|
49
|
-
position_effect: z.ZodNullable<z.ZodNativeEnum<typeof PositionEffect>>;
|
|
50
|
-
occ: z.ZodNullable<z.ZodString>;
|
|
51
|
-
quantity: z.ZodNumber;
|
|
52
|
-
execution_price: z.ZodNullable<z.ZodObject<{
|
|
53
|
-
amount: z.ZodNumber;
|
|
54
|
-
currency: z.ZodString;
|
|
55
|
-
}, "strip", z.ZodTypeAny, {
|
|
56
|
-
amount: number;
|
|
57
|
-
currency: string;
|
|
58
|
-
}, {
|
|
59
|
-
amount: number;
|
|
60
|
-
currency: string;
|
|
61
|
-
}>>;
|
|
62
|
-
}, "execution_price">, "strip", z.ZodTypeAny, {
|
|
63
|
-
type: LegType;
|
|
64
|
-
action: TradeAction;
|
|
65
|
-
position_effect: PositionEffect | null;
|
|
66
|
-
occ: string | null;
|
|
67
|
-
quantity: number;
|
|
68
|
-
}, {
|
|
69
|
-
type: LegType;
|
|
70
|
-
action: TradeAction;
|
|
71
|
-
position_effect: PositionEffect | null;
|
|
72
|
-
occ: string | null;
|
|
73
|
-
quantity: number;
|
|
74
|
-
}>;
|
|
75
|
-
/**
|
|
76
|
-
* Full Trade Link Config - stored in database as JSONB
|
|
77
|
-
* Supports both simple trades and multi-leg options trades
|
|
51
|
+
* A brokerage-reported option lifecycle event. Rows carrying an event describe
|
|
52
|
+
* what happened to a contract, so `action` is not meaningful on them.
|
|
78
53
|
*/
|
|
79
54
|
//#endregion
|
|
80
|
-
//#region
|
|
81
|
-
type
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Short query parameter keys for trade link URLs
|
|
92
|
-
*/
|
|
55
|
+
//#region ../trade-it-core/src/types.d.ts
|
|
56
|
+
type TradeItEventType = 'tradeit.ready' | 'tradeit.close_requested' | 'tradeit.brokerage_connected' | 'tradeit.trade_submitted' | 'tradeit.trade_executed' | 'tradeit.error' | 'tradeit.login_required';
|
|
57
|
+
interface TradeItEvent<TPayload = Record<string, unknown>> {
|
|
58
|
+
source: 'tradeit';
|
|
59
|
+
version: 1;
|
|
60
|
+
type: TradeItEventType;
|
|
61
|
+
payload?: TPayload;
|
|
62
|
+
}
|
|
63
|
+
type TradeItMode = 'connect' | 'trade';
|
|
64
|
+
/** Compact query keys accepted by Trade It trade URLs. */
|
|
93
65
|
declare enum TradeLinkParam {
|
|
94
66
|
TradeType = "tt",
|
|
95
|
-
// s (simple), m (multi_leg)
|
|
96
67
|
Action = "t",
|
|
97
|
-
|
|
68
|
+
Direction = "dir",
|
|
98
69
|
OrderType = "ot",
|
|
99
|
-
// m, l, st, sl
|
|
100
70
|
Amount = "a",
|
|
101
|
-
// number
|
|
102
71
|
Unit = "u",
|
|
103
|
-
// d, s
|
|
104
72
|
LimitPrice = "lp",
|
|
105
|
-
// number
|
|
106
73
|
StopPrice = "sp",
|
|
107
|
-
// number
|
|
108
74
|
TimeInForce = "tif",
|
|
109
|
-
|
|
75
|
+
TakeProfit = "tp",
|
|
76
|
+
StopLoss = "sl",
|
|
110
77
|
UtmReferred = "ref",
|
|
111
|
-
// string
|
|
112
78
|
Legs = "legs",
|
|
113
79
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
type
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
80
|
+
/** Canonical snake_case leg shape used by Trade Link APIs. */
|
|
81
|
+
interface TradeLinkLegConfig {
|
|
82
|
+
type: LegType;
|
|
83
|
+
action: TradeAction;
|
|
84
|
+
position_effect: PositionEffect | null;
|
|
85
|
+
occ: string | null;
|
|
86
|
+
quantity: number;
|
|
87
|
+
}
|
|
88
|
+
/** User-facing camelCase leg shape accepted by the embedded SDK. */
|
|
89
|
+
interface TradeItMultiLegTradeLegConfig {
|
|
90
|
+
type?: LegType;
|
|
91
|
+
action?: TradeAction;
|
|
92
|
+
positionEffect?: PositionEffect | null;
|
|
93
|
+
occ?: string | null;
|
|
94
|
+
quantity?: number;
|
|
95
|
+
}
|
|
96
|
+
/** Attached take-profit or stop-loss trigger. */
|
|
97
|
+
interface TradeItExitTrigger {
|
|
98
|
+
value: number;
|
|
99
|
+
unit: '$' | '%';
|
|
122
100
|
}
|
|
123
|
-
type TradeItMode = 'connect' | 'trade';
|
|
124
|
-
type TradeItMultiLegTradeLegConfig = Partial<Camelize<TradeLinkLegConfig>>;
|
|
125
101
|
/**
|
|
126
102
|
* Query params accepted by Trade It's /t/[ticker] page.
|
|
127
103
|
* User-facing config uses descriptive keys; core converts them to the short-key
|
|
128
|
-
* query format used by the page parser (tt, t, ot, a, u, lp, sp, tif, ref, legs).
|
|
104
|
+
* query format used by the page parser (tt, t, dir, ot, a, u, lp, sp, tif, tp, sl, ref, legs).
|
|
129
105
|
*/
|
|
130
106
|
interface TradeItTradeConfigBase {
|
|
131
107
|
ticker: string;
|
|
@@ -140,6 +116,8 @@ interface TradeItSimpleTradeConfig extends TradeItTradeConfigBase {
|
|
|
140
116
|
action?: TradeAction;
|
|
141
117
|
amount?: number;
|
|
142
118
|
unit?: TradeUnit;
|
|
119
|
+
takeProfit?: TradeItExitTrigger;
|
|
120
|
+
stopLoss?: TradeItExitTrigger;
|
|
143
121
|
}
|
|
144
122
|
interface TradeItMultiLegTradeConfig extends TradeItTradeConfigBase {
|
|
145
123
|
tradeType: TradeType.MultiLeg;
|
|
@@ -219,4 +197,4 @@ interface UseTradeItReturn {
|
|
|
219
197
|
}
|
|
220
198
|
declare function useTradeIt(defaults?: UseTradeItOptions): UseTradeItReturn;
|
|
221
199
|
//#endregion
|
|
222
|
-
export { LegType, type OpenConnectOptions, type OpenTradeOptions, OrderDirection, OrderType, PositionEffect, TimeInForce, TradeAction, type TradeItConnectLaunch, type TradeItEvent, type TradeItEventType, type TradeItLaunch, TradeItModal, type TradeItModalAppearance, type TradeItModalProps, type TradeItMultiLegTradeConfig, type TradeItMultiLegTradeLegConfig, type TradeItSimpleTradeConfig, type TradeItTradeConfig, type TradeItTradeLaunch, type TradeLinkLegConfig, TradeLinkParam, TradeType, TradeUnit, type UseTradeItOptions, getTradeItErrorMessage, getUrlOrigin, isTradeItEvent, resolveLaunchUrl, useTradeIt };
|
|
200
|
+
export { LegType, type OpenConnectOptions, type OpenTradeOptions, OrderDirection, OrderType, PositionEffect, TimeInForce, TradeAction, type TradeItConnectLaunch, type TradeItEvent, type TradeItEventType, type TradeItExitTrigger, type TradeItLaunch, TradeItModal, type TradeItModalAppearance, type TradeItModalProps, type TradeItMultiLegTradeConfig, type TradeItMultiLegTradeLegConfig, type TradeItSimpleTradeConfig, type TradeItTradeConfig, type TradeItTradeLaunch, type TradeLinkLegConfig, TradeLinkParam, TradeType, TradeUnit, TriggerUnit, type UseTradeItOptions, getTradeItErrorMessage, getUrlOrigin, isTradeItEvent, resolveLaunchUrl, useTradeIt };
|