ohlc's
This commit is contained in:
48
src/blockchain/ohlcs.js
Normal file
48
src/blockchain/ohlcs.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import {socket} from "@/socket.js";
|
||||
import {useStore} from "@/store/store.js";
|
||||
import {Exchange} from "@/blockchain/orderlib.js";
|
||||
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
|
||||
import {ethers, FixedNumber} from "ethers";
|
||||
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
|
||||
|
||||
const ohlcSubCounts = {} // key is route and value is a subscription counter
|
||||
export const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 decimals is 127 bits
|
||||
|
||||
|
||||
export function subOHLCs( chainId, poolPeriods ) {
|
||||
if( !poolPeriods.length )
|
||||
return
|
||||
const toSub = []
|
||||
for( const [pool,period] of poolPeriods ) {
|
||||
const key = `${pool}|${period}`
|
||||
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
|
||||
ohlcSubCounts[key] = 1
|
||||
toSub.push(key)
|
||||
} else {
|
||||
ohlcSubCounts[key]++
|
||||
}
|
||||
}
|
||||
if( toSub.length )
|
||||
socket.emit('subOHLCs', chainId, toSub)
|
||||
}
|
||||
|
||||
export function unsubPrices( chainId, poolPeriods ) {
|
||||
const toUnsub = []
|
||||
for( const [pool,period] of poolPeriods ) {
|
||||
const key = `${pool}|${period}`
|
||||
if (!(key in ohlcSubCounts) || ohlcSubCounts[key] === 0) {
|
||||
console.error('overdecremented',pool,period)
|
||||
ohlcSubCounts[key] = 1
|
||||
toSub.push(key)
|
||||
} else {
|
||||
ohlcSubCounts[key]--
|
||||
if( ohlcSubCounts[key] == 0 )
|
||||
toUnsub.push(key)
|
||||
}
|
||||
}
|
||||
if( toUnsub.length )
|
||||
socket.emit('unsubOHLCs', chainId, toUnsub )
|
||||
}
|
||||
|
||||
// todo get history
|
||||
|
||||
@@ -4,6 +4,7 @@ import {Exchange} from "@/blockchain/orderlib.js";
|
||||
import {uniswapV3PoolAddress} from "@/blockchain/uniswap.js";
|
||||
import {ethers, FixedNumber} from "ethers";
|
||||
import {uniswapV3PoolAbi} from "@/blockchain/abi.js";
|
||||
import {subOHLCs} from "@/blockchain/ohlcs.js";
|
||||
|
||||
const subscriptionCounts = {} // key is route and value is a subscription counter
|
||||
export const WIDE_PRICE_FORMAT = {decimals:38, width:512, signed:false}; // 38 decimals is 127 bits
|
||||
|
||||
@@ -8,6 +8,7 @@ import {subPrices, unsubPrices, WIDE_PRICE_FORMAT} from "@/blockchain/prices.js"
|
||||
import {computed, onBeforeUnmount} from "vue";
|
||||
import {FixedNumber} from "ethers";
|
||||
import {routeInverted} from "@/misc.js";
|
||||
import {subOHLCs} from "@/blockchain/ohlcs.js";
|
||||
|
||||
const s = useStore()
|
||||
const os = useOrderStore()
|
||||
@@ -37,8 +38,10 @@ const price = computed(()=>{
|
||||
return p.toPrecision(props.precision)
|
||||
})
|
||||
|
||||
if( route.value )
|
||||
if( route.value ) {
|
||||
subPrices([route.value])
|
||||
subOHLCs( s.chainId.value, [[route.value.pool,'1D']])
|
||||
}
|
||||
else
|
||||
console.log('route is empty: no price')
|
||||
|
||||
|
||||
@@ -48,12 +48,14 @@
|
||||
<v-card-title><v-icon icon="mdi-safe-square" color="grey-darken-2" size="small"/> Vault Assets {{s.vaults.length>1?'#'+(num+1):''}}</v-card-title> <!-- todo vault nicknames -->
|
||||
<v-card-subtitle v-if="exists" class="overflow-x-hidden"><copy-button :text="addr"/>{{addr}}</v-card-subtitle>
|
||||
<v-card-text v-if="empty">
|
||||
<!--
|
||||
<p>
|
||||
Your vault is a smart contract that securely holds your funds plus any orders you place. When your order
|
||||
conditions are met, Dexorder creates a blockchain transaction asking your vault to execute the order. Your
|
||||
vault then checks that order against the current blockchain time and pool price, and only trades if
|
||||
everything looks good.
|
||||
</p>
|
||||
-->
|
||||
<p v-if="!s.mockenv">There are no funds currently in your vault. Send tokens to the address above to fund your vault.</p>
|
||||
<p v-if="s.mockenv">There are no funds currently in your vault. Use the faucet below to mint some testnet coins into your vault.</p>
|
||||
</v-card-text>
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import {io} from "socket.io-client";
|
||||
import {useStore} from "@/store/store.js";
|
||||
import {flushOrders, onChainChanged} from "@/blockchain/wallet.js";
|
||||
import {ethers} from "ethers";
|
||||
import {flushOrders} from "@/blockchain/wallet.js";
|
||||
import {parseOrderStatus} from "@/blockchain/orderlib.js";
|
||||
|
||||
export const socket = io(import.meta.env.VITE_WS_URL || undefined, {transports: ["websocket"]})
|
||||
@@ -22,6 +21,10 @@ socket.on('p', async (chainId, pool, price) => {
|
||||
s.poolPrices[[chainId,pool]] = price
|
||||
})
|
||||
|
||||
socket.on('ohlcs', async (chainId, pool, ohlcs) => {
|
||||
console.log('pool bars', pool, ohlcs)
|
||||
})
|
||||
|
||||
socket.on('vb', async (chainId, vault, balances) => {
|
||||
const s = useStore()
|
||||
if( s.chainId.value !== chainId )
|
||||
|
||||
3
tradingview.md
Normal file
3
tradingview.md
Normal file
@@ -0,0 +1,3 @@
|
||||
https://github.com/tradingview/charting_library
|
||||
https://www.tradingview.com/charting-library-docs/latest/getting_started/Best-Practices/
|
||||
|
||||
Reference in New Issue
Block a user