alpaca-trade-api-csharp icon indicating copy to clipboard operation
alpaca-trade-api-csharp copied to clipboard

[QUESTION]: Using the IOptionContract interface

Open cdeMonkey opened this issue 10 months ago • 1 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

What is your question?

Hi, how can I get the current Asset Price of an options Contract? I can only see the last close price which is a day behind.

Anything else?

No response

cdeMonkey avatar Apr 01 '24 14:04 cdeMonkey

@cdeMonkey Sorry for the delayed answer, I was on vacation last week. I hope you've already figured out that SDK has the IAlpacaOptionsDataClient interface and this interface has the ListLatestTradesAsync method that allows you to get required data for one or many option contracts like this:

var key = new SecretKey("...", "...");
using var client = Environments.Live.GetAlpacaOptionsDataClient(key);

var trades= await client.ListLatestTradesAsync(new LatestOptionsDataRequest(["AAPL241220C00300000"]));
Console.WriteLine(trades["AAPL241220C00300000"]);

You can also use the ListLatestQuotesAsync method or even the ListSnapshotsAsync method for getting both the latest quote and trade information in a single response.

OlegRa avatar Apr 07 '24 10:04 OlegRa