Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
1,063 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/alpacahq/alpaca-trade-api-go/alpaca" | ||
"github.com/alpacahq/alpaca-trade-api-go/common" | ||
"github.com/alpacahq/alpaca-trade-api-go/v2/stream" | ||
) | ||
|
||
func main() { | ||
// You can set your credentials here in the code, or (preferably) via the | ||
// APCA_API_KEY_ID and APCA_API_SECRET_KEY environment variables | ||
apiKey := "YOUR_API_KEY_HERE" | ||
apiSecret := "YOUR_API_SECRET_HERE" | ||
if common.Credentials().ID == "" { | ||
os.Setenv(common.EnvApiKeyID, apiKey) | ||
} | ||
if common.Credentials().Secret == "" { | ||
os.Setenv(common.EnvApiSecretKey, apiSecret) | ||
} | ||
|
||
stream.UseFeed("sip") | ||
|
||
if err := stream.SubscribeTradeUpdates(tradeUpdateHandler); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := stream.SubscribeTrades(tradeHandler, "AAPL"); err != nil { | ||
panic(err) | ||
} | ||
|
||
if err := stream.SubscribeQuotes(quoteHandler, "MSFT"); err != nil { | ||
panic(err) | ||
} | ||
if err := stream.SubscribeBars(barHandler, "IBM"); err != nil { | ||
panic(err) | ||
} | ||
|
||
select {} | ||
} | ||
|
||
func tradeUpdateHandler(update alpaca.TradeUpdate) { | ||
fmt.Println("trade update", update) | ||
} | ||
|
||
func tradeHandler(trade stream.Trade) { | ||
fmt.Println("trade", trade) | ||
} | ||
|
||
func quoteHandler(quote stream.Quote) { | ||
fmt.Println("quote", quote) | ||
} | ||
|
||
func barHandler(bar stream.Bar) { | ||
fmt.Println("bar", bar) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.