Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

if(positions[symbol]) { const position = positions[symbol]; const entryPrice =…

  1. User

    if(positions[symbol]) {

      const position = positions[symbol];
      const entryPrice = position.openPrice;
    
      const formattedPrice = entryPrice.toString().replace(".", "");
      console.log(entryPrice, +formattedPrice / priceDivider); // Выведет "4234"
    
      const bestPrice = formattedPrice > bestBidPrice ? bestAskPrice : bestBidPrice;
      const cupKeys = Object.keys(cup);
      const entryIndex = cupKeys.reverse().indexOf(formattedPrice.toString());
      const bestPriceIndex = cupKeys.indexOf(bestPrice.toString());
    
      const {width: textWidth} = ctx.measureText(entryPrice.toString());
    
      // console.log(formattedPrice, bestPrice, cupKeys, entryIndex, bestPriceIndex);
    
      if(+formattedPrice <= bestBidPrice) {
        const height = ((entryIndex - bestPriceIndex) + 1) * cellHeight;
        ctx.fillStyle = "#00573761";
        ctx.fillRect(size.width - cupOptions().cell.paddingX * dpiScale - textWidth - 2, (bestPriceIndex) * cellHeight, size.width, height);
      } else {
        const height = (bestPriceIndex - entryIndex) * cellHeight;
        ctx.fillStyle = "#b41c185c";
        ctx.fillRect(size.width - cupOptions().cell.paddingX * dpiScale - textWidth - 2, entryIndex * cellHeight, size.width, height);
      }
    }
    

    нужно сделать этот квадрат поверх всех остальных

  2. Assistant

    Для того чтобы сделать данный квадрат поверх всех остальных элементов, необходимо использовать CSS свойство "z-index". Установите значение "z-index" для квадрата, которое будет больше, чем у остальных элементов. Например:

    .squared {
      position: absolute;
      z-index: 999; /* Большее значение, чем у остальных элементов */
    }
    

    Затем, присвойте класс "squared" к элементу, который вы хотите поместить поверх остальных элементов:

    <canvas class="squared"></canvas>
    

    Поместите этот элемент в нужное место в вашем коде, чтобы он находился поверх остальных элементов.

  3. User

    if(formattedPrice.length !== bestBidPrice.toString().length) { formattedPrice = formattedPrice + "0"; }

    нужно сделать цикл, который будет добавлять нули, пока длина прайса не будет равно бест прайсу

  4. Assistant

    Вы можете использовать цикл while для добавления нулей к formattedPrice, пока его длина не будет равна длине bestBidPrice.toString(). Вот пример, как это можно сделать:

    while (formattedPrice.length !== bestBidPrice.toString().length) {
      formattedPrice = formattedPrice + "0";
    }
    

    Этот цикл будет выполняться до тех пор, пока длина formattedPrice не станет равной длине строки, полученной из bestBidPrice. Каждую итерацию цикла будет добавляться по одному нулю в конец formattedPrice. Когда длины будут совпадать, цикл завершится.