@@ -12,7 +12,8 @@ import { getDecimalsFromTick, usdFormatter } from '~/utils';
12
12
13
13
type Inputs = {
14
14
direction : 'Buy' | 'Sell' ;
15
- type : 'Market' | 'Limit' ;
15
+ type : 'Market' | 'Limit' | 'StopLimit' ;
16
+ triggerPrice ?: string ;
16
17
price : string ;
17
18
quantity : string ;
18
19
} ;
@@ -39,6 +40,7 @@ export const CreateOrder: FC<{
39
40
order_type : match ( watch ( 'type' , 'Market' ) )
40
41
. with ( 'Market' , ( ) => OrderType . MARKET )
41
42
. with ( 'Limit' , ( ) => OrderType . LIMIT )
43
+ . with ( 'StopLimit' , ( ) => OrderType . STOP_LIMIT )
42
44
. exhaustive ( ) ,
43
45
order_quantity : watch ( 'quantity' , undefined ) ,
44
46
order_price : watch ( 'price' , undefined )
@@ -102,8 +104,43 @@ export const CreateOrder: FC<{
102
104
< select { ...register ( 'type' ) } className = "flex flex-1 py-2 text-center font-bold" >
103
105
< option value = "Market" > Market</ option >
104
106
< option value = "Limit" > Limit</ option >
107
+ < option value = "StopLimit" > Stop Limit</ option >
105
108
</ select >
106
109
110
+ < label
111
+ className = { `flex-col ${ match ( watch ( 'type' , 'Market' ) )
112
+ . with ( 'StopLimit' , ( ) => 'flex' )
113
+ . otherwise ( ( ) => 'hidden' ) } `}
114
+ >
115
+ < span className = "font-bold font-size-5" > Trigger Price ({ quote } )</ span >
116
+ < Controller
117
+ name = "triggerPrice"
118
+ control = { control }
119
+ rules = { {
120
+ validate : {
121
+ custom : async ( _ , data ) => {
122
+ const errors = await getValidationErrors ( data , symbol . symbol , helper . validator ) ;
123
+ return errors ?. trigger_price != null ? errors . trigger_price . message : true ;
124
+ }
125
+ }
126
+ } }
127
+ render = { ( { field : { name, onBlur, onChange } , fieldState : { error } } ) => (
128
+ < >
129
+ < TokenInput
130
+ className = { `${ error != null ? 'border-[var(--color-red)]' : '' } ` }
131
+ decimals = { quoteDecimals }
132
+ placeholder = "Price"
133
+ name = { name }
134
+ onBlur = { onBlur }
135
+ onChange = { onChange }
136
+ hasError = { error != null }
137
+ />
138
+ { renderError ( error ) }
139
+ </ >
140
+ ) }
141
+ />
142
+ </ label >
143
+
107
144
< label className = "flex flex-col" >
108
145
< span className = "font-bold font-size-5" > Price ({ quote } )</ span >
109
146
< Controller
@@ -213,8 +250,10 @@ function getInput(data: Inputs, symbol: string): OrderEntity {
213
250
order_type : match ( data . type )
214
251
. with ( 'Market' , ( ) => OrderType . MARKET )
215
252
. with ( 'Limit' , ( ) => OrderType . LIMIT )
253
+ . with ( 'StopLimit' , ( ) => OrderType . STOP_LIMIT )
216
254
. exhaustive ( ) ,
217
255
order_price : data . price ,
218
- order_quantity : data . quantity
256
+ order_quantity : data . quantity ,
257
+ trigger_price : data . triggerPrice
219
258
} ;
220
259
}
0 commit comments