price handling fixes affecting orderbuild, pairprice, ordershapes, etc
This commit is contained in:
@@ -247,7 +247,7 @@ export function createShape(shapeType, points, options={}, ...callbacks) {
|
|||||||
// programatically adds a shape to the chart
|
// programatically adds a shape to the chart
|
||||||
let shapeId
|
let shapeId
|
||||||
try {
|
try {
|
||||||
console.log('creating shape', points, options)
|
// console.log('creating shape', points, options)
|
||||||
if (points.time || points.price)
|
if (points.time || points.price)
|
||||||
shapeId = chart.createShape(points, options)
|
shapeId = chart.createShape(points, options)
|
||||||
else if (points.length === 1)
|
else if (points.length === 1)
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ export async function loadOHLC (symbol, contract, from, to, tvRes) {
|
|||||||
switch (row.length) {
|
switch (row.length) {
|
||||||
case 1:
|
case 1:
|
||||||
if (row[0].length !== 0)
|
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
|
break
|
||||||
case 2:
|
case 2:
|
||||||
time = parseInt(row[0])
|
time = parseInt(row[0])
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ class TrancheShapes {
|
|||||||
* 10 ** -(amountIsBase ? this.symbol.base.d : this.symbol.quote.d)
|
* 10 ** -(amountIsBase ? this.symbol.base.d : this.symbol.quote.d)
|
||||||
const weight = Number(filledAmount) / Number(this.status.order.amount)
|
const weight = Number(filledAmount) / Number(this.status.order.amount)
|
||||||
const amountSymbol = amountIsBase ? this.symbol.base.s : this.symbol.quote.s
|
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 time = f.time
|
||||||
const out = Number(f.filledOut) / (1-this.status.order.route.fee/1000000)
|
const out = Number(f.filledOut) / (1-this.status.order.route.fee/1000000)
|
||||||
let price = out / Number(f.filledIn)
|
let price = out / Number(f.filledIn)
|
||||||
@@ -89,7 +89,7 @@ class TrancheShapes {
|
|||||||
const symbol = this.symbol
|
const symbol = this.symbol
|
||||||
const scale = 10**symbol.decimals;
|
const scale = 10**symbol.decimals;
|
||||||
const buy = status.order.tokenIn === this.symbol.quote.a
|
const buy = status.order.tokenIn === this.symbol.quote.a
|
||||||
const inverted = buy === symbol.inverted
|
const inverted = buy
|
||||||
amount = Number(amount)
|
amount = Number(amount)
|
||||||
* 10 ** -(buy ? this.symbol.base.d : this.symbol.quote.d)
|
* 10 ** -(buy ? this.symbol.base.d : this.symbol.quote.d)
|
||||||
const amountSymbol = buy ? this.symbol.base.s : this.symbol.quote.s
|
const amountSymbol = buy ? this.symbol.base.s : this.symbol.quote.s
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ export function allocationText(weight, amount, symbol, separator = ' ') {
|
|||||||
const hasAmount = amount !== null && amount !== undefined && amount > 0
|
const hasAmount = amount !== null && amount !== undefined && amount > 0
|
||||||
if (hasAmount)
|
if (hasAmount)
|
||||||
amount = Number(amount)
|
amount = Number(amount)
|
||||||
const hasWeight = weight !== null && weight !== undefined
|
const hasWeight = weight !== null && weight !== undefined && weight !== 1
|
||||||
if (hasWeight)
|
if (hasWeight)
|
||||||
weight = Number(weight)
|
weight = Number(weight)
|
||||||
let text = ''
|
let text = ''
|
||||||
|
|||||||
@@ -38,13 +38,13 @@ const pair = computed(() => {
|
|||||||
function pairPrice(chainId, baseToken, quoteToken, price) {
|
function pairPrice(chainId, baseToken, quoteToken, price) {
|
||||||
if (price === null || price === undefined)
|
if (price === null || price === undefined)
|
||||||
return null
|
return null
|
||||||
const decimals = baseToken.d - quoteToken.d
|
const decimals = quoteToken.d - baseToken.d
|
||||||
// console.log('pairPrice', chainId, baseToken, quoteToken, price, decimals)
|
// console.log('pairPrice', chainId, baseToken, quoteToken, price, decimals)
|
||||||
// console.log('adjusted pairPrice', price)
|
|
||||||
if (decimals >= 0)
|
if (decimals >= 0)
|
||||||
price /= 10 ** decimals
|
price /= 10 ** decimals
|
||||||
else
|
else
|
||||||
price *= 10 ** -decimals
|
price *= 10 ** -decimals
|
||||||
|
// console.log('adjusted pairPrice', price)
|
||||||
if (inversionPreference(chainId, baseToken, quoteToken))
|
if (inversionPreference(chainId, baseToken, quoteToken))
|
||||||
price = 1 / price
|
price = 1 / price
|
||||||
// console.log('inverted?', price)
|
// console.log('inverted?', price)
|
||||||
|
|||||||
@@ -97,11 +97,11 @@
|
|||||||
<line-price class="mx-3" v-if="!t.marketOrder"
|
<line-price class="mx-3" v-if="!t.marketOrder"
|
||||||
:base="item.order.tokenIn" :quote="item.order.tokenOut"
|
:base="item.order.tokenIn" :quote="item.order.tokenOut"
|
||||||
:b="t.minLine.intercept" :m="t.minLine.slope" :is-min="true"
|
: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"
|
<line-price class="mx-3" v-if="!t.marketOrder"
|
||||||
:base="item.order.tokenIn" :quote="item.order.tokenOut"
|
:base="item.order.tokenIn" :quote="item.order.tokenOut"
|
||||||
:b="t.maxLine.intercept" :m="t.maxLine.slope" :is-min="false"
|
:b="t.maxLine.intercept" :m="t.maxLine.slope" :is-min="false"
|
||||||
:show-btn="false"/>
|
:show-btn="true"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</td>
|
</td>
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ const maxAmount = computed(()=>{
|
|||||||
return null
|
return null
|
||||||
const balance = s.balances[token.a]
|
const balance = s.balances[token.a]
|
||||||
if( !balance )
|
if( !balance )
|
||||||
return 0
|
return null
|
||||||
const divisor = os.amountIsTotal ? 1 : os.tranches
|
const divisor = os.amountIsTotal ? 1 : os.tranches
|
||||||
return balance / 10**token.d / divisor
|
return balance / 10**token.d / divisor
|
||||||
})
|
})
|
||||||
@@ -165,7 +165,7 @@ const available = computed(()=>{
|
|||||||
return max === null ? '' : `Available: ${maxAmount.value} ${tokenIn.value.s}`
|
return max === null ? '' : `Available: ${maxAmount.value} ${tokenIn.value.s}`
|
||||||
})
|
})
|
||||||
|
|
||||||
const lastMaxValue = ref(null)
|
const lastMaxValue = ref(-1)
|
||||||
|
|
||||||
function setMax() {
|
function setMax() {
|
||||||
let amount = maxAmount.value
|
let amount = maxAmount.value
|
||||||
|
|||||||
@@ -139,11 +139,11 @@ export function linePointsValue(time0, price0, time1, price1, unixTime = null) {
|
|||||||
|
|
||||||
|
|
||||||
export function applyLinePoint(tranche, symbol, buy, price0) {
|
export function applyLinePoint(tranche, symbol, buy, price0) {
|
||||||
console.log('applyLinePoint', buy?'BUY':'SELL', symbol, price0)
|
const orig = price0
|
||||||
price0 *= 10 ** -symbol.decimals
|
price0 *= 10 ** -symbol.decimals
|
||||||
const inverted = buy === symbol.inverted
|
if (buy)
|
||||||
if (inverted)
|
|
||||||
price0 = 1/price0
|
price0 = 1/price0
|
||||||
|
console.log('applyLinePoint', buy?'BUY':'SELL', symbol, orig, price0)
|
||||||
applyLine(tranche, symbol, buy, price0, 0)
|
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
|
const scale = 10 ** -symbol.decimals
|
||||||
price0 *= scale
|
price0 *= scale
|
||||||
price1 *= scale
|
price1 *= scale
|
||||||
const inverted = buy === symbol.inverted
|
if (buy) {
|
||||||
if (inverted) {
|
|
||||||
price0 = 1/price0
|
price0 = 1/price0
|
||||||
price1 = 1/price1
|
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) {
|
function applyLine(tranche, symbol, buy, intercept, slope, isMaximum=false) {
|
||||||
let m = slope
|
let m = slope
|
||||||
let b = intercept
|
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)
|
m = encodeIEE754(m)
|
||||||
b = encodeIEE754(b)
|
b = encodeIEE754(b)
|
||||||
if (isMaximum) {
|
if (isMaximum) {
|
||||||
|
|||||||
Reference in New Issue
Block a user