Browse Source

Limit quantity to increments of 100

Bitmex only allows buy/sell orders in increments of 100 USD. In order to
simplify the hedging calculation for the maker we keep quantity the same
as Bitmex.
no-buy-button-while-setting-up-cfd
rishflab 3 years ago
parent
commit
744968a630
  1. 9
      taker-frontend/src/components/Trade.test.tsx
  2. 26
      taker-frontend/src/components/Trade.tsx

9
taker-frontend/src/components/Trade.test.tsx

@ -0,0 +1,9 @@
import { isEvenlyDivisible } from "./Trade";
it("1200 is evenly divisible by 100.0", () => {
expect(isEvenlyDivisible(1200, 100.0)).toBe(true);
});
it("233.3 is not evenly divisible by 100.0", () => {
expect(isEvenlyDivisible(233.3, 100.0)).toBe(false);
});

26
taker-frontend/src/components/Trade.tsx

@ -112,9 +112,11 @@ export default function Trade({
const quantityTooHigh = maxQuantity < parse(quantity); const quantityTooHigh = maxQuantity < parse(quantity);
const quantityTooLow = minQuantity > parse(quantity); const quantityTooLow = minQuantity > parse(quantity);
const quantityGreaterZero = parse(quantity) > 0; const quantityGreaterZero = parse(quantity) > 0;
const quantityIncrement = 100;
const quantityIsEvenlyDivisibleByIncrement = isEvenlyDivisible(parse(quantity), quantityIncrement);
const canSubmit = orderId && !isLongSubmitting && !balanceTooLow const canSubmit = orderId && !isLongSubmitting && !balanceTooLow
&& !quantityTooHigh && !quantityTooLow && quantityGreaterZero; && !quantityTooHigh && !quantityTooLow && quantityGreaterZero && quantityIsEvenlyDivisibleByIncrement;
let alertBox; let alertBox;
@ -130,6 +132,12 @@ export default function Trade({
description={"Please deposit more into you wallet."} description={"Please deposit more into you wallet."}
/>; />;
} }
if (!quantityIsEvenlyDivisibleByIncrement) {
alertBox = <AlertBox
title={`Quantity is not in increments of ${quantityIncrement}!`}
description={`Increment is ${quantityIncrement}`}
/>;
}
if (quantityTooHigh) { if (quantityTooHigh) {
alertBox = <AlertBox alertBox = <AlertBox
title={"Quantity too high!"} title={"Quantity too high!"}
@ -184,7 +192,13 @@ export default function Trade({
</Center> </Center>
</GridItem> </GridItem>
<GridItem colSpan={1}> <GridItem colSpan={1}>
<Quantity min={minQuantity} max={maxQuantity} quantity={quantity} onChange={onQuantityChange} /> <Quantity
min={minQuantity}
max={maxQuantity}
quantity={quantity}
onChange={onQuantityChange}
quantityIncrement={quantityIncrement}
/>
</GridItem> </GridItem>
<GridItem colSpan={1}> <GridItem colSpan={1}>
<Leverage leverage={leverage} /> <Leverage leverage={leverage} />
@ -276,10 +290,11 @@ interface QuantityProps {
min: number; min: number;
max: number; max: number;
quantity: string; quantity: string;
quantityIncrement: number;
onChange: any; onChange: any;
} }
function Quantity({ min, max, onChange, quantity }: QuantityProps) { function Quantity({ min, max, onChange, quantity, quantityIncrement }: QuantityProps) {
return ( return (
<FormControl id="quantity"> <FormControl id="quantity">
<FormLabel>Quantity</FormLabel> <FormLabel>Quantity</FormLabel>
@ -289,6 +304,7 @@ function Quantity({ min, max, onChange, quantity }: QuantityProps) {
min={min} min={min}
max={max} max={max}
default={min} default={min}
step={quantityIncrement}
onChange={onChange} onChange={onChange}
value={quantity} value={quantity}
> >
@ -345,3 +361,7 @@ function Margin({ margin }: MarginProps) {
</VStack> </VStack>
); );
} }
export function isEvenlyDivisible(numerator: number, divisor: number): boolean {
return (numerator % divisor === 0.0);
}

Loading…
Cancel
Save