react typescript, klinechart charting library. You need to access market data as here https://www.binance.com/ru/futures/DOGEUSDT
here is my code
import React, {useState, useEffect, ChangeEvent} from “react”;
import {
Badge, Box,
Button,
ButtonGroup,
Chip,
CircularProgress,
Grid,
Icon, IconButton, Skeleton, TextField,
Typography
} from “@mui/material”;
import ArrowUpwardRoundedIcon from ‘@mui/icons-material/ArrowUpwardRounded’;
import ArrowDownwardRoundedIcon from ‘@mui/icons-material/ArrowDownwardRounded’;
import {useAuthContext} from “…/…/AuthProvider/AuthProvider”;
import FormatPrice from “…/…/Common/FormatPrice”;
import {Order, readCandlesByTrade, readOrderByTrade, Trade, updateTrade} from “…/…/…/actions/cicap-diary-trades”;
import DataTable from “…/…/DataTable/DataTable”;
import {useSnackbar} from “notistack”;
import {CandleChart} from “…/CandleChart/CandleChart”;
import {TradeEntity} from “…/CandleChart/CandleChart.props”;
import {FormattedNumber} from “react-intl”;
import ImageIcon from “next/image”;
import {createTradeImage, deleteTradeImage, tradeImagesCollection, TradeImage} from “…/…/…/actions/cicap-diary-trades-images”;
const timezoneOffset = new Date().getTimezoneOffset() * 60;
interface SideTypeProps {
order: Order;
}
const SideType = ({order}: SideTypeProps) => {
let label = ‘’;
let color = ‘default’;
const icon = order?.side && ‘sell’ === order.side
? ArrowDownwardRoundedIcon
: ArrowUpwardRoundedIcon;
switch (order?.type) {
case ‘limit’:
label = ‘L’;
color = ‘success’
break;
case ‘market’:
label = ‘M’;
color = ‘warning’
break;
case ‘stop_market’:
label = ‘F’;
color = ‘primary’
break;
}
setWaiting(true);
readOrderByTrade(tradeId, diaryToken)
.then(data => {
setWaiting(false);
if (!data) return;
Assistant
To display real-time candles on the chart and calculate the percentage at the current price, you can use the Binance API to get the real-time data.
First, you need to install the WebSocket package:
npm install --save react-use-websocket
Then, import the useWebSocket hook from the package in the component where you want to use the real-time data:
User
<DataGrid
import {DataGrid} from "@mui/x-data-grid";
Добавить ограниченную высоту с красным скроллом на колонки
Assistant
To add a limited height with a red scrollbar in the DataGrid component from Material-UI, you need to update its style properties. You can pass the sx prop to the DataGrid component to provide custom styling.
Here's an example of how to set a limited height and a red scrollbar for the DataGrid component:
In those transactions where there is no closed order, you need to display real-time candles on the chart and calculate the percentage at the current price. This is necessary so that you can follow the transaction in real time. It is necessary that the chart reflects the current situation on the market, as here https://www.binance.com/ru/futures/DOGEUSDT
import { Options, WebSocketHook, JsonValue } from ‘./types’;
export declare const useWebSocket: <T extends JsonValue | null = JsonValue | null>(url: string | (() => string | Promise) | null, options?: Options, connect?: boolean) => WebSocketHook<T, MessageEvent | null>;
useWebSocket
import { useWebSocket } from 'react-use-websocket';
In your TradeDetails component, you can create a function to handle the real-time data received through WebSocket:
const handleRealTimeData = (data: any) => {
// Process the data and update the state accordingly
};
After that, you can use the useWebSocket hook in the TradeDetails component to get real-time data from the Binance API, and pass the handleRealTimeData function as the message handler:
In the handleRealTimeData function, you need to process the data according to your requirement and update the states, such as candleData, accordingly. You might need to convert the received data into the format that the charting library expects. Then you can use the real-time data to display candles on the chart and calculate the percentage at the current price.
Please note that you need to replace the interval variable in the wsUrl with the appropriate interval format supported by the Binance API, e.g., '1m' for 1 minute, '3m' for 3 minutes, etc.
Finally, to make sure the chart is updated with real-time information, you can follow a similar approach in the CandleChart component to update the chart when the real-time data is updated in the parent component (TradeDetails), using the useEffect hook.
Now your chart should display real-time candles and the percentage at the current price based on the data received from the Binance API.
In this example, we set a limited height of '400px' to the DataGrid component, and then we apply custom styling to the scrollbar by targeting the .MuiDataGrid-renderingZone element. We add a red scrollbar and a light gray scrollbar track.
Now the DataGrid will have a limited height with a red scrollbar.