Hi. I’m using the alpaca-trade-api-go to get streaming quotes. And there’s 2 things I can’t figure out how to do with stream.SubscribeQuotes…probably due to my inexperience.
First up, stream.SubscribeQuotes takes a func and then a bunch of strings. Not an array of strings; but an unlimited amout of individual strings. How can I take an array of strings that hold my stock symbols and pipe them into stream.SubscribeQuotes?
Second, I can’t figure out how to get the quotes into a table widget I created with termui. The table widget was created in another file. I want the quoteHandler function to append lines to the table widget’s data property. But I don’t know how to pass the table widget to my quoteHandler.
Here’s the code. Any help would be much appreciated!
package main
import (
"fmt"
"log"
"github.com/gizak/termui/v3/widgets"
"github.com/alpacahq/alpaca-trade-api-go/v2/stream"
)
func SubQuotes(w0 *widgets.Table){
mySymbols := string[]{"MSFT","AMD"} //how do I put this into SubscribeQuotes?
if err := stream.SubscribeQuotes(quoteHandler, "MSFT", "AMD"); err != nil {
log.Fatal(err)
}
}
func quoteHandler(quote stream.Quote) { // How do I get w0 into this function?
data := []string{quote.Symbol, fmt.Sprint(quote.AskSize), fmt.Sprint(quote.AskPrice),fmt.Sprint(quote.BidPrice),fmt.Sprint(quote.BidSize)}
w0.Rows = append(w0.Rows, data) //this line won't work until I figure out how to pass w0
fmt.Println(data)
}