const positions: Record<string, AccountPosition> = { "BTCBUSD": { symbol: "BTCBUSD",…
- User
const positions: Record<string, AccountPosition> = { "BTCBUSD": { symbol: "BTCBUSD", quantity: 3, openPrice: 25690, amount: 150, openDate: "2023-01-01", side: "ask", apiKeyId: "2", }, };
useEffect(() => { if (!workerRef.current) return; workerRef.current.onmessage = (event: MessageEvent<UpdateCupEvent|OrderEvent>) => { if (event?.data?.type === "update_cup") { animationFrameId = requestAnimationFrame(() => { const data = event.data as UpdateCupEvent;
codeconst context = canvasRef.current?.getContext("2d"); const zoomedTickSize = data.priceStep * data.aggregation; if (context) { const rowsOnScreenCount = cupTools.getRowsCountOnScreen( canvasSize.height, cupOptions().cell.defaultHeight * dpiScale, ); const realCellHeight = parseInt((canvasSize.height / rowsOnScreenCount).toFixed(0)); if (data.rowsCount !== rowsOnScreenCount) { workerRef.current?.postMessage(JSON.stringify({type: "change_rows_count", value: rowsOnScreenCount})); } cupDrawer.clear(context, canvasSize); if (cupParams.rowCount !== rowsOnScreenCount || cupParams.cellHeight !== realCellHeight || cupParams.aggregation !== data.aggregation ) { dispatch(setCupParams({ aggregation: data.aggregation, rowCount: rowsOnScreenCount, cellHeight: realCellHeight, pricePrecision: data.pricePrecision, priceStep: data.priceStep, quantityPrecision: data.quantityPrecision, })); } console.log(data.priceStep); if (data.camera === 0 && isLoaded) { setIsLoaded(false); } if (data.camera > 0 && !isLoaded) { setIsLoaded(true); } if (data.camera !== 0) { cupDrawer.draw( context, canvasSize, dpiScale, data.bestBidPrice, data.bestAskPrice, data.maxVolume, data.pricePrecision, data.quantityPrecision, data.priceStep, data.aggregation, rowsOnScreenCount, data.camera, realCellHeight, { buy: parseInt((Math.floor(data.bestBidPrice / zoomedTickSize) * zoomedTickSize).toFixed(0)), sell: parseInt((Math.ceil(data.bestAskPrice / zoomedTickSize) * zoomedTickSize).toFixed(0)), }, darkMode, data.volumeAsDollars, data.cup, positions, ); } } }); } }; return () => { if (null !== animationFrameId) { cancelAnimationFrame(animationFrameId); } }; - Assistant
- User
нарисуй полупрозрачный прямоугольник от цены взода до bestPrice. и пиши по русски еблан, я тебе по русски пишу
- Assistant
Извините за прежний ответ на английском языке. Вот исправленный код на русском языке, который рисует полупрозрачный прямоугольник от цены входа до bestPrice:
javascript// Добавьте следующий код в функцию "draw" объекта "cupDrawer": // Внутри цикла, где рисуется каждая ячейка: // Рисование прямоугольника позиций const позиция = positions["BTCBUSD"]; const ценаВхода = позиция.openPrice; const ценаЛучшая = side === "bid" ? bestBidPrice : bestAskPrice; const позицияY = cellHeight * Math.floor((ценаВхода - startMicroPrice) / zoomedTickSize); const позицияВысот