C
C#10mo ago
Isaaaak

Protocol buffer from Yahoo Finance API

I'm trying to pull data (specifically "price") from a websocket (wss://streamer.finance.yahoo.com/), and it works great. The problem is that the data is in a protocol buffer format. I have the .proto file to decode this data, but I don't actually understand how to do it in C#. It works on an online protobuf decoder (https://www.protobufpal.com/), so I know there is no issue with my .proto file or the data (see image). I tried a few different ways but I just can't get it to work. I'm a beginner in C# so don't know all the concepts.
No description
No description
31 Replies
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Jimmacle
Jimmacle10mo ago
i'm using https://github.com/protobuf-net/protobuf-net for my current project, it also has a source generator package to generate models from .proto files
GitHub
GitHub - protobuf-net/protobuf-net: Protocol Buffers library for id...
Protocol Buffers library for idiomatic .NET . Contribute to protobuf-net/protobuf-net development by creating an account on GitHub.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
Well, I don't know how to get that base64 protobuf thing to turn into an object with the property "price". Or like any way to access "price" (see first screenshot). I suppose "doesn't work" is the wrong wording, more like I just can't figure it out I've seen some tutorials and people mentioning this. Maybe I should just go with this instead of googles version. Going to try it
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
it isn't
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
It's just a websocket right now
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
uh idk about that, the websocket works fine I just kind of stole it of a tutorial
MODiX
MODiX10mo ago
TeBeCo
a github repo link might help if you push that code above
Quoted by
React with ❌ to remove this embed.
Isaaaak
Isaaaak10mo ago
GitHub
GitHub - izzeww/YahooFinanceWebSocket
Contribute to izzeww/YahooFinanceWebSocket development by creating an account on GitHub.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
ye
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
Those strings you see, they are base64 protobuf:s
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
I need to convert them into objects, or JSON or something like that, so I can access the properties (like "price") no this part is the issue I'm gonna read up a bit on protobuf-net and try it out
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
thanks, gonna try that
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
wooah
MODiX
MODiX10mo ago
TeBeCo
Convert.FromBase64 then give it to proto reader/serializer
Quoted by
React with ❌ to remove this embed.
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
think it's supposed to be that way
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
true, seems weird ye it's an index, so it's right You can change it to something else if you want, like "ES=F"
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
string message = "{\"subscribe\":[\"ETH-USD\", \"BTC-USD\", \"YM=F\", \"ES=F\", \"QM=F\", \"RTY=F\", \"MNQ=F\", \"NQ=F\"]}";
string message = "{\"subscribe\":[\"ETH-USD\", \"BTC-USD\", \"YM=F\", \"ES=F\", \"QM=F\", \"RTY=F\", \"MNQ=F\", \"NQ=F\"]}";
Unknown User
Unknown User10mo ago
Message Not Public
Sign In & Join Server To View
Isaaaak
Isaaaak10mo ago
thanks you so much, didn't realize it was that "simple" (really very hard, for me)
Want results from more Discord servers?
Add your server