-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* rest endpoint changes * location added * minimum changes for the crypto future * Add an example for crypto-perps * Add crypto perp market data support (stream and rest) * Add marketdata REST example for crypto perp endpoints * Fixed lint issues * Apply changes suggested via PR feedback * Bugfix in GetLatestCryptoPerpBars * Added GetLatestCryptoPerpBars --------- Co-authored-by: manoj <[email protected]>
- Loading branch information
1 parent
4ca59cf
commit a2396c6
Showing
7 changed files
with
370 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/alpacahq/alpaca-trade-api-go/v3/marketdata" | ||
"github.com/alpacahq/alpaca-trade-api-go/v3/marketdata/stream" | ||
) | ||
|
||
func main() { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
baseURL := "ws://stream.data.alpaca.markets/v1beta1/crypto-perps" | ||
|
||
c := stream.NewCryptoPerpClient( | ||
marketdata.GLOBAL, | ||
stream.WithLogger(stream.DefaultLogger()), | ||
stream.WithBaseURL(baseURL), // Set the base URL | ||
// configuring initial subscriptions and handlers | ||
stream.WithCryptoPerpTrades(func(ct stream.CryptoPerpTrade) { | ||
fmt.Printf("TRADE: %+v\n", ct) | ||
}, "BTC-PERP"), | ||
stream.WithCryptoPerpQuotes(func(cq stream.CryptoPerpQuote) { | ||
fmt.Printf("QUOTE: %+v\n", cq) | ||
}, "BTC-PERP"), | ||
stream.WithCryptoPerpOrderbooks(func(cob stream.CryptoPerpOrderbook) { | ||
fmt.Printf("ORDERBOOK: %+v\n", cob) | ||
}, "BTC-PERP"), | ||
stream.WithCryptoPerpBars(func(cb stream.CryptoPerpBar) { | ||
fmt.Printf("BAR: %+v\n", cb) | ||
}, "BTC-PERP"), | ||
stream.WithCryptoPerpUpdatedBars(func(cb stream.CryptoPerpBar) { | ||
fmt.Printf("UPDATED BAR: %+v\n", cb) | ||
}, "BTC-PERP"), | ||
stream.WithCryptoPerpDailyBars(func(cb stream.CryptoPerpBar) { | ||
fmt.Printf("DAILY BAR: %+v\n", cb) | ||
}, "BTC-PERP"), | ||
) | ||
|
||
if err := c.Connect(ctx); err != nil { | ||
panic(err) | ||
} | ||
if err := <-c.Terminated(); err != nil { | ||
panic(err) | ||
} | ||
} |
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
Oops, something went wrong.