alpacahq / alpaca-trade-api-csharp

C# SDK for Alpaca Trade API https://docs.alpaca.markets/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[QUESTION]: Using the IOptionContract interface

cdeMonkey opened this issue · comments

Is there an existing issue for this?

  • 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 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.