From 3b953a7c216a9cc57e13d00d0280a89be7fd9c9e Mon Sep 17 00:00:00 2001 From: James Grugett Date: Fri, 22 Jul 2022 00:57:56 -0500 Subject: [PATCH] Range limit orders (#655) * Prototype range limit order UI * Conditionally show YES or NO max payout * Range bet executes both bets immediately. * Validate lowLimitProb < highLimitProb * Show error if low limit is higher than high limit * Update range order UI * Revert "Validate lowLimitProb < highLimitProb" This reverts commit c261fc274360711baf1033f12907971a96b13548. * Revert "Range bet executes both bets immediately." This reverts commit 30b95d75d9ee52ed2f49ae2af3edced161b21aeb. * Buy panel only non-limit orders * Bet choice => outcome * More iterating on range UI * betChoice => outcome * Lighten placeholder text --- common/calculate-cpmm.ts | 1 + common/new-bet.ts | 28 +- web/components/amount-input.tsx | 2 +- web/components/bet-panel.tsx | 511 +++++++++++++++++++++------ web/components/bucket-input.tsx | 5 +- web/components/number-input.tsx | 11 +- web/components/probability-input.tsx | 51 ++- 7 files changed, 487 insertions(+), 122 deletions(-) diff --git a/common/calculate-cpmm.ts b/common/calculate-cpmm.ts index 493b5fa9..b5153355 100644 --- a/common/calculate-cpmm.ts +++ b/common/calculate-cpmm.ts @@ -123,6 +123,7 @@ export function calculateCpmmAmountToProb( prob: number, outcome: 'YES' | 'NO' ) { + if (prob <= 0 || prob >= 1 || isNaN(prob)) return Infinity if (outcome === 'NO') prob = 1 - prob // First, find an upper bound that leads to a more extreme probability than prob. diff --git a/common/new-bet.ts b/common/new-bet.ts index f484b9f7..ea0b011d 100644 --- a/common/new-bet.ts +++ b/common/new-bet.ts @@ -1,4 +1,4 @@ -import { sortBy, sumBy } from 'lodash' +import { sortBy, sum, sumBy } from 'lodash' import { Bet, fill, LimitBet, MAX_LOAN_PER_CONTRACT, NumericBet } from './bet' import { @@ -239,6 +239,32 @@ export const getBinaryCpmmBetInfo = ( } } +export const getBinaryBetStats = ( + outcome: 'YES' | 'NO', + betAmount: number, + contract: CPMMBinaryContract | PseudoNumericContract, + limitProb: number, + unfilledBets: LimitBet[] +) => { + const { newBet } = getBinaryCpmmBetInfo( + outcome, + betAmount ?? 0, + contract, + limitProb, + unfilledBets as LimitBet[] + ) + const remainingMatched = + ((newBet.orderAmount ?? 0) - newBet.amount) / + (outcome === 'YES' ? limitProb : 1 - limitProb) + const currentPayout = newBet.shares + remainingMatched + + const currentReturn = betAmount ? (currentPayout - betAmount) / betAmount : 0 + + const totalFees = sum(Object.values(newBet.fees)) + + return { currentPayout, currentReturn, totalFees, newBet } +} + export const getNewBinaryDpmBetInfo = ( outcome: 'YES' | 'NO', amount: number, diff --git a/web/components/amount-input.tsx b/web/components/amount-input.tsx index a31957cb..426a9371 100644 --- a/web/components/amount-input.tsx +++ b/web/components/amount-input.tsx @@ -41,7 +41,7 @@ export function AmountInput(props: { {label}