Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trade] History Chart #1456

Merged
merged 58 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
fd0e66f
add history chart
GrandSchtroumpf Aug 28, 2024
5b6a3d6
add setter for disposable & recurring
GrandSchtroumpf Aug 29, 2024
221b0e6
write overlapping
GrandSchtroumpf Aug 29, 2024
869b50a
implement date range
GrandSchtroumpf Aug 29, 2024
3f4e7fd
better bounds
GrandSchtroumpf Aug 29, 2024
c92bafc
adjust bound for market
GrandSchtroumpf Aug 29, 2024
b67046a
fix overlapping price boundary
GrandSchtroumpf Aug 29, 2024
d467842
use local search in disposable
GrandSchtroumpf Aug 30, 2024
516872c
handle only one state in disposable
GrandSchtroumpf Aug 30, 2024
d702c2e
fix build
GrandSchtroumpf Aug 30, 2024
833aa81
Merge remote-tracking branch 'origin/main' into issue-#1448
GrandSchtroumpf Sep 4, 2024
874ca62
improve timeout
GrandSchtroumpf Sep 4, 2024
bb5e86f
fix disposable
GrandSchtroumpf Sep 4, 2024
9c0ea2b
set bounds based on data
GrandSchtroumpf Sep 4, 2024
dfd1910
fix tests
GrandSchtroumpf Sep 4, 2024
e232253
fix disposable create
GrandSchtroumpf Sep 4, 2024
1fb4f51
fix disposable emptyOrder
GrandSchtroumpf Sep 4, 2024
3df6e8a
add label on loading icon
GrandSchtroumpf Sep 5, 2024
1269520
don't use tradeCtx for chart
GrandSchtroumpf Sep 5, 2024
3f10647
move Layout to each page
GrandSchtroumpf Sep 5, 2024
eca4b43
rename TradeChart to StrategyChart
GrandSchtroumpf Sep 5, 2024
77cb315
implement chart in edit
GrandSchtroumpf Sep 5, 2024
b1ff178
Merge remote-tracking branch 'origin/main' into issue-#1448
GrandSchtroumpf Sep 5, 2024
d550e21
fix overlapping edit range chart
GrandSchtroumpf Sep 5, 2024
5d515ad
add icons
GrandSchtroumpf Sep 6, 2024
5c93615
setup edit budget for disposable & recurring
GrandSchtroumpf Sep 6, 2024
2e46691
add legend
GrandSchtroumpf Sep 6, 2024
b1597a1
edit budget overlapping
GrandSchtroumpf Sep 6, 2024
2fd1e78
verify if readonly exists
GrandSchtroumpf Sep 9, 2024
4971192
add activity
GrandSchtroumpf Sep 9, 2024
75e875c
add price range for activity
GrandSchtroumpf Sep 9, 2024
32d652f
readonly chart for overlapping
GrandSchtroumpf Sep 9, 2024
28cdc81
reset settings with default price
GrandSchtroumpf Sep 9, 2024
5bd7d90
Use market Price as ref is on order
GrandSchtroumpf Sep 9, 2024
3c05aa8
disable route type in activity
GrandSchtroumpf Sep 9, 2024
24ee312
improve default values
GrandSchtroumpf Sep 9, 2024
e49f54a
create default orders
GrandSchtroumpf Sep 10, 2024
88d67ee
improve price display
GrandSchtroumpf Sep 10, 2024
62f1206
updat multiplier
GrandSchtroumpf Sep 10, 2024
f03e915
Merge remote-tracking branch 'origin/main' into issue-#1448
GrandSchtroumpf Sep 10, 2024
6bd629a
fix after merge
GrandSchtroumpf Sep 10, 2024
bc8db5c
fix date range filtering in activity
GrandSchtroumpf Sep 10, 2024
af3c66b
[CI] Update Screenshots
GrandSchtroumpf Sep 10, 2024
5ebcd1e
change size of the font
GrandSchtroumpf Sep 11, 2024
790cdf0
[CI] Update Screenshots
GrandSchtroumpf Sep 11, 2024
f88004b
round to 4 decimals
GrandSchtroumpf Sep 11, 2024
392b399
round market price to 4 decimals
GrandSchtroumpf Sep 11, 2024
f8ff4b3
move chart disposable
GrandSchtroumpf Sep 11, 2024
01e108b
Merge remote-tracking branch 'origin/main' into issue-#1448
GrandSchtroumpf Sep 11, 2024
15cee6f
[CI] Update Screenshots
GrandSchtroumpf Sep 11, 2024
4b16ba6
request changes
GrandSchtroumpf Sep 11, 2024
09c89ef
move chart to strategies/common
GrandSchtroumpf Sep 11, 2024
21c6710
max width in edit price
GrandSchtroumpf Sep 11, 2024
5dba97d
fix height of not found
GrandSchtroumpf Sep 11, 2024
4e7818e
Merge remote-tracking branch 'origin/main' into issue-#1448
GrandSchtroumpf Sep 11, 2024
a065a3a
[CI] Update Screenshots
GrandSchtroumpf Sep 11, 2024
2c9b3e3
remove check on data length
GrandSchtroumpf Sep 12, 2024
a5c3995
[CI] Update Screenshots
GrandSchtroumpf Sep 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/screenshots/strategy/overlapping/Overlapping/deposit/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified e2e/screenshots/strategy/overlapping/Overlapping/withdraw/form.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/assets/icons/lock.svg
3 changes: 3 additions & 0 deletions src/components/activity/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export interface ActivitySearchParams extends Partial<PaginationParams> {
actions?: ActivityAction[];
start?: Date;
end?: Date;
// This is only for StrategyPageParams, but if I don't implement it here the build breaks
priceStart?: string;
priceEnd?: string;
}
export const activityActionName: Record<ActivityAction, string> = {
create: 'Create',
Expand Down
1 change: 1 addition & 0 deletions src/components/common/CarbonLogoLoading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const CarbonLogoLoading = ({
fill="none"
xmlns="http://www.w3.org/2000/svg"
className={className}
aria-label="Loading"
>
<path
style={{
Expand Down
30 changes: 25 additions & 5 deletions src/components/simulator/input/d3Chart/D3ChartCandlesticks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ import {
scaleBand,
D3ChartSettings,
} from 'libs/d3';
import { SimulatorType } from 'libs/routing/routes/sim';
import { useMemo } from 'react';
import { prettifyNumber } from 'utils/helpers';
import { Candlesticks } from 'components/simulator/input/d3Chart/Candlesticks';
import { D3ChartDisposable } from './recurring/D3ChartDisposable';
import { TradeTypes } from 'libs/routing/routes/trade';

export type ChartPrices<T = string> = {
buy: { min: T; max: T };
Expand All @@ -32,8 +33,10 @@ export interface D3ChartCandlesticksProps {
onDragEnd?: OnPriceUpdates;
isLimit?: { buy: boolean; sell: boolean };
dms: D3ChartSettings;
type: SimulatorType;
type: TradeTypes;
overlappingSpread?: string;
overlappingMarketPrice?: number;
readonly?: boolean;
}

export const D3ChartCandlesticks = (props: D3ChartCandlesticksProps) => {
Expand All @@ -48,6 +51,8 @@ export const D3ChartCandlesticks = (props: D3ChartCandlesticksProps) => {
dms,
type,
overlappingSpread,
overlappingMarketPrice,
readonly,
} = props;

const xScale = useMemo(
Expand All @@ -72,7 +77,9 @@ export const D3ChartCandlesticks = (props: D3ChartCandlesticksProps) => {
<D3YAxisRight
ticks={y.ticks}
dms={dms}
formatter={(value) => prettifyNumber(value)}
formatter={(value) => {
return prettifyNumber(value, { decimals: 100, abbreviate: true });
}}
/>
<XAxis xScale={xScale} dms={dms} />
{marketPrice && (
Expand All @@ -81,11 +88,23 @@ export const D3ChartCandlesticks = (props: D3ChartCandlesticksProps) => {
color="white"
y={y.scale(marketPrice)}
lineProps={{ strokeDasharray: 2 }}
label={prettifyNumber(marketPrice ?? '')}
label={prettifyNumber(marketPrice ?? '', { decimals: 4 })}
/>
)}
{type === 'disposable' && isLimit && (
<D3ChartDisposable
readonly={readonly}
yScale={y.scale}
isLimit={isLimit}
dms={dms}
prices={prices}
onDragEnd={onDragEnd}
onPriceUpdates={onPriceUpdates}
/>
)}
{type === 'recurring' && isLimit && (
<D3ChartRecurring
readonly={readonly}
yScale={y.scale}
isLimit={isLimit}
dms={dms}
Expand All @@ -96,12 +115,13 @@ export const D3ChartCandlesticks = (props: D3ChartCandlesticksProps) => {
)}
{type === 'overlapping' && overlappingSpread !== undefined && (
<D3ChartOverlapping
readonly={readonly}
yScale={y.scale}
dms={dms}
prices={prices}
onDragEnd={onDragEnd}
onPriceUpdates={onPriceUpdates}
marketPrice={data[0].open ?? 0}
marketPrice={overlappingMarketPrice ?? data[0].open ?? 0}
spread={Number(overlappingSpread)}
/>
)}
Expand Down
31 changes: 30 additions & 1 deletion src/components/simulator/input/d3Chart/D3ChartHandleLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ interface Props {
label?: string;
lineProps?: SVGProps<SVGLineElement>;
handleClassName?: string;
readonly?: boolean;
isDraggable?: boolean;
}

Expand All @@ -25,6 +26,7 @@ export const D3ChartHandleLine = ({ lineProps, ...props }: Props) => {
color,
y = 0,
label,
readonly,
isDraggable,
handleClassName,
} = props;
Expand All @@ -43,7 +45,10 @@ export const D3ChartHandleLine = ({ lineProps, ...props }: Props) => {
/>
<g
transform={`translate(${lineWidth},-${handleDms.height / 2})`}
className={cn(isDraggable && 'cursor-ns-resize', handleClassName)}
className={cn(
isDraggable && !readonly && 'cursor-ns-resize',
handleClassName
)}
>
<rect y={y} {...handleDms} fill={color} rx={4} />
{label && (
Expand All @@ -52,6 +57,30 @@ export const D3ChartHandleLine = ({ lineProps, ...props }: Props) => {
</text>
)}
</g>
{readonly && (
<g
className="readonly"
transform={`translate(${lineWidth - 20}, ${y - 8})`}
>
<circle cx="8.41406" cy="8.28931" r="8" fill="#404040" />
<rect
x="5.49805"
y="7.87268"
width="5.83333"
height="4.16667"
rx="1"
stroke="white"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M6.33008 6.62264C6.33008 5.47205 7.26282 4.53931 8.41341 4.53931V4.53931C9.564 4.53931 10.4967 5.47205 10.4967 6.62264V7.87264H6.33008V6.62264Z"
stroke="white"
strokeLinecap="round"
strokeLinejoin="round"
/>
</g>
)}
</g>
);
};
7 changes: 5 additions & 2 deletions src/components/simulator/input/d3Chart/D3ChartRect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ import { cn } from 'utils/helpers';
interface RectProps extends SVGProps<SVGRectElement> {
selector: string;
isDragging: boolean;
readonly?: boolean;
}
export const D3ChartRect = ({ selector, isDragging, ...props }: RectProps) => {
export const D3ChartRect = (props: RectProps) => {
const { selector, isDragging, readonly, ...attr } = props;
return (
<rect
className={cn(selector, {
'cursor-grab': !isDragging,
'cursor-grabbing': isDragging,
'cursor-auto': readonly,
})}
fillOpacity={0.15}
{...props}
{...attr}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Props = Pick<
yScale: ScaleLinear<number, number>;
marketPrice?: number;
spread: number;
readonly?: boolean;
};

export const D3ChartOverlapping = (props: Props) => {
Expand All @@ -37,6 +38,7 @@ export const D3ChartOverlapping = (props: Props) => {
yScale,
prices,
marketPrice,
readonly,
onPriceUpdates,
onDragEnd,
spread,
Expand Down Expand Up @@ -208,36 +210,41 @@ export const D3ChartOverlapping = (props: Props) => {
dms={dms}
color="var(--sell)"
lineProps={{ strokeDasharray: 2 }}
label={prettifyNumber(prices.sell.min ?? '')}
label={prettifyNumber(prices.sell.min ?? '', { decimals: 4 })}
readonly={readonly}
/>
<D3ChartHandleLine
selector={selectorHandleBuyMax}
handleClassName="opacity-40"
dms={dms}
color="var(--buy)"
lineProps={{ strokeDasharray: 2 }}
label={prettifyNumber(prices.buy.max ?? '')}
label={prettifyNumber(prices.buy.max ?? '', { decimals: 4 })}
readonly={readonly}
/>
<D3ChartOverlappingHandle
selector={selectorHandleBuyMin}
dms={dms}
onDrag={onDragBuy}
onDragEnd={onDragEndBuy}
color="var(--buy)"
label={prettifyNumber(prices.buy.min ?? '')}
label={prettifyNumber(prices.buy.min ?? '', { decimals: 4 })}
readonly={readonly}
/>
<D3ChartOverlappingHandle
selector={selectorHandleSellMax}
dms={dms}
onDrag={onDragSell}
onDragEnd={onDragEndSell}
color="var(--sell)"
label={prettifyNumber(prices.sell.max ?? '')}
label={prettifyNumber(prices.sell.max ?? '', { decimals: 4 })}
readonly={readonly}
/>
<D3ChartOverlappingRangeGroup
dms={dms}
onDrag={onDragRect}
onDragEnd={onDragEndRect}
readonly={readonly}
/>
<D3ChartPriceOutOfScale
type="buy"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface Props {
onDragEnd?: (y: number) => void;
color: string;
label?: string;
readonly?: boolean;
}

export const D3ChartOverlappingHandle = ({
Expand All @@ -22,21 +23,30 @@ export const D3ChartOverlappingHandle = ({
onDragEnd,
...props
}: Props) => {
const selection = getSelector(props.selector);
const isSelectable = useSelectable(props.selector);

const handleDrag = drag()
.subject(() => ({
y: Number(selection.select('line').attr('y1')),
}))
.on('start', ({ y }) => onDragStart?.(y))
.on('drag', ({ y }) => onDrag?.(y))
.on('end', ({ y }) => onDragEnd?.(y));

useEffect(() => {
if (props.readonly) return;
const selection = getSelector(props.selector);
const handleDrag = drag()
.subject(() => ({
y: Number(selection.select('line').attr('y1')),
}))
.on('start', ({ y }) => onDragStart?.(y))
.on('drag', ({ y }) => onDrag?.(y))
.on('end', ({ y }) => onDragEnd?.(y));

if (!isSelectable) return;

handleDrag(selection as Selection<Element, unknown, any, any>);
}, [isSelectable, handleDrag, selection]);
}, [
isSelectable,
onDrag,
onDragEnd,
onDragStart,
props.readonly,
props.selector,
]);

return <D3ChartHandleLine {...props} isDraggable />;
return <D3ChartHandleLine {...props} isDraggable={!props.readonly} />;
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { D3ChartSettings } from 'libs/d3/types';
import { useEffect, useState } from 'react';

interface Props {
readonly?: boolean;
dms: D3ChartSettings;
onDragStart?: (y: number, y2: number) => void;
onDrag?: (y: number, y2: number) => void;
onDragEnd?: (y: number, y2: number) => void;
}

export const D3ChartOverlappingRangeGroup = ({
readonly,
dms,
onDragStart,
onDrag,
Expand Down Expand Up @@ -52,19 +54,21 @@ export const D3ChartOverlappingRangeGroup = ({
});

useEffect(() => {
if (!isSelectable || !onDrag) return;
if (readonly || !isSelectable || !onDrag) return;
handleDrag(selection as Selection<Element, unknown, any, any>);
}, [isSelectable, handleDrag, onDrag, selection]);
}, [isSelectable, handleDrag, onDrag, selection, readonly]);

return (
<g className={selector}>
<D3ChartRect
readonly={readonly}
selector={selectorRectBuy}
isDragging={isDragging}
width={dms.boundedWidth}
fill="var(--buy)"
/>
<D3ChartRect
readonly={readonly}
selector={selectorRectSell}
isDragging={isDragging}
width={dms.boundedWidth}
Expand Down
Loading