Skip to content

Commit

Permalink
Apply changes suggested via PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
chathumi-k committed Dec 13, 2024
1 parent 47027d0 commit afbb472
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 222 deletions.
15 changes: 7 additions & 8 deletions examples/crypto-perp-stream/crypto_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,27 @@ func main() {

baseURL := "ws://stream.data.alpaca.markets/v1beta1/crypto-perps"

// Creating a client that connects to iex
c := stream.NewCryptoPerpsClient(
c := stream.NewCryptoPerpClient(
marketdata.GLOBAL,
stream.WithLogger(stream.DefaultLogger()),
stream.WithBaseURL(baseURL), // Set the base URL
// configuring initial subscriptions and handlers
stream.WithCryptoPerpsTrades(func(ct stream.CryptoPerpsTrade) {
stream.WithCryptoPerpTrades(func(ct stream.CryptoPerpTrade) {
fmt.Printf("TRADE: %+v\n", ct)
}, "BTC-PERP"),
stream.WithCryptoPerpsQuotes(func(cq stream.CryptoPerpsQuote) {
stream.WithCryptoPerpQuotes(func(cq stream.CryptoPerpQuote) {
fmt.Printf("QUOTE: %+v\n", cq)
}, "BTC-PERP"),
stream.WithCryptoPerpsOrderbooks(func(cob stream.CryptoPerpsOrderbook) {
stream.WithCryptoPerpOrderbooks(func(cob stream.CryptoPerpOrderbook) {
fmt.Printf("ORDERBOOK: %+v\n", cob)
}, "BTC-PERP"),
stream.WithCryptoPerpsBars(func(cb stream.CryptoPerpsBar) {
stream.WithCryptoPerpBars(func(cb stream.CryptoPerpBar) {
fmt.Printf("BAR: %+v\n", cb)
}, "BTC-PERP"),
stream.WithCryptoPerpsUpdatedBars(func(cb stream.CryptoPerpsBar) {
stream.WithCryptoPerpUpdatedBars(func(cb stream.CryptoPerpBar) {
fmt.Printf("UPDATED BAR: %+v\n", cb)
}, "BTC-PERP"),
stream.WithCryptoPerpsDailyBars(func(cb stream.CryptoPerpsBar) {
stream.WithCryptoPerpDailyBars(func(cb stream.CryptoPerpBar) {
fmt.Printf("DAILY BAR: %+v\n", cb)
}, "BTC-PERP"),
)
Expand Down
20 changes: 10 additions & 10 deletions examples/marketdata/marketdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,26 @@ func cryptoQuote() {
fmt.Println()
}

func cryptoPerpsQuote() {
quote, err := marketdata.GetLatestCryptoPerpsQuote("BTC-PERP", marketdata.GetLatestCryptoQuoteRequest{})
func cryptoPerpQuote() {
quote, err := marketdata.GetLatestCryptoPerpQuote("BTC-PERP", marketdata.GetLatestCryptoQuoteRequest{})
if err != nil {
panic(err)
}
fmt.Printf("Latest crypto perp quote: %+v\n\n", quote)
fmt.Println()
}

func cryptoPerpsTrade() {
trade, err := marketdata.GetLatestCryptoPerpsTrade("BTC-PERP", marketdata.GetLatestCryptoTradeRequest{})
func cryptoPerpTrade() {
trade, err := marketdata.GetLatestCryptoPerpTrade("BTC-PERP", marketdata.GetLatestCryptoTradeRequest{})
if err != nil {
panic(err)
}
fmt.Printf("Latest crypto perp trade: %+v\n\n", trade)
fmt.Println()
}

func cryptoPerpsBar() {
trade, err := marketdata.GetLatestCryptoPerpsBar("BTC-PERP", marketdata.GetLatestCryptoBarRequest{})
func cryptoPerpBar() {
trade, err := marketdata.GetLatestCryptoPerpBar("BTC-PERP", marketdata.GetLatestCryptoBarRequest{})
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -236,16 +236,16 @@ func main() {
{Name: "news", Func: news},
{Name: "auctions", Func: auctions},
{Name: "crypto_quote", Func: cryptoQuote},
{Name: "crypto_perp_quote", Func: cryptoPerpsQuote},
{Name: "crypto_perp_trade", Func: cryptoPerpsTrade},
{Name: "crypto_perp_bar", Func: cryptoPerpsBar},
{Name: "crypto_perp_quote", Func: cryptoPerpQuote},
{Name: "crypto_perp_trade", Func: cryptoPerpTrade},
{Name: "crypto_perp_bar", Func: cryptoPerpBar},
{Name: "option_chain", Func: optionChain},
{Name: "corporate_actions", Func: corporateActions},
}
for {
fmt.Println("Examples: ")
for i, e := range examples {
fmt.Printf("[ %d ] %s\n", i, e.Name)
fmt.Printf("[ %2d ] %s\n", i, e.Name)
}
fmt.Print("Please type the number of the example you'd like to run or q to exit: ")
r := bufio.NewReader(os.Stdin)
Expand Down
8 changes: 4 additions & 4 deletions marketdata/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,10 @@ type CryptoSnapshot struct {
PrevDailyBar *CryptoBar `json:"prevDailyBar"`
}

type CryptoPerpsTrade CryptoTrade
type CryptoPerpsQuote CryptoQuote
type CryptoPerpsBar CryptoBar
type CryptoPerpsSnapshot CryptoSnapshot
type CryptoPerpTrade CryptoTrade
type CryptoPerpQuote CryptoQuote
type CryptoPerpBar CryptoBar
type CryptoPerpSnapshot CryptoSnapshot

// CryptoSnapshots is the snapshots for multiple crypto symbols
type CryptoSnapshots struct {
Expand Down
Loading

0 comments on commit afbb472

Please sign in to comment.