alpacahq / alpaca-trade-api-go

Go client for Alpaca's trade API
Apache License 2.0
328 stars 93 forks source link

No trade updates for crypto orders/positions #205

Open Grimmble opened 2 years ago

Grimmble commented 2 years ago

Hi,

Ver: github.com/alpacahq/alpaca-trade-api-go/v2 v2.5.0

Seems that trade updates using the client.StreamTradeUpdates() functionality differ quite a bit from stocks to crypto. For stocks I would be notified of any new, rejected, fill etc. type of events, doesn't seem to be the case for crypto where I've only been able to get canceled events.

Is there a different implementation for crypto streams? Or are the events different for crypto? (the docs doesn't give a clear indication about this)

NOTE: The code below works fine for stocks

// Start the trade client
client := alpaca.NewClient(alpaca.ClientOpts{
  ApiKey:     "***",
  ApiSecret:  "***",
  BaseURL:    "https://paper-api.alpaca.markets",
  RetryLimit: 100,
  RetryDelay: 5 * time.Second,
})

handler := func(tu alpaca.TradeUpdate) {
  fmt.Printf("NEW EVENT: %+v\n", tu)
}

err := client.StreamTradeUpdates(context.Background(), handler)
Grimmble commented 2 years ago

Small update:

This seem specific to stop_limit type crypto orders. E.g. for SOLUSD: Tried placing a market order and a new + fill event was immidately picked up by the client.StreamTradeUpdates() handler. Then I tried placing a stop_limit order and no new event is picked up by the client.StreamTradeUpdates() handler (even though it show up in the Alpaca UI as "new")