alpacahq / Alpaca-API

The Alpaca API is a developer interface for trading operations and market data reception through the Alpaca platform.
https://alpaca.markets/
142 stars 13 forks source link

Add price of purchase #65

Closed gjtorikian closed 5 years ago

gjtorikian commented 5 years ago

If I place a market order like so:

    buyOrderRequest := alpaca.PlaceOrderRequest{
        AccountID:   account.ID,
        AssetKey:    &stock,
        Qty:         quantity,
        Side:        alpaca.Buy,
        Type:        alpaca.Market,
        TimeInForce: alpaca.Day,
    }

    resp, err = alpacaClient.PlaceOrder(buyOrderRequest)

It would be nice to get data on what the actual buy price was. As it stands, although the market order is filled instantly, there is no guarantee that it's at the price I expected and that slippage did not occur. This would also be advantageous for limit orders: I place a limit_order, but I would like to know from the resulting Order entity what that price was!

bdowling commented 5 years ago

Order execution is an asynchronous operation. If you later query the order API for the order ID you can see that it includes a filled_avg_price that should answer your question. The streaming API will also return this data and is good to utilize for faster execution details.

BTW if you in the future your issues are with a particular client library, posting the issues in the language repo may be better.

Thanks, Brian

codebeaulieu commented 5 years ago

I ran into this before but I think the issue is that what is being returned isn't your filled order, its returning your new pending order. Even if it was filled immediately.

In other words, rather than waiting for a response that your order has been filled, its a receipt or a way of communicating that your order was successfully received.

Maybe I'm wrong on this, this is just how I think about this endpoint.

gjtorikian commented 5 years ago

Maybe I'm wrong on this, this is just how I think about this endpoint.

You're both right! 😆

Sounds like I need to hold on to the order_id until the order is fulfilled, and then check the filled_avg_price.

BTW if you in the future your issues are with a particular client library, posting the issues in the language repo may be better.

Sorry about that. My question was language idempotent but I felt like this example showed what I was saying.