当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript js.BigNumber.eq方法代码示例

本文整理汇总了TypeScript中bignumber.js.BigNumber.eq方法的典型用法代码示例。如果您正苦于以下问题:TypeScript js.BigNumber.eq方法的具体用法?TypeScript js.BigNumber.eq怎么用?TypeScript js.BigNumber.eq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bignumber.js.BigNumber的用法示例。


在下文中一共展示了js.BigNumber.eq方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: updateProfitLoss

export async function updateProfitLoss(db: Knex, marketId: Address, positionDelta: BigNumber, account: Address, outcome: number, tradePriceBN: BigNumber, transactionHash: string, blockNumber: number, logIndex: number, tradeData: undefined | Pick<TradesRow<BigNumber>, "orderType" | "creator" | "filler" | "price" | "numCreatorTokens" | "numCreatorShares" | "numFillerTokens" | "numFillerShares">): Promise<void> {
  if (positionDelta.eq(ZERO)) return;

  const tradePositionDelta = new Shares(positionDelta);
  const timestamp = getCurrentTime();

  const marketsRow: Pick<MarketsRow<BigNumber>, "minPrice" | "maxPrice"> = await db("markets").first("minPrice", "maxPrice").where({ marketId });

  const marketMinPrice = new Price(marketsRow.minPrice);
  const marketMaxPrice = new Price(marketsRow.maxPrice);
  const tradePrice = new Price(tradePriceBN);

  const { tradePriceMinusMinPrice } = getTradePriceMinusMinPrice({
    marketMinPrice,
    tradePrice,
  });

  const prevData: UpdateData = await db
    .first(["price", "position", "profit", "frozenFunds", "realizedCost"])
    .from("wcl_profit_loss_timeseries")
    .where({ account, marketId, outcome })
    .orderByRaw(`"blockNumber" DESC, "logIndex" DESC`);

  const netPosition: Shares = prevData ? new Shares(prevData.position) : Shares.ZERO;
  const averageTradePriceMinusMinPriceForOpenPosition = prevData ? new Price(prevData.price) : Price.ZERO;
  const realizedCost = prevData ? new Tokens(prevData.realizedCost) : Tokens.ZERO;
  const realizedProfit = prevData ? new Tokens(prevData.profit) : Tokens.ZERO;
  const frozenFunds = prevData ? prevData.frozenFunds : ZERO;

  const { tradeQuantityOpened } = getTradeQuantityOpened({
    netPosition,
    tradePositionDelta,
  });
  const { nextNetPosition } = getNextNetPosition({
    netPosition,
    tradePositionDelta,
  });
  const { nextRealizedProfit } = getNextRealizedProfit({
    realizedProfit,
    marketMinPrice,
    marketMaxPrice,
    netPosition,
    averageTradePriceMinusMinPriceForOpenPosition,
    tradePositionDelta,
    tradePriceMinusMinPrice,
  });
  const { nextRealizedCost } = getNextRealizedCost({
    realizedCost,
    marketMinPrice,
    marketMaxPrice,
    netPosition,
    tradePositionDelta,
    averageTradePriceMinusMinPriceForOpenPosition,
  });
  const { nextAverageTradePriceMinusMinPriceForOpenPosition } =
    getNextAverageTradePriceMinusMinPriceForOpenPosition({
      netPosition,
      averageTradePriceMinusMinPriceForOpenPosition,
      tradePositionDelta,
      tradePriceMinusMinPrice,
    });
  const { tradeRealizedProfitDelta } = getTradeRealizedProfitDelta({
    marketMinPrice,
    marketMaxPrice,
    netPosition,
    averageTradePriceMinusMinPriceForOpenPosition,
    tradePositionDelta,
    tradePriceMinusMinPrice,
  });
  const nextFrozenFunds = getFrozenFundsAfterEventForOneOutcome({
    frozenFundsBeforeEvent: { frozenFunds },
    event: makeFrozenFundsEvent(account, tradeRealizedProfitDelta.magnitude, marketsRow, tradeData),
  });

  const nextProfitLossTimeseries = { // this is of type ProfitLossTimeseries<BigNumberType = string>
    account,
    marketId,
    outcome,
    price: nextAverageTradePriceMinusMinPriceForOpenPosition.magnitude.toString(),
    position: nextNetPosition.magnitude.toString(),
    quantityOpened: tradeQuantityOpened.magnitude.toString(),
    profit: nextRealizedProfit.magnitude.toString(),
    transactionHash,
    timestamp,
    blockNumber,
    logIndex,
    frozenFunds: nextFrozenFunds.frozenFunds.toString(),
    realizedCost: nextRealizedCost.magnitude.toString(),
  };

  await db.insert(nextProfitLossTimeseries).into("wcl_profit_loss_timeseries");
}
开发者ID:AugurProject,项目名称:augur_node,代码行数:92,代码来源:update-profit-loss.ts


注:本文中的bignumber.js.BigNumber.eq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。