/    Sign up×
Community /Pin to ProfileBookmark

Hello Friends, someone can help with a little thing with WebSocket ?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@NogDogNov 23.2021 — > @romi1234567#1639744 someone can help with a little thing with WebSocket ?

Post your question and see. (This is a forum for public exchange of questions and answers. ;) )
Copy linkTweet thisAlerts:
@romi1234567authorNov 23.2021 — import React from 'react'

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

import HeaderItems from './HeaderItems'




export default function () {

const [coinData, setcoinData] = useState([])

const [price, setprice] = useState()





useEffect(() => {

const getdata= async()=>{

try {
const res = await new WebSocket ('wss://wstest.fxempire.com?token=btctothemoon')
const apicall = {
"type":"SUBSCRIBE",
"instruments":["cc-btc-usd-cccagg"],

}

res.onopen = (e)=>{
res.send(JSON.stringify(apicall))


}
res.onmessage = (e)=>{

const ans = JSON.parse(e.data)
setcoinData(ans)
console.log(ans.last);

}



This is the server response:

{cc-btc-usd-cccagg: {…}}cc-btc-usd-cccagg:

base: "BTC"

change: -1329.5599999999977

high: 59507.93

historicalClose: {1week: 60108.9, 1month: 61313.09

, 3month: 49521.06, ytd: 28972.4,

1year: 18385.74, …}

last: 56788.01

lastUpdate: "2021-11-23T01:25:30.000Z"

low: 55663.21

marketCap: 1071811562667.06

open: 58117.57

percentChange: -2.29

quote: "USD"quoteSymbol: "$

"supply: 18873906tickTime: "2021-11-23 01:25"volume: 39917.07258976

[[Prototype]]: Object[[Prototype]]:

Object

Header.jsx:35 undefined


for some reason when i try to console "last" value with (ans.last) it give back undefind ):
Copy linkTweet thisAlerts:
@NogDogNov 23.2021 — [[58],[2,4,52]]
×

Success!

Help @romi1234567 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.24,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...