Skip to content

Commit b6ee761

Browse files
committed
stop limit order
1 parent 895de6d commit b6ee761

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

app/components/CreateOrder.tsx

+41-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import { getDecimalsFromTick, usdFormatter } from '~/utils';
1212

1313
type Inputs = {
1414
direction: 'Buy' | 'Sell';
15-
type: 'Market' | 'Limit';
15+
type: 'Market' | 'Limit' | 'StopLimit';
16+
triggerPrice?: string;
1617
price: string;
1718
quantity: string;
1819
};
@@ -39,6 +40,7 @@ export const CreateOrder: FC<{
3940
order_type: match(watch('type', 'Market'))
4041
.with('Market', () => OrderType.MARKET)
4142
.with('Limit', () => OrderType.LIMIT)
43+
.with('StopLimit', () => OrderType.STOP_LIMIT)
4244
.exhaustive(),
4345
order_quantity: watch('quantity', undefined),
4446
order_price: watch('price', undefined)
@@ -102,8 +104,43 @@ export const CreateOrder: FC<{
102104
<select {...register('type')} className="flex flex-1 py-2 text-center font-bold">
103105
<option value="Market">Market</option>
104106
<option value="Limit">Limit</option>
107+
<option value="StopLimit">Stop Limit</option>
105108
</select>
106109

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+
107144
<label className="flex flex-col">
108145
<span className="font-bold font-size-5">Price ({quote})</span>
109146
<Controller
@@ -213,8 +250,10 @@ function getInput(data: Inputs, symbol: string): OrderEntity {
213250
order_type: match(data.type)
214251
.with('Market', () => OrderType.MARKET)
215252
.with('Limit', () => OrderType.LIMIT)
253+
.with('StopLimit', () => OrderType.STOP_LIMIT)
216254
.exhaustive(),
217255
order_price: data.price,
218-
order_quantity: data.quantity
256+
order_quantity: data.quantity,
257+
trigger_price: data.triggerPrice
219258
};
220259
}

0 commit comments

Comments
 (0)