Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to separate the pairs from the stream? #597

Open
Sexy-Commando opened this issue Aug 2, 2024 · 5 comments
Open

how to separate the pairs from the stream? #597

Sexy-Commando opened this issue Aug 2, 2024 · 5 comments

Comments

@Sexy-Commando
Copy link

i want to process the stream as it arrives and i have no idea how to do that. the stream arrives in this variable event,and i need to separate the pairs so that i can process them.so i can't loop through it,i can't use string separator,i can't add it to a map.how to do this?

func main() {
pairs := map[string]string{"ETHBTC":"1s","BTCUSDT":"1s","LTCBTC":"1s"}
wsKlineHandler := func(event *binance.WsKlineEvent) {
fmt.Println(event.Symbol,event.Kline.Open)
}
errHandler := func(err error) {
fmt.Println(err)
}
doneC, _, err := binance.WsCombinedKlineServe(pairs, wsKlineHandler, errHandler)
if err != nil {
fmt.Println(err)
return
}
<-doneC
}

this is the stream i get

ETHBTC 0.05150000
LTCBTC 0.00110300
BTCUSDT 66311.48000000

@xyq-c-cpp
Copy link
Collaborator

what do you want to do in the wsKlineHandler ? @Sexy-Commando

@Sexy-Commando
Copy link
Author

the stream arrives in variable event in wsKlineHandler,but the pairs come as a whole.i want to separate the pairs as separate strings.
this is the stream i get

ETHBTC 0.05150000
LTCBTC 0.00110300
BTCUSDT 66311.48000000
lets say i want to add them to database and i need to separate the stream i get into separate strings
and add it to db.
ETHBTC 0.05150000 and add to database
,then LTCBTC 0.00110300 add to database
,BTCUSDT 66311.48000000 add to database etc...
so how do i split the stream i get?
can it be done? @xyq-c-cpp

@xyq-c-cpp
Copy link
Collaborator

why the pairs come as a whole? it's just a single object pointer in wsKlineHandler, you know, you just handle the single object pointer and then add it to database. @Sexy-Commando

@Sexy-Commando
Copy link
Author

but how do i do that? i have no idea. could you provide an example?
@xyq-c-cpp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@xyq-c-cpp @Sexy-Commando and others