[BUG]: 5000+ Assets are labeled PtPNoException starting 4th of march 2024
IvoTops opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
The list of active us-equity assets returns around 11500 assets. Before march 4 around 110 would have the PtPNoException flag set. Since march the 4th around 5200 assets have it set.
Expected Behavior
The 110 instruments was and is correct (I checked with the helpdesk). So the flag must be incorrectly reported as being set starting with a recent api update or some other change.
Steps To Reproduce
// This code will query all active us equities and check the PtPNoException flag. It should only be true for around 110 out of 11500 assets
var assets = await _alpacaTradingAPI.ListAssetsAsync(new AssetsRequest() { AssetStatus = AssetStatus.Active, AssetClass = AssetClass.UsEquity });
if (assets == null) return false;
var alpDate = DateOnly.FromDateTime(TimeZones.ConvertFromUTCtoEST(DateTime.UtcNow));
foreach (var a in assets)
{
if (a == null) continue;
var isPTP = a.Attributes != null && a.Attributes.Any(q => q.HasFlag(AssetAttributes.PtpNoException));
}
Environment
- SDK Version: 7.0.x
- OS (version, bitness): Windows 11
- .NET SDK (version): 8.x
- target process .NET version/bitness: 8.0.x
Hi @IvoTops, you treat the AssetAttributes
enum as an enum with the Flags
attribute but it's not true. The enum values are just continuous numbers and there is a reason why every asset has an array of such attributes not just a single value.
I run this code snippet (with a valid key/secret pair):
var key = new SecretKey("...", "...");
using var client = Environments.Live.GetAlpacaTradingClient(key);
var assets = await client.ListAssetsAsync(new AssetsRequest
{
AssetStatus = AssetStatus.Active, AssetClass = AssetClass.UsEquity
});
var attributes = assets.SelectMany(asset => asset.Attributes).ToHashSet();
Console.WriteLine($"Assets: {assets.Count}");
Console.WriteLine($"Attributes: {attributes.Count}");
foreach (var attribute in attributes)
{
Console.WriteLine(
$"\t{attribute} : {assets.Count(asset => asset.Attributes.Contains(attribute))}");
}
and it produces the next result:
Assets: 11643
Attributes: 4
OptionsEnabled : 5546
FractionalAtExtended : 5185
PtpNoException : 50
PtpWithException : 60
I've cross-checked it using cURL and all these values are correct.