update WS for trading view charts
This commit is contained in:
parent
94f823c91f
commit
d3f5cd9045
|
@ -14,7 +14,7 @@ socket.addEventListener('open', (_event) => {
|
|||
// Listen for messages
|
||||
socket.addEventListener('message', (msg) => {
|
||||
const data = JSON.parse(msg.data)
|
||||
if (data.type !== 'PRICE_DATA') return console.warn(data)
|
||||
if (data.type !== 'BASE_QUOTE_PRICE_DATA') return console.warn(data)
|
||||
|
||||
const currTime = data.data.unixTime * 1000
|
||||
const lastBar = subscriptionItem.lastBar
|
||||
|
@ -60,11 +60,11 @@ export function subscribeOnStream(
|
|||
}
|
||||
|
||||
const msg = {
|
||||
type: 'SUBSCRIBE_PRICE',
|
||||
type: 'SUBSCRIBE_BASE_QUOTE_PRICE',
|
||||
data: {
|
||||
chartType: parseResolution(resolution),
|
||||
address: symbolInfo.address,
|
||||
currency: symbolInfo.type || 'usd',
|
||||
baseAddress: symbolInfo.base_token,
|
||||
quoteAddress: symbolInfo.quote_token,
|
||||
},
|
||||
}
|
||||
if (!isOpen(socket)) {
|
||||
|
@ -80,7 +80,7 @@ export function subscribeOnStream(
|
|||
|
||||
export function unsubscribeFromStream() {
|
||||
const msg = {
|
||||
type: 'UNSUBSCRIBE_PRICE',
|
||||
type: 'UNSUBSCRIBE_BASE_QUOTE_PRICE',
|
||||
}
|
||||
|
||||
if (!isOpen(socket)) {
|
||||
|
|
|
@ -249,12 +249,19 @@ export default {
|
|||
let ticker = mangoStoreState.selectedMarket.name
|
||||
let quote_token = ''
|
||||
let base_token = ''
|
||||
console.log(1)
|
||||
|
||||
if (group && symbolAddress) {
|
||||
console.log(2)
|
||||
|
||||
const market = getMktFromMktAddress(group, symbolAddress)
|
||||
if (market) {
|
||||
console.log(3)
|
||||
|
||||
ticker = market.name
|
||||
if (market instanceof Serum3Market) {
|
||||
console.log(4)
|
||||
|
||||
base_token = group
|
||||
.getFirstBankByTokenIndex(market.baseTokenIndex)
|
||||
.mint.toString()
|
||||
|
@ -313,17 +320,14 @@ export default {
|
|||
try {
|
||||
const { firstDataRequest } = periodParams
|
||||
let bars
|
||||
if (
|
||||
symbolInfo.description?.includes('PERP') &&
|
||||
symbolInfo.address !== '8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6'
|
||||
) {
|
||||
if (symbolInfo.description?.includes('PERP') && symbolInfo.address) {
|
||||
marketType = 'perp'
|
||||
bars = await queryPerpBars(
|
||||
symbolInfo.address,
|
||||
resolution as any,
|
||||
periodParams,
|
||||
)
|
||||
} else {
|
||||
} else if (symbolInfo.address) {
|
||||
marketType = 'spot'
|
||||
bars = await queryBirdeyeBars(
|
||||
symbolInfo.base_token,
|
||||
|
|
|
@ -554,8 +554,7 @@ const TradingViewChart = () => {
|
|||
const marketAddress =
|
||||
(mkt instanceof Serum3Market
|
||||
? mkt?.serumMarketExternal.toString()
|
||||
: mkt?.publicKey.toString()) ||
|
||||
'8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6'
|
||||
: mkt?.publicKey.toString()) || 'Loading'
|
||||
|
||||
const widgetOptions: ChartingLibraryWidgetOptions = {
|
||||
// debug: true,
|
||||
|
@ -626,11 +625,11 @@ const TradingViewChart = () => {
|
|||
|
||||
console.log('creating new chart')
|
||||
const tvWidget = new widget(widgetOptions)
|
||||
tvWidgetRef.current = tvWidget
|
||||
tvWidgetRef.current.onChartReady(() => {
|
||||
tvWidget.onChartReady(() => {
|
||||
tvWidgetRef.current = tvWidget
|
||||
setChartReady(true)
|
||||
})
|
||||
tvWidgetRef.current.headerReady().then(() => {
|
||||
tvWidget.headerReady().then(() => {
|
||||
setHeaderReady(true)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ const TradingViewChartKline = ({ setIsFullView, isFullView }: Props) => {
|
|||
useEffect(() => {
|
||||
let dataFeed = spotDataFeed
|
||||
const group = mangoStore.getState().group
|
||||
let address = '8BnEgHoWFysVcuFFX7QztDmzuH8r5ZFvyP3sYwn1XTh6'
|
||||
let address = ''
|
||||
|
||||
if (!selectedMarketName?.toLowerCase().includes('perp') && group) {
|
||||
address = group!
|
||||
|
|
Loading…
Reference in New Issue