price handling fixes affecting orderbuild, pairprice, ordershapes, etc

This commit is contained in:
tim
2024-10-13 18:28:01 -04:00
parent 4b5626094a
commit fe8dd3ef6c
8 changed files with 16 additions and 17 deletions

View File

@@ -247,7 +247,7 @@ export function createShape(shapeType, points, options={}, ...callbacks) {
// programatically adds a shape to the chart
let shapeId
try {
console.log('creating shape', points, options)
// console.log('creating shape', points, options)
if (points.time || points.price)
shapeId = chart.createShape(points, options)
else if (points.length === 1)

View File

@@ -181,7 +181,7 @@ export async function loadOHLC (symbol, contract, from, to, tvRes) {
switch (row.length) {
case 1:
if (row[0].length !== 0)
console.log(`Warning: weird nonempty row at OHLC line ${lineNum}: ${line}`)
console.log(`Warning: weird nonempty row at OHLC line ${lineNum}: "${line}"`)
break
case 2:
time = parseInt(row[0])

View File

@@ -68,7 +68,7 @@ class TrancheShapes {
* 10 ** -(amountIsBase ? this.symbol.base.d : this.symbol.quote.d)
const weight = Number(filledAmount) / Number(this.status.order.amount)
const amountSymbol = amountIsBase ? this.symbol.base.s : this.symbol.quote.s
console.log('fillpoint', buy, filledAmount, this.status.order, this.symbol)
// console.log('fillpoint', buy, filledAmount, this.status.order, this.symbol)
const time = f.time
const out = Number(f.filledOut) / (1-this.status.order.route.fee/1000000)
let price = out / Number(f.filledIn)
@@ -89,7 +89,7 @@ class TrancheShapes {
const symbol = this.symbol
const scale = 10**symbol.decimals;
const buy = status.order.tokenIn === this.symbol.quote.a
const inverted = buy === symbol.inverted
const inverted = buy
amount = Number(amount)
* 10 ** -(buy ? this.symbol.base.d : this.symbol.quote.d)
const amountSymbol = buy ? this.symbol.base.s : this.symbol.quote.s

View File

@@ -42,7 +42,7 @@ export function allocationText(weight, amount, symbol, separator = ' ') {
const hasAmount = amount !== null && amount !== undefined && amount > 0
if (hasAmount)
amount = Number(amount)
const hasWeight = weight !== null && weight !== undefined
const hasWeight = weight !== null && weight !== undefined && weight !== 1
if (hasWeight)
weight = Number(weight)
let text = ''

View File

@@ -38,13 +38,13 @@ const pair = computed(() => {
function pairPrice(chainId, baseToken, quoteToken, price) {
if (price === null || price === undefined)
return null
const decimals = baseToken.d - quoteToken.d
const decimals = quoteToken.d - baseToken.d
// console.log('pairPrice', chainId, baseToken, quoteToken, price, decimals)
// console.log('adjusted pairPrice', price)
if (decimals >= 0)
price /= 10 ** decimals
else
price *= 10 ** -decimals
// console.log('adjusted pairPrice', price)
if (inversionPreference(chainId, baseToken, quoteToken))
price = 1 / price
// console.log('inverted?', price)

View File

@@ -97,11 +97,11 @@
<line-price class="mx-3" v-if="!t.marketOrder"
:base="item.order.tokenIn" :quote="item.order.tokenOut"
:b="t.minLine.intercept" :m="t.minLine.slope" :is-min="true"
:show-btn="false"/>
:show-btn="true"/>
<line-price class="mx-3" v-if="!t.marketOrder"
:base="item.order.tokenIn" :quote="item.order.tokenOut"
:b="t.maxLine.intercept" :m="t.maxLine.slope" :is-min="false"
:show-btn="false"/>
:show-btn="true"/>
</div>
</td>

View File

@@ -156,7 +156,7 @@ const maxAmount = computed(()=>{
return null
const balance = s.balances[token.a]
if( !balance )
return 0
return null
const divisor = os.amountIsTotal ? 1 : os.tranches
return balance / 10**token.d / divisor
})
@@ -165,7 +165,7 @@ const available = computed(()=>{
return max === null ? '' : `Available: ${maxAmount.value} ${tokenIn.value.s}`
})
const lastMaxValue = ref(null)
const lastMaxValue = ref(-1)
function setMax() {
let amount = maxAmount.value

View File

@@ -139,11 +139,11 @@ export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
export function applyLinePoint(tranche, symbol, buy, price0) {
console.log('applyLinePoint', buy?'BUY':'SELL', symbol, price0)
const orig = price0
price0 *= 10 ** -symbol.decimals
const inverted = buy === symbol.inverted
if (inverted)
if (buy)
price0 = 1/price0
console.log('applyLinePoint', buy?'BUY':'SELL', symbol, orig, price0)
applyLine(tranche, symbol, buy, price0, 0)
}
@@ -152,8 +152,7 @@ export function applyLinePoints(tranche, symbol, buy, time0, price0, time1, pric
const scale = 10 ** -symbol.decimals
price0 *= scale
price1 *= scale
const inverted = buy === symbol.inverted
if (inverted) {
if (buy) {
price0 = 1/price0
price1 = 1/price1
}
@@ -165,7 +164,7 @@ export function applyLinePoints(tranche, symbol, buy, time0, price0, time1, pric
function applyLine(tranche, symbol, buy, intercept, slope, isMaximum=false) {
let m = slope
let b = intercept
console.log('applyLine current line value', isMaximum?'min':'max', m*timestamp()+b, 1./(m*timestamp()+b))
console.log('applyLine current line value', isMaximum?'max':'min', m*timestamp()+b, 1./(m*timestamp()+b))
m = encodeIEE754(m)
b = encodeIEE754(b)
if (isMaximum) {