Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
23cb4fd
Migrate asset inversion code
IYTEC Nov 25, 2022
abe9e24
Add functionality for pair switching
IYTEC Nov 25, 2022
17d1a80
Add invertion toggle button
IYTEC Nov 25, 2022
e520273
✨ Stable asset switching
IYTEC Nov 28, 2022
6fdb43f
Add asset support hook
IYTEC Nov 28, 2022
f723679
Show invert button for stable assets
IYTEC Nov 28, 2022
a5d8bc3
Sort orders
IYTEC Nov 28, 2022
06092d2
🚨 Fix linting error
IYTEC Nov 28, 2022
2ae8d93
🚨 More eslint fixing
IYTEC Nov 28, 2022
171db83
✨ Show asset inversion button for all assets
IYTEC Nov 29, 2022
30c5f26
Complete invertion for all assets
IYTEC Nov 30, 2022
011c3f4
More updates for inversion for all assets
IYTEC Dec 1, 2022
9e563bf
🎨 Update search table item
IYTEC Dec 1, 2022
6608c32
🚨 Fix eslint
IYTEC Dec 1, 2022
8ed4168
🧐 Fix console errors
IYTEC Dec 1, 2022
99f31c3
Console error fix
IYTEC Dec 1, 2022
45322cd
♻️ Update formatting for chart data
IYTEC Dec 2, 2022
6d8d7a0
Testing chart page
IYTEC Dec 2, 2022
3b223ea
πŸ› Testing flictering chart
IYTEC Dec 2, 2022
5ee96a4
πŸ› Complete implementation for chart inversion
IYTEC Dec 4, 2022
653ecd1
✨ Add info when asset is not 6 decimals
IYTEC Dec 5, 2022
198efa6
✨ Set default state for stable assets
IYTEC Dec 5, 2022
9b6e808
πŸ› Fix amount issue
IYTEC Dec 5, 2022
21d17b1
πŸ› Fix price in orderbook
IYTEC Dec 5, 2022
6ea2a93
πŸ› Fix price in trades history
IYTEC Dec 5, 2022
067e8c0
Price inversion for usd price
IYTEC Dec 8, 2022
5f8732e
USD Inversion component
IYTEC Dec 8, 2022
872cd70
✨ Remove USD price for inverted mode for some asset
IYTEC Dec 8, 2022
8cf8e64
✨ Remove reversal of asset
IYTEC Dec 8, 2022
67a7655
🚨 Fix linting error
IYTEC Dec 8, 2022
014b9d4
πŸ› Fix amount field in open order
IYTEC Dec 8, 2022
b69dc72
Correct color of orderbook for inverted mode
IYTEC Dec 8, 2022
eef0658
Update pricing
IYTEC Dec 8, 2022
ef51c97
Sort table list
IYTEC Dec 9, 2022
44df060
Update stable assets list
IYTEC Dec 9, 2022
6985006
✨ Complete Asset Inversion
IYTEC Dec 10, 2022
b0de6c9
Merge branch 'development' of https://github.com/algodex/algodex-reac…
IYTEC Dec 10, 2022
096d683
βœ… Fix failing test
IYTEC Dec 12, 2022
313668e
🚚 Rename stable assets file
IYTEC Dec 12, 2022
43ad1b0
🚚 Update stable asset file name
IYTEC Dec 12, 2022
8bb9b9e
Complete update
IYTEC Dec 13, 2022
3cf0e12
Merge branch 'development' of https://github.com/algodex/algodex-reac…
IYTEC Dec 13, 2022
22041a7
πŸ› Order book update
IYTEC Dec 14, 2022
a32546b
Testing
IYTEC Dec 14, 2022
487ef95
πŸ› Reformat Open order prices
IYTEC Dec 16, 2022
ee86076
🚨 Fix linting error
IYTEC Dec 16, 2022
d43f2a4
More fixes
IYTEC Dec 16, 2022
4c12b72
Correct formular
IYTEC Dec 16, 2022
2038ea4
More updates
IYTEC Dec 16, 2022
61f5204
More testing
IYTEC Dec 19, 2022
112ab92
Update inversion for amount
IYTEC Dec 19, 2022
8375511
More update to amount
IYTEC Dec 20, 2022
ed89857
Fix amount tab
IYTEC Dec 20, 2022
33eebab
Testing amount
IYTEC Dec 20, 2022
0bf355e
Fix issue with amount
IYTEC Dec 20, 2022
7ebb926
Testing
IYTEC Dec 22, 2022
a4d74b9
Updated amount
IYTEC Dec 22, 2022
8cea81c
Form balace and and hover price
IYTEC Dec 22, 2022
db0521b
Update order total with correct value for insufficient balance
IYTEC Dec 23, 2022
f515f42
Update amount to use available balance
IYTEC Dec 28, 2022
6b32ed1
Parse order info data type on sell order inverted mode
IYTEC Jan 3, 2023
0ccf9d3
πŸ”€Merge changes from development
IYTEC Jan 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 99 additions & 40 deletions components/Asset/Chart/Chart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import * as ReactDOM from 'react-dom'

import { useCallback, useEffect, useRef, useState } from 'react'
import { useCallback, useEffect, useRef, useState, useMemo } from 'react'

import ChartOverlay from './ChartOverlay'
import ChartSettings from './ChartSettings'
Expand All @@ -26,6 +26,8 @@ import styled from '@emotion/styled'
import useAreaChart from './hooks/useAreaChart'
import useCandleChart from './hooks/useCandleChart'
import { withAssetChartQuery } from '@/hooks'
import floatToFixed from '@algodex/algodex-sdk/lib/utils/format/floatToFixed'
import { useInversionStatus } from '@/hooks/utils/useInversionStatus'

const Container = styled.div`
position: relative;
Expand Down Expand Up @@ -76,42 +78,7 @@ const SettingsContainer = styled.div`
height: 2.75rem;
}
`
function autoScaleProvider(original, chart, priceData) {
let visibleRange = chart.timeScale().getVisibleRange()
if (!visibleRange) {
return
}
const rangeStart = visibleRange.from
const rangeEnd = visibleRange.to
let max = 0
let min = -1
for (let i = 0; i < priceData.length; i++) {
const priceItem = priceData[i]
if (priceItem.time < rangeStart) {
continue
}
max = Math.max(priceItem.close, max)
max = Math.max(priceItem.open, max)
max = Math.max(priceItem.high, max)
if (min === -1) {
min = priceItem.open
}
min = Math.min(priceItem.close, min)
min = Math.min(priceItem.low, min)
min = Math.min(priceItem.open, min)
if (priceItem.time > rangeEnd) {
break
}
}

const res = original()
if (res !== null && min !== -1) {
res.priceRange.maxValue = max
res.priceRange.minValue = min
}

return res
}
export function Chart({
asset,
interval: _interval,
Expand All @@ -126,6 +93,30 @@ export function Chart({
const [overlay, setOverlay] = useState(_overlay)
const [chartMode, setChartMode] = useState(_mode)
const [currentLogical, setCurrentLogical] = useState(ohlc.length - 1)
const isInverted = useInversionStatus(asset.id)
// console.log(isInverted, 'is inverted')
const formatedPriceData = useMemo(
() => {
if (isInverted) {
const formatedPriceClone = [...ohlc]
const formattedPrice = formatedPriceClone.reduce(
(accumulator, currentValue) => {
accumulator.push({
...currentValue,
close: currentValue.close !== 0 ? floatToFixed(1 / currentValue.close) : 'Invalid',
high: currentValue.high !== 0 ? floatToFixed(1 / currentValue.high) : 'Invalid',
low: currentValue.low !== 0 ? floatToFixed(1 / currentValue.low) : 'Invalid',
open: currentValue.open !== 0 ? floatToFixed(1 / currentValue.open) : 'Invalid'
})
return accumulator
}, []);
return formattedPrice
} else {
return ohlc
}
},
[isInverted, ohlc],
)

useEffect(() => {
setOverlay(_overlay)
Expand All @@ -143,9 +134,45 @@ export function Chart({
const candleChartRef = useRef()
const areaChartRef = useRef()

const { candleChart } = useCandleChart(candleChartRef, volume, ohlc, autoScaleProvider)
const { areaChart } = useAreaChart(areaChartRef, ohlc, autoScaleProvider)
const autoScaleProvider = useCallback((original, chart, priceData) => {
let visibleRange = chart.timeScale().getVisibleRange()
if (!visibleRange) {
return
}
const rangeStart = visibleRange.from
const rangeEnd = visibleRange.to
let max = 0
let min = -1
for (let i = 0; i < priceData.length; i++) {
const priceItem = priceData[i]
if (priceItem.time < rangeStart) {
continue
}
max = Math.max(priceItem.close, max)
max = Math.max(priceItem.open, max)
max = Math.max(priceItem.high, max)
if (min === -1) {
min = priceItem.open
}
min = Math.min(priceItem.close, min)
min = Math.min(priceItem.low, min)
min = Math.min(priceItem.open, min)
if (priceItem.time > rangeEnd) {
break
}
}

const res = original()
if (res !== null && min !== -1) {
res.priceRange.maxValue = max
res.priceRange.minValue = min
}

return res
}, [])

const { candleChart } = useCandleChart(candleChartRef, volume, formatedPriceData, autoScaleProvider)
const { areaChart } = useAreaChart(areaChartRef, formatedPriceData, autoScaleProvider)
const onSettingsChange = useCallback(
(e) => {
if (e?.target?.name === 'mode') {
Expand All @@ -170,6 +197,16 @@ export function Chart({
if (ohlc == null || volume == null) {
return
}
// if (asset.isInverted) {
// if (ohlc == null || algoVolume == null) {
// return
// }
// } else {
// if (ohlc == null || volume == null) {
// return
// }
// }

const priceEntry = ohlc[logical]
const volumeEntry = volume[logical]

Expand All @@ -183,7 +220,13 @@ export function Chart({
)

const mouseOut = useCallback(() => {
setOverlay(_overlay)
// setOverlay(_overlay)
if (isInverted) {
const __overlay = { ...overlay, ..._overlay }
setOverlay(__overlay)
} else {
setOverlay(_overlay)
}
}, [setOverlay, _overlay])

const mouseMove = useCallback(
Expand All @@ -203,6 +246,18 @@ export function Chart({
return
}

// if (isInverted) {
// if (logical >= ohlc.length || logical >= algoVolume.length) {
// // setOverlay(_overlay)
// return
// }
// } else {
// if (logical >= ohlc.length || logical >= volume.length) {
// // setOverlay(_overlay)
// return
// }
// }

if (logical !== currentLogical) {
setCurrentLogical(logical)
updateHoverPrices(logical)
Expand All @@ -218,6 +273,7 @@ export function Chart({
setCurrentLogical,
updateHoverPrices,
volume,
asset.isInverted,
ohlc
]
)
Expand Down Expand Up @@ -248,6 +304,7 @@ export function Chart({
ask={overlay.orderbook.ask}
spread={overlay.orderbook.spread}
volume={overlay.volume}
// volume={asset.isInverted ? overlay.algoVolume : overlay.volume}
/>
)}
{typeof overlay.ohlc === 'undefined' && (
Expand All @@ -258,6 +315,7 @@ export function Chart({
ask={_overlay.orderbook.ask}
spread={_overlay.orderbook.spread}
volume={_overlay.volume}
// volume={asset.isInverted ? overlay.algoVolume : overlay.volume}
/>
)}
<SettingsContainer>
Expand All @@ -270,7 +328,8 @@ export function Chart({
Chart.propTypes = {
asset: PropTypes.shape({
id: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
decimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired
decimals: PropTypes.oneOfType([PropTypes.string, PropTypes.number]).isRequired,
isInverted: PropTypes.bool
}).isRequired,
interval: PropTypes.string.isRequired,
mode: PropTypes.string.isRequired,
Expand Down
Loading