File tree Expand file tree Collapse file tree 2 files changed +54
-4
lines changed Expand file tree Collapse file tree 2 files changed +54
-4
lines changed Original file line number Diff line number Diff line change @@ -27,11 +27,15 @@ func main() {
2727 incomingQuotes := make (chan robinhood.Quote )
2828 outgoingDecisions := make (chan map [string ]int )
2929
30- go liveProducer ( conf , client , incomingQuotes )
31- go algo ( incomingQuotes , outgoingDecisions )
32- go broker ( outgoingDecisions )
30+ for _ , symbol := range conf . Symbols {
31+ fmt . Println ( robinhood . GetInstrumentID ( symbol , client ) )
32+ }
3333
34- select {}
34+ // go liveProducer(conf, client, incomingQuotes)
35+ // go algo(incomingQuotes, outgoingDecisions)
36+ // go broker(outgoingDecisions)
37+ //
38+ // select {}
3539}
3640
3741func liveProducer (conf config.Config , client * http.Client , c chan robinhood.Quote ) {
Original file line number Diff line number Diff line change 1+ package robinhood
2+
3+ import (
4+ "encoding/json"
5+ "net/http"
6+ )
7+
8+ type InstrumentList struct {
9+ List []Instrument `json:"results"`
10+ NextPage string `json:"next"`
11+ }
12+
13+ type Instrument struct {
14+ Symbol string `json:"symbol"`
15+ ID string `json:"id"`
16+ }
17+
18+ func GetInstrumentID (symbol string , client * http.Client ) (id string , err error ) {
19+ instrumentList := InstrumentList {}
20+
21+ // Create the new request
22+ req , err := http .NewRequest ("GET" , "https://api.robinhood.com/instruments/" , nil )
23+ if err != nil {
24+ return "" , err
25+ }
26+
27+ query := req .URL .Query ()
28+ query .Add ("symbol" , symbol )
29+ req .URL .RawQuery = query .Encode ()
30+
31+ // Execute request
32+ resp , err := client .Do (req )
33+ if err != nil {
34+ return "" , err
35+ }
36+
37+ defer resp .Body .Close ()
38+
39+ // Decode the body using the initialized quotes struct
40+ err = json .NewDecoder (resp .Body ).Decode (& instrumentList )
41+ if err != nil {
42+ return "" , err
43+ }
44+
45+ return instrumentList .List [0 ].ID , nil
46+ }
You can’t perform that action at this time.
0 commit comments