Skip to content

Commit

Permalink
fix(trading): ensure notional and sizePct are set when setting size a…
Browse files Browse the repository at this point in the history
…nd price from orderbook
  • Loading branch information
oldalbus committed Dec 19, 2024
1 parent 09703ca commit c42ff47
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 26 deletions.
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/derivative/limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { useTicketContext } from '../ticket-context';
import { SubmitButton } from '../elements/submit-button';
import { useT } from '../../../lib/use-t';
import { Datagrid } from '../elements/datagrid';
import { TicketEventUpdater } from '../ticket-events';
import { DerivativeLimitTicketEventUpdater } from '../ticket-events';
import { type FormProps } from './ticket';
import { Feedback } from './feedback';
import * as Fields from '../fields';
Expand Down Expand Up @@ -61,7 +61,7 @@ export const Limit = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<DerivativeLimitTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/derivative/market.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { type FormFieldsMarket, useMarketSchema } from '../schemas';
import { TicketTypeSelect } from '../ticket-type-select';
import { type FormProps } from './ticket';

import { TicketEventUpdater } from '../ticket-events';
import { DerivativeMarketTicketEventUpdater } from '../ticket-events';
import { Datagrid } from '../elements/datagrid';
import { useTicketContext } from '../ticket-context';
import { SubmitButton } from '../elements/submit-button';
Expand Down Expand Up @@ -60,7 +60,7 @@ export const Market = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<DerivativeMarketTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/derivative/stop-limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
FormGridCol,
} from '../elements/form';
import { type FormFieldsStopLimit, useStopLimitSchema } from '../schemas';
import { TicketEventUpdater } from '../ticket-events';
import { DerivativeLimitTicketEventUpdater } from '../ticket-events';
import { TicketTypeSelect } from '../ticket-type-select';
import { type FormProps } from './ticket';
import { useTicketContext } from '../ticket-context';
Expand Down Expand Up @@ -78,7 +78,7 @@ export const StopLimit = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<DerivativeLimitTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/derivative/stop-market.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { type FormFieldsStopMarket, useStopMarketSchema } from '../schemas';
import { TicketTypeSelect } from '../ticket-type-select';
import { type FormProps } from './ticket';
import { TicketEventUpdater } from '../ticket-events';
import { DerivativeMarketTicketEventUpdater } from '../ticket-events';
import { useTicketContext } from '../ticket-context';
import { SubmitButton } from '../elements/submit-button';
import { useT } from '../../../lib/use-t';
Expand Down Expand Up @@ -81,7 +81,7 @@ export const StopMarket = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<DerivativeMarketTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
2 changes: 2 additions & 0 deletions apps/trading/components/ticket/derivative/ticket.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const Ticket = ({ market }: { market: MarketInfo }) => {
};

export type FormProps = {
type: TicketType;
side: Side;
onSideChange: (value: Side) => void;
onTypeChange: (value: TicketType) => void;
Expand All @@ -69,6 +70,7 @@ export const TicketDefaultSwitch = () => {
const [type, setType] = useTicketType();

const props: FormProps = {
type,
side,
onSideChange: (value: Side) => setSide(value),
onTypeChange: (value: TicketType) => setType(value),
Expand Down
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/spot/limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useTicketContext } from '../ticket-context';
import { SubmitButton } from '../elements/submit-button';
import { useT } from '../../../lib/use-t';
import { Datagrid } from '../elements/datagrid';
import { TicketEventUpdater } from '../ticket-events';
import { SpotLimitTicketEventUpdater } from '../ticket-events';
import { Feedback } from './feedback';

import * as Fields from '../fields';
Expand Down Expand Up @@ -62,7 +62,7 @@ export const Limit = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<SpotLimitTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/spot/market.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { type FormFieldsMarket, useMarketSchema } from '../schemas';
import { TicketTypeSelect } from '../ticket-type-select';
import { type FormProps } from './ticket';
import { useTicketContext } from '../ticket-context';
import { TicketEventUpdater } from '../ticket-events';
import { SpotMarketTicketEventUpdater } from '../ticket-events';
import { Feedback } from './feedback';
import { Datagrid } from '../elements/datagrid';

Expand Down Expand Up @@ -60,7 +60,7 @@ export const Market = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<SpotMarketTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
4 changes: 2 additions & 2 deletions apps/trading/components/ticket/spot/stop-limit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
FormGrid,
} from '../elements/form';
import { type FormFieldsStopLimit, useStopLimitSchema } from '../schemas';
import { TicketEventUpdater } from '../ticket-events';
import { SpotLimitTicketEventUpdater } from '../ticket-events';
import { TicketTypeSelect } from '../ticket-type-select';
import { type FormProps } from './ticket';
import { useTicketContext } from '../ticket-context';
Expand Down Expand Up @@ -75,7 +75,7 @@ export const StopLimit = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<SpotLimitTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
6 changes: 3 additions & 3 deletions apps/trading/components/ticket/spot/stop-market.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { FormProvider, useForm } from 'react-hook-form';
import uniqueId from 'lodash/uniqueId';
import { zodResolver } from '@hookform/resolvers/zod';
import { addDays } from 'date-fns';
import BigNumber from 'bignumber.js';

import {
OrderType,
Expand All @@ -21,7 +22,7 @@ import {
import { type FormFieldsStopMarket, useStopMarketSchema } from '../schemas';
import { TicketTypeSelect } from '../ticket-type-select';
import { type FormProps } from './ticket';
import { TicketEventUpdater } from '../ticket-events';
import { SpotMarketTicketEventUpdater } from '../ticket-events';
import { useTicketContext } from '../ticket-context';
import { SubmitButton } from '../elements/submit-button';
import { Datagrid } from '../elements/datagrid';
Expand All @@ -33,7 +34,6 @@ import * as Fields from '../fields';
import * as Data from '../info';
import * as SpotFields from './fields';
import * as utils from '../utils';
import BigNumber from 'bignumber.js';

export const StopMarket = (props: FormProps) => {
const t = useT();
Expand Down Expand Up @@ -77,7 +77,7 @@ export const StopMarket = (props: FormProps) => {

return (
<FormProvider {...form}>
<TicketEventUpdater />
<SpotMarketTicketEventUpdater />
<Form
onSubmit={form.handleSubmit((fields) => {
const reference = `${pubKey}-${Date.now()}-${uniqueId()}`;
Expand Down
27 changes: 23 additions & 4 deletions apps/trading/components/ticket/ticket-events.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
import { useTicketEvents } from './use-ticket-events';
import {
useDerivativeLimitTicketEvents,
useDerivativeMarketTicketEvents,
useSpotLimitTicketEvents,
useSpotMarketTicketEvents,
} from './use-ticket-events';

/** Render the useTicketEvents hook */
export const TicketEventUpdater = () => {
useTicketEvents();
export const DerivativeLimitTicketEventUpdater = () => {
useDerivativeLimitTicketEvents();
return null;
};

export const DerivativeMarketTicketEventUpdater = () => {
useDerivativeMarketTicketEvents();
return null;
};

export const SpotLimitTicketEventUpdater = () => {
useSpotLimitTicketEvents();
return null;
};

export const SpotMarketTicketEventUpdater = () => {
useSpotMarketTicketEvents();
return null;
};
Loading

0 comments on commit c42ff47

Please sign in to comment.