├── .all-contributorsrc ├── .config └── dotnet-tools.json ├── .editorconfig ├── .gitattributes ├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── --bug-report.yaml │ ├── --documentation-improvement.yaml │ ├── --feature-request.yaml │ ├── --general-question.yaml │ └── config.yml ├── PULL_REQUEST_TEMPLATE.md ├── dependabot.yml └── workflows │ ├── codeql-analysis.yml │ ├── documentation.yml │ ├── lockfiles.yml │ └── release.yml ├── .gitignore ├── Alpaca.Markets.Extensions.Tests ├── Alpaca.Markets.Extensions.Tests.csproj ├── AlpacaCryptoDataClientTest.cs ├── AlpacaCryptoStreamingClientTest.cs ├── AlpacaDataClientTest.Auctions.cs ├── AlpacaDataClientTest.Bars.cs ├── AlpacaDataClientTest.News.cs ├── AlpacaDataClientTest.Quotes.cs ├── AlpacaDataClientTest.Trades.cs ├── AlpacaDataClientTest.cs ├── AlpacaDataStreamingClientTest.Bars.cs ├── AlpacaDataStreamingClientTest.Cancellations.cs ├── AlpacaDataStreamingClientTest.Corrections.cs ├── AlpacaDataStreamingClientTest.Lulds.cs ├── AlpacaDataStreamingClientTest.Quotes.cs ├── AlpacaDataStreamingClientTest.Statuses.cs ├── AlpacaDataStreamingClientTest.Trades.cs ├── AlpacaDataStreamingClientTest.cs ├── AlpacaDataSubscriptionExtensions.cs ├── AlpacaDataSubscriptionTest.cs ├── AlpacaNewsStreamingClientTest.cs ├── AlpacaOptionsDataClientTest.Bars.cs ├── AlpacaOptionsDataClientTest.Snapshots.cs ├── AlpacaOptionsDataClientTest.Trades.cs ├── AlpacaOptionsDataClientTest.cs ├── AlpacaTradingClientTest.cs ├── AlpacaValueTaskTest.cs ├── BracketTest.cs ├── EnvironmentTest.cs ├── GlobalUsings.cs ├── MockClient.cs ├── MockClientsFactory.cs ├── ServiceCollectionTest.cs ├── StatisticsTest.cs ├── StreamingDataClientTest.cs └── WithReconnectTest.cs ├── Alpaca.Markets.Extensions ├── Alpaca.Markets.Extensions.csproj ├── Alpaca.Markets.Extensions.csproj.DotSettings ├── AlpacaProxy │ └── EnvironmentExtensions.cs ├── AsyncTasks │ └── AlpacaValueTask.cs ├── Cache │ └── AlpacaTradingClientExtensions.cs ├── CompatibilitySuppressions.xml ├── GlobalSuppressions.cs ├── IHttpClient │ └── AlpacaServiceCollectionExtensions.cs ├── Orders │ ├── Bracket.cs │ └── OrderSideExtensions.cs ├── Pagination │ ├── AlpacaDataClientExtensions.cs │ ├── AlpacaOptionsDataClientExtensions.cs │ ├── AlpacaTradingClientExtensions.cs │ ├── HistoricalBarsClientExtensions.cs │ ├── HistoricalQuotesClientExtensions.cs │ ├── HistoricalTradesClientExtensions.cs │ └── PaginationExtensions.cs ├── PublicAPI.Shipped.txt ├── PublicAPI.Unshipped.txt ├── README.md ├── Reconnection │ ├── AlpacaCryptoStreamingClientExtensions.cs │ ├── AlpacaDataStreamingClientExtensions.cs │ ├── AlpacaNewsStreamingClientExtensions.cs │ ├── AlpacaStreamingClientExtensions.cs │ ├── ClientWithReconnectBase.cs │ ├── ClientWithSubscriptionReconnectBase.cs │ └── ReconnectionParameters.cs ├── Statistics │ ├── EnumerableExtensions.cs │ └── HistoricalBarsClientExtensions.cs ├── Subscriptions │ ├── AlpacaCryptoStreamingClientExtensions.cs │ ├── AlpacaDataStreamingClientExtensions.cs │ ├── AlpacaDataSubscriptionContainer.cs │ ├── AlpacaDataSubscriptionExtensions.cs │ ├── AlpacaNewsStreamingClientExtensions.cs │ ├── DisposableAlpacaDataSubscription.cs │ ├── IDisposableAlpacaDataSubscription.cs │ ├── StreamingClientExtensions.cs │ └── StreamingDataClientExtensions.cs ├── TimeInterval │ └── AlpacaTradingClientExtensions.cs └── packages.lock.json ├── Alpaca.Markets.Tests ├── Alpaca.Markets.Tests.csproj ├── AlpacaCryptoDataClientTest.Bars.cs ├── AlpacaCryptoDataClientTest.Latest.cs ├── AlpacaCryptoDataClientTest.Other.cs ├── AlpacaCryptoDataClientTest.Quotes.cs ├── AlpacaCryptoDataClientTest.Snapshot.cs ├── AlpacaCryptoDataClientTest.Trades.cs ├── AlpacaCryptoDataClientTest.cs ├── AlpacaCryptoStreamingClientTest.cs ├── AlpacaDataClientTest.Auctions.cs ├── AlpacaDataClientTest.Bars.cs ├── AlpacaDataClientTest.Latest.cs ├── AlpacaDataClientTest.Meta.cs ├── AlpacaDataClientTest.Other.cs ├── AlpacaDataClientTest.Quotes.cs ├── AlpacaDataClientTest.Snapshot.cs ├── AlpacaDataClientTest.Trades.cs ├── AlpacaDataClientTest.cs ├── AlpacaDataStreamingClientTest.cs ├── AlpacaNewsStreamingClientTest.cs ├── AlpacaOptionsDataClientTest.Bars.cs ├── AlpacaOptionsDataClientTest.Snapshots.cs ├── AlpacaOptionsDataClientTest.Trades.cs ├── AlpacaOptionsDataClientTest.cs ├── AlpacaStreamingClientTest.cs ├── AlpacaTradingClientTest.Account.cs ├── AlpacaTradingClientTest.Actions.cs ├── AlpacaTradingClientTest.Assets.cs ├── AlpacaTradingClientTest.Options.cs ├── AlpacaTradingClientTest.Orders.cs ├── AlpacaTradingClientTest.Positions.cs ├── AlpacaTradingClientTest.Watchlists.cs ├── AlpacaTradingClientTest.cs ├── ConvertersTest.cs ├── DefaultValuesTest.cs ├── ErrorsAndWarningsTracker.cs ├── GlobalUsings.cs ├── HistoricalDataHelpers.cs ├── HistoricalRequestTest.cs ├── IMock.cs ├── IntervalTest.cs ├── MessageDataHelpers.cs ├── MockClientsFactory.cs ├── MockHttpClient.cs ├── MockWsClient.cs ├── OrderTypeTest.cs ├── RequestValidationTest.cs ├── SubscriptionHelper.cs └── ThrottleParametersTest.cs ├── Alpaca.Markets.sln ├── Alpaca.Markets.sln.DotSettings ├── Alpaca.Markets.snk ├── Alpaca.Markets ├── Alpaca.Markets.csproj ├── Alpaca.Markets.csproj.DotSettings ├── AlpacaCryptoDataClient.cs ├── AlpacaCryptoStreamingClient.cs ├── AlpacaDataClient.cs ├── AlpacaDataStreamingClient.cs ├── AlpacaNewsStreamingClient.cs ├── AlpacaOptionsDataClient.cs ├── AlpacaStreamingClient.cs ├── AlpacaTradingClient.General.cs ├── AlpacaTradingClient.Orders.cs ├── AlpacaTradingClient.WatchList.cs ├── AlpacaTradingClient.cs ├── Authentication │ ├── BasicKey.cs │ ├── OAuthKey.cs │ ├── SecretKey.cs │ └── SecurityKey.cs ├── CompatibilitySuppressions.xml ├── DataHistoricalClientBase.cs ├── DataStreamingClientBase.cs ├── Enums │ ├── AccountActivityType.cs │ ├── AccountStatus.cs │ ├── Adjustment.cs │ ├── AssetAttributes.cs │ ├── AssetClass.cs │ ├── AssetStatus.cs │ ├── AuthStatus.cs │ ├── BarTimeFrame.cs │ ├── BarTimeFrameUnit.cs │ ├── ConnectionStatus.cs │ ├── CorporateActionDateType.cs │ ├── CorporateActionFilterType.cs │ ├── CorporateActionSubType.cs │ ├── CorporateActionType.cs │ ├── CryptoExchange.cs │ ├── DayTradeMarginCallProtection.cs │ ├── Exchange.cs │ ├── HistoryPeriodUnit.cs │ ├── IntradayProfitLoss.cs │ ├── IntradayReporting.cs │ ├── JsonAction.cs │ ├── MarketDataFeed.cs │ ├── Multiplier.cs │ ├── OptionStyle.cs │ ├── OptionType.cs │ ├── OptionsFeed.cs │ ├── OptionsTradingLevel.cs │ ├── OrderClass.cs │ ├── OrderSide.cs │ ├── OrderStatus.cs │ ├── OrderStatusFilter.cs │ ├── OrderType.cs │ ├── PositionIntent.cs │ ├── PositionSide.cs │ ├── SortDirection.cs │ ├── TakerSide.cs │ ├── Tape.cs │ ├── TimeFrame.cs │ ├── TimeInForce.cs │ ├── TradeConfirmEmail.cs │ └── TradeEvent.cs ├── Environment │ ├── EnvironmentExtensions.cs │ ├── Environments.cs │ ├── IEnvironment.cs │ ├── LiveEnvironment.cs │ └── PaperEnvironment.cs ├── Exceptions │ ├── RequestValidationException.cs │ └── RestClientErrorException.cs ├── Extensions │ └── ConfigurationExtensions.cs ├── GlobalSuppressions.cs ├── Helpers │ ├── AccountActivityTypeEnumConverter.cs │ ├── ActionExtensions.cs │ ├── ActiveStocksExtensions.cs │ ├── AlpacaScreenerClientExtensions.cs │ ├── AnnouncementExtensions.cs │ ├── AssetAttributesEnumConverter.cs │ ├── AssumeUtcIsoDateTimeConverter.cs │ ├── CryptoExchangeEnumConverter.cs │ ├── CustomTimeZone.cs │ ├── DateOnlyConverter.cs │ ├── DateTimeHelper.cs │ ├── DebuggerDisplayExtensions.cs │ ├── DecimalExtensions.cs │ ├── DictionaryExtensions.cs │ ├── EnumExtensions.cs │ ├── EnumerableExtensions.cs │ ├── ExchangeEnumConverter.cs │ ├── HistoricalRequestBaseExtensions.cs │ ├── HttpClientExtensions.Delete.cs │ ├── HttpClientExtensions.Get.cs │ ├── HttpClientExtensions.Patch.cs │ ├── HttpClientExtensions.Post.cs │ ├── HttpClientExtensions.cs │ ├── HttpResponseMethodExtensions.cs │ ├── HttpStatusCodeExtensions.cs │ ├── IntervalCalenderExtensions.cs │ ├── IntervalExtensions.cs │ ├── JsonNewOrderExtensions.cs │ ├── KeyValuePairExtensions.cs │ ├── ListExtensions.cs │ ├── OpenClose.cs │ ├── OrderExtensions.cs │ ├── OrderQuantity.cs │ ├── OrderSideEnumConverter.cs │ ├── PaginationExtensions.cs │ ├── PositionQuantity.cs │ ├── QueryBuilder.cs │ ├── TimeOnlyConverter.cs │ ├── UnixSecondsDateTimeConverter.cs │ ├── UriBuilderExtensions.cs │ └── Validation.cs ├── Interfaces │ ├── IAccount.cs │ ├── IAccountActivity.cs │ ├── IAccountConfiguration.cs │ ├── IActiveStock.cs │ ├── IAlpacaCryptoDataClient.cs │ ├── IAlpacaCryptoStreamingClient.cs │ ├── IAlpacaDataClient.cs │ ├── IAlpacaDataStreamingClient.cs │ ├── IAlpacaDataSubscription.cs │ ├── IAlpacaNewsStreamingClient.cs │ ├── IAlpacaOptionsDataClient.cs │ ├── IAlpacaScreenerClient.cs │ ├── IAlpacaStreamingClient.cs │ ├── IAlpacaTradingClient.cs │ ├── IAnnouncement.cs │ ├── IAsset.cs │ ├── IAuction.cs │ ├── IAuctionEntry.cs │ ├── IBar.cs │ ├── ICashDividend.cs │ ├── ICashMerger.cs │ ├── IClock.cs │ ├── ICorporateActionsResponse.cs │ ├── ICorrection.cs │ ├── IDictionaryPage.cs │ ├── IErrorInformation.cs │ ├── IForwardSplit.cs │ ├── IGreeks.cs │ ├── IHistoricalBarsClient.cs │ ├── IHistoricalQuotesClient.cs │ ├── IHistoricalRequest.cs │ ├── IHistoricalTradesClient.cs │ ├── IIntervalCalendar.cs │ ├── ILimitUpLimitDown.cs │ ├── IMarketMover.cs │ ├── IMarketMovers.cs │ ├── IMultiPage.cs │ ├── IMultiPageMutable.cs │ ├── INameChange.cs │ ├── INewsArticle.cs │ ├── IOptionContract.cs │ ├── IOptionSnapshot.cs │ ├── IOrder.cs │ ├── IOrderActionStatus.cs │ ├── IOrderBook.cs │ ├── IOrderBookEntry.cs │ ├── IPage.cs │ ├── IPageMutable.cs │ ├── IPortfolioHistory.cs │ ├── IPortfolioHistoryItem.cs │ ├── IPosition.cs │ ├── IPositionActionStatus.cs │ ├── IQuote.cs │ ├── IRedemption.cs │ ├── IReverseSplit.cs │ ├── IRightsDistribution.cs │ ├── ISnapshot.cs │ ├── ISpinOff.cs │ ├── IStatus.cs │ ├── IStockAndCashMerger.cs │ ├── IStockDividend.cs │ ├── IStockMerger.cs │ ├── IStreamingClient.cs │ ├── IStreamingDataClient.cs │ ├── ISubscriptionHandler.cs │ ├── ISymbolMutable.cs │ ├── ITrade.cs │ ├── ITradeUpdate.cs │ ├── IUnitSplit.cs │ ├── IWatchList.cs │ └── IWorthlessRemoval.cs ├── Messages │ ├── JsonAccount.cs │ ├── JsonAccountActivity.cs │ ├── JsonAccountConfiguration.cs │ ├── JsonActiveStock.cs │ ├── JsonActiveStocks.cs │ ├── JsonAnnouncement.cs │ ├── JsonAsset.cs │ ├── JsonAuction.cs │ ├── JsonAuctionEntry.cs │ ├── JsonAuctionsPage.cs │ ├── JsonAuthRequest.cs │ ├── JsonAuthResponse.cs │ ├── JsonAuthentication.cs │ ├── JsonBarsPage.cs │ ├── JsonCalendar.cs │ ├── JsonCashDividend.cs │ ├── JsonCashMerger.cs │ ├── JsonClock.cs │ ├── JsonConnectionSuccess.cs │ ├── JsonCorporateActionsResponse.cs │ ├── JsonCorrection.cs │ ├── JsonCryptoSnapshot.cs │ ├── JsonError.cs │ ├── JsonForwardSplit.cs │ ├── JsonGreeks.cs │ ├── JsonHistoricalBar.cs │ ├── JsonHistoricalCryptoQuote.cs │ ├── JsonHistoricalOrderBook.cs │ ├── JsonHistoricalQuote.cs │ ├── JsonHistoricalTrade.cs │ ├── JsonLatestBar.cs │ ├── JsonLatestBestBidOffer.cs │ ├── JsonLatestData.cs │ ├── JsonLatestQuote.cs │ ├── JsonLatestTrade.cs │ ├── JsonLimitUpLimitDown.cs │ ├── JsonListenRequest.cs │ ├── JsonMarketMover.cs │ ├── JsonMarketMovers.cs │ ├── JsonMultiAuctionsPage.cs │ ├── JsonMultiBarsPage.cs │ ├── JsonMultiQuotesPage.cs │ ├── JsonMultiTradesPage.cs │ ├── JsonNameChange.cs │ ├── JsonNewOrder.cs │ ├── JsonNewOrderAdvancedAttributes.cs │ ├── JsonNewsArticle.cs │ ├── JsonNewsPage.cs │ ├── JsonOptionContract.cs │ ├── JsonOptionContractsPage.cs │ ├── JsonOptionQuote.cs │ ├── JsonOptionSnapshot.cs │ ├── JsonOptionSnapshotsData.cs │ ├── JsonOptionTrade.cs │ ├── JsonOrder.cs │ ├── JsonOrderActionStatus.cs │ ├── JsonOrderBookEntry.cs │ ├── JsonOrderLeg.cs │ ├── JsonPortfolioHistory.cs │ ├── JsonPosition.cs │ ├── JsonPositionActionStatus.cs │ ├── JsonQuotesPage.cs │ ├── JsonRealTimeBar.cs │ ├── JsonRealTimeBase.cs │ ├── JsonRealTimeCryptoQuote.cs │ ├── JsonRealTimeOrderBook.cs │ ├── JsonRealTimeQuote.cs │ ├── JsonRealTimeTrade.cs │ ├── JsonRedemption.cs │ ├── JsonReverseSplit.cs │ ├── JsonRightsDistribution.cs │ ├── JsonSnapshot.cs │ ├── JsonSpinOff.cs │ ├── JsonStockAndCashMerger.cs │ ├── JsonStockDividend.cs │ ├── JsonStockMerger.cs │ ├── JsonStreamError.cs │ ├── JsonSubscriptionUpdate.cs │ ├── JsonTradeUpdate.cs │ ├── JsonTradesPage.cs │ ├── JsonTradingStatus.cs │ ├── JsonUnitSplit.cs │ ├── JsonWatchList.cs │ └── JsonWorthlessRemoval.cs ├── Orders │ ├── AdvancedOrderBase.cs │ ├── BracketOrder.cs │ ├── IStopLoss.cs │ ├── ITakeProfit.cs │ ├── LimitOrder.cs │ ├── MarketOrder.cs │ ├── MultiLegOrder.cs │ ├── OneCancelsOtherOrder.cs │ ├── OrderBase.cs │ ├── OrderBaseExtensions.cs │ ├── OrderLeg.cs │ ├── OrderSideExtensions.cs │ ├── SimpleOrderBase.cs │ ├── StopLimitOrder.cs │ ├── StopLossOrder.cs │ ├── StopOrder.cs │ ├── TakeProfitOrder.cs │ ├── TrailOffset.cs │ └── TrailingStopOrder.cs ├── Parameters │ ├── AccountActivitiesRequest.cs │ ├── AlpacaClientConfigurationBase.cs │ ├── AlpacaCryptoDataClientConfiguration.cs │ ├── AlpacaCryptoStreamingClientConfiguration.cs │ ├── AlpacaDataClientConfiguration.cs │ ├── AlpacaDataStreamingClientConfiguration.cs │ ├── AlpacaNewsStreamingClientConfiguration.cs │ ├── AlpacaOptionsDataClientConfiguration.cs │ ├── AlpacaStreamingClientConfiguration.cs │ ├── AlpacaTradingClientConfiguration.cs │ ├── AnnouncementsRequest.cs │ ├── AssetsRequest.cs │ ├── CalendarRequest.cs │ ├── ChangeOrderRequest.cs │ ├── ChangeWatchListRequest.cs │ ├── CorporateActionsRequest.cs │ ├── DeleteAllPositionsRequest.cs │ ├── DeletePositionRequest.cs │ ├── HistoricalAuctionsRequest.cs │ ├── HistoricalBarsRequest.cs │ ├── HistoricalCryptoBarsRequest.cs │ ├── HistoricalCryptoQuotesRequest.cs │ ├── HistoricalCryptoTradesRequest.cs │ ├── HistoricalOptionBarsRequest.cs │ ├── HistoricalOptionTradesRequest.cs │ ├── HistoricalQuotesRequest.cs │ ├── HistoricalRequestBase.cs │ ├── HistoricalTradesRequest.cs │ ├── HistoryPeriod.cs │ ├── Interval.cs │ ├── LatestDataListRequest.cs │ ├── LatestMarketDataListRequest.cs │ ├── LatestMarketDataRequest.cs │ ├── LatestOptionsDataRequest.cs │ ├── LatestOrderBooksRequest.cs │ ├── ListOrdersRequest.cs │ ├── NewOrderRequest.cs │ ├── NewWatchListRequest.cs │ ├── NewsArticlesRequest.cs │ ├── OptionChainRequest.cs │ ├── OptionContractsRequest.cs │ ├── OptionLegRequest.cs │ ├── OptionSnapshotRequest.cs │ ├── Pagination.cs │ ├── PortfolioHistoryRequest.cs │ ├── SnapshotDataListRequest.cs │ ├── StreamingClientConfiguration.cs │ └── UpdateWatchListRequest.cs ├── PublicAPI.Shipped.txt ├── PublicAPI.Unshipped.txt ├── README.md ├── RateLimit │ ├── IRateLimitProvider.cs │ ├── IRateLimitValues.cs │ ├── RateLimitHandler.cs │ └── RateLimitValues.cs ├── Throttling │ └── ThrottleParameters.cs ├── WebSocket │ ├── ClientWebSocketWrapper.cs │ ├── IWebSocket.cs │ ├── ReceiveResult.cs │ ├── StreamingClientBase.cs │ ├── SynchronizationQueue.cs │ └── WebSocketTransport.cs └── packages.lock.json ├── CONTRIBUTING.md ├── CONTRIBUTORS.md ├── Configuration.xml ├── Documentation ├── .gitignore ├── Documentation.csproj ├── _site │ ├── api │ │ ├── Alpaca.Markets.AccountActivitiesRequest.html │ │ ├── Alpaca.Markets.AccountActivityType.html │ │ ├── Alpaca.Markets.AccountStatus.html │ │ ├── Alpaca.Markets.AdvancedOrderBase.html │ │ ├── Alpaca.Markets.AggregatesRequest.html │ │ ├── Alpaca.Markets.AggregationPeriod.html │ │ ├── Alpaca.Markets.AggregationPeriodUnit.html │ │ ├── Alpaca.Markets.AggregationType.html │ │ ├── Alpaca.Markets.AlpacaDataClient.html │ │ ├── Alpaca.Markets.AlpacaDataClientConfiguration.html │ │ ├── Alpaca.Markets.AlpacaDataStreamingClient.html │ │ ├── Alpaca.Markets.AlpacaDataStreamingClientConfiguration.html │ │ ├── Alpaca.Markets.AlpacaStreamingClient.html │ │ ├── Alpaca.Markets.AlpacaStreamingClientConfiguration.html │ │ ├── Alpaca.Markets.AlpacaTradingClient.html │ │ ├── Alpaca.Markets.AlpacaTradingClientConfiguration.html │ │ ├── Alpaca.Markets.ApiVersion.html │ │ ├── Alpaca.Markets.AssetClass.html │ │ ├── Alpaca.Markets.AssetStatus.html │ │ ├── Alpaca.Markets.AssetsRequest.html │ │ ├── Alpaca.Markets.AuthStatus.html │ │ ├── Alpaca.Markets.BarSetRequest.html │ │ ├── Alpaca.Markets.BracketOrder.html │ │ ├── Alpaca.Markets.CalendarRequest.html │ │ ├── Alpaca.Markets.ChangeOrderRequest.html │ │ ├── Alpaca.Markets.ChangeWatchListRequest-1.html │ │ ├── Alpaca.Markets.DayTradeMarginCallProtection.html │ │ ├── Alpaca.Markets.DeletePositionRequest.html │ │ ├── Alpaca.Markets.EnvironmentExtensions.html │ │ ├── Alpaca.Markets.Environments.html │ │ ├── Alpaca.Markets.Exchange.html │ │ ├── Alpaca.Markets.ExchangeType.html │ │ ├── Alpaca.Markets.HistoricalRequest.html │ │ ├── Alpaca.Markets.HistoryPeriod.html │ │ ├── Alpaca.Markets.HistoryPeriodUnit.html │ │ ├── Alpaca.Markets.IAccount.html │ │ ├── Alpaca.Markets.IAccountActivity.html │ │ ├── Alpaca.Markets.IAccountBase.html │ │ ├── Alpaca.Markets.IAccountConfiguration.html │ │ ├── Alpaca.Markets.IAccountUpdate.html │ │ ├── Alpaca.Markets.IAgg.html │ │ ├── Alpaca.Markets.IAggBase.html │ │ ├── Alpaca.Markets.IAlpacaDataClient.html │ │ ├── Alpaca.Markets.IAlpacaDataStreamingClient.html │ │ ├── Alpaca.Markets.IAlpacaDataSubscription-1.html │ │ ├── Alpaca.Markets.IAlpacaDataSubscription.html │ │ ├── Alpaca.Markets.IAlpacaStreamingClient.html │ │ ├── Alpaca.Markets.IAlpacaTradingClient.html │ │ ├── Alpaca.Markets.IAsset.html │ │ ├── Alpaca.Markets.ICalendar.html │ │ ├── Alpaca.Markets.IClock.html │ │ ├── Alpaca.Markets.IEnvironment.html │ │ ├── Alpaca.Markets.IExchange.html │ │ ├── Alpaca.Markets.IExclusiveTimeInterval.html │ │ ├── Alpaca.Markets.IHistoricalBase.html │ │ ├── Alpaca.Markets.IHistoricalItems-1.html │ │ ├── Alpaca.Markets.IHistoricalQuote.html │ │ ├── Alpaca.Markets.IHistoricalTrade.html │ │ ├── Alpaca.Markets.IInclusiveTimeInterval.html │ │ ├── Alpaca.Markets.ILastQuote.html │ │ ├── Alpaca.Markets.ILastTrade.html │ │ ├── Alpaca.Markets.IOrder.html │ │ ├── Alpaca.Markets.IOrderActionStatus.html │ │ ├── Alpaca.Markets.IPolygonDataClient.html │ │ ├── Alpaca.Markets.IPolygonStreamingClient.html │ │ ├── Alpaca.Markets.IPortfolioHistory.html │ │ ├── Alpaca.Markets.IPortfolioHistoryItem.html │ │ ├── Alpaca.Markets.IPosition.html │ │ ├── Alpaca.Markets.IPositionActionStatus.html │ │ ├── Alpaca.Markets.IQuoteBase-1.html │ │ ├── Alpaca.Markets.IRequestWithTimeInterval-1.html │ │ ├── Alpaca.Markets.IStopLoss.html │ │ ├── Alpaca.Markets.IStreamAgg.html │ │ ├── Alpaca.Markets.IStreamBase.html │ │ ├── Alpaca.Markets.IStreamQuote.html │ │ ├── Alpaca.Markets.IStreamTrade.html │ │ ├── Alpaca.Markets.IStreamingClientBase.html │ │ ├── Alpaca.Markets.ITakeProfit.html │ │ ├── Alpaca.Markets.ITimeInterval.html │ │ ├── Alpaca.Markets.ITimestamps.html │ │ ├── Alpaca.Markets.ITradeUpdate.html │ │ ├── Alpaca.Markets.IWatchList.html │ │ ├── Alpaca.Markets.IWebSocket.html │ │ ├── Alpaca.Markets.IWebSocketFactory.html │ │ ├── Alpaca.Markets.LimitOrder.html │ │ ├── Alpaca.Markets.ListOrdersRequest.html │ │ ├── Alpaca.Markets.MarketDataType.html │ │ ├── Alpaca.Markets.MarketOrder.html │ │ ├── Alpaca.Markets.NewOrderRequest.html │ │ ├── Alpaca.Markets.NewWatchListRequest.html │ │ ├── Alpaca.Markets.OAuthKey.html │ │ ├── Alpaca.Markets.OneCancelsOtherOrder.html │ │ ├── Alpaca.Markets.OrderBase.html │ │ ├── Alpaca.Markets.OrderBaseExtensions.html │ │ ├── Alpaca.Markets.OrderClass.html │ │ ├── Alpaca.Markets.OrderSide.html │ │ ├── Alpaca.Markets.OrderSideExtensions.html │ │ ├── Alpaca.Markets.OrderStatus.html │ │ ├── Alpaca.Markets.OrderStatusFilter.html │ │ ├── Alpaca.Markets.OrderType.html │ │ ├── Alpaca.Markets.PolygonDataClient.html │ │ ├── Alpaca.Markets.PolygonDataClientConfiguration.html │ │ ├── Alpaca.Markets.PolygonStreamingClient.html │ │ ├── Alpaca.Markets.PolygonStreamingClientConfiguration.html │ │ ├── Alpaca.Markets.PortfolioHistoryRequest.html │ │ ├── Alpaca.Markets.PositionSide.html │ │ ├── Alpaca.Markets.RequestValidationException.html │ │ ├── Alpaca.Markets.RestClientErrorException.html │ │ ├── Alpaca.Markets.SecretKey.html │ │ ├── Alpaca.Markets.SecurityKey.html │ │ ├── Alpaca.Markets.SimpleOrderBase.html │ │ ├── Alpaca.Markets.SortDirection.html │ │ ├── Alpaca.Markets.StopLimitOrder.html │ │ ├── Alpaca.Markets.StopLossOrder.html │ │ ├── Alpaca.Markets.StopOrder.html │ │ ├── Alpaca.Markets.StreamingClientBase-1.html │ │ ├── Alpaca.Markets.StreamingClientConfiguration.html │ │ ├── Alpaca.Markets.TakeProfitOrder.html │ │ ├── Alpaca.Markets.ThrottleParameters.html │ │ ├── Alpaca.Markets.TickType.html │ │ ├── Alpaca.Markets.TimeFrame.html │ │ ├── Alpaca.Markets.TimeInForce.html │ │ ├── Alpaca.Markets.TimeInterval.html │ │ ├── Alpaca.Markets.TradeConfirmEmail.html │ │ ├── Alpaca.Markets.TradeEvent.html │ │ ├── Alpaca.Markets.TrailOffset.html │ │ ├── Alpaca.Markets.TrailingStopOrder.html │ │ ├── Alpaca.Markets.UpdateWatchListRequest.html │ │ ├── Alpaca.Markets.html │ │ ├── index.html │ │ └── toc.html │ ├── articles │ │ └── intro.html │ ├── index.html │ ├── manifest.json │ ├── styles │ │ ├── docfx.js │ │ └── search-worker.js │ └── xrefmap.yml ├── api │ ├── .gitignore │ └── index.md ├── articles │ ├── intro.md │ └── toc.yml ├── docfx.json ├── index.md └── toc.yml ├── Icon.png ├── LICENSE ├── Portable.Helpers ├── CallerArgumentExpressionAttribute.cs ├── GlobalSuppressions.cs ├── Index.cs ├── KeyValuePairExtensions.cs ├── NullableHelper.cs ├── Portable.Helpers.projitems ├── Portable.Helpers.shproj ├── Range.cs └── ValidatedNotNullAttribute.cs ├── README.md ├── SECURITY.md └── UsageExamples ├── DateHelperExample.cs ├── IndicatorLibraryExample.cs ├── MeanReversionBrokerage.cs ├── MeanReversionPaperOnly.cs ├── MeanReversionWithCrypto.cs ├── Program.cs ├── README.md └── UsageExamples.csproj /.config/dotnet-tools.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": 1, 3 | "isRoot": true, 4 | "tools": { 5 | "jetbrains.dotcover.globaltool": { 6 | "version": "2023.2.5", 7 | "commands": [ 8 | "dotnet-dotcover" 9 | ] 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*.cs] 2 | 3 | # CS8632: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. 4 | dotnet_diagnostic.CS8632.severity = none 5 | 6 | # IDE0049: Simplify Names 7 | dotnet_style_predefined_type_for_member_access = false:silent 8 | 9 | # IDE0049: Simplify Names 10 | dotnet_style_predefined_type_for_locals_parameters_members = false:silent 11 | 12 | # Define the 'private_methods' symbol group: 13 | dotnet_naming_symbols.private_methods.applicable_kinds = method 14 | dotnet_naming_symbols.private_methods.applicable_accessibilities = private 15 | 16 | # Define the 'private_static_methods' symbol group 17 | dotnet_naming_symbols.private_static_methods.applicable_kinds = method 18 | dotnet_naming_symbols.private_static_methods.applicable_accessibilities = private 19 | dotnet_naming_symbols.private_static_methods.required_modifiers = static 20 | 21 | # Define the 'private_methods_style' naming style 22 | dotnet_naming_style.private_methods_style.capitalization = camel_case 23 | 24 | # Define the 'private_methods_rule' naming rule 25 | dotnet_naming_rule.private_methods_rule.symbols = private_methods 26 | dotnet_naming_rule.private_methods_rule.style = private_methods_style 27 | dotnet_naming_rule.private_methods_rule.severity = error 28 | 29 | # Define the 'private_static_methods_rule' naming rule 30 | dotnet_naming_rule.private_static_methods_rule.symbols = private_static_methods 31 | dotnet_naming_rule.private_static_methods_rule.style = private_methods_style 32 | dotnet_naming_rule.private_static_methods_rule.severity = error -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: [OlegRa] -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/--documentation-improvement.yaml: -------------------------------------------------------------------------------- 1 | name: 📖 Documentation Improvement 2 | description: Suggest improvements to our documentation 3 | title: "[DOCS]: " 4 | labels: [Documentation] 5 | body: 6 | - type: markdown 7 | attributes: 8 | value: | 9 | Thanks for taking the time to fill out this documentation improvement request! 10 | - type: checkboxes 11 | attributes: 12 | label: Is there an existing issue for this? 13 | description: Please search to see if an issue realated to this already exists. 14 | options: 15 | - label: I have searched the existing issues 16 | required: true 17 | - type: textarea 18 | attributes: 19 | label: Documentation Link 20 | description: Add a link to the page which needs improvement (if relevant) 21 | validations: 22 | required: false 23 | - type: textarea 24 | attributes: 25 | label: Describe the problem 26 | description: Is the documentation missing? Or is it confusing? Why is it confusing? 27 | validations: 28 | required: true 29 | - type: textarea 30 | attributes: 31 | label: Describe the improvement 32 | description: A clear and concise description of the improvement. 33 | validations: 34 | required: false 35 | - type: textarea 36 | attributes: 37 | label: Anything else? 38 | description: | 39 | Links? References? Anything that will give us more context about the issue you are encountering! 40 | validations: 41 | required: false 42 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/--general-question.yaml: -------------------------------------------------------------------------------- 1 | name: 🤔 General question 2 | description: Ask a general question about .NET SDK for Alpaca Markets API 3 | title: "[QUESTION]: " 4 | body: 5 | - type: checkboxes 6 | attributes: 7 | label: Is there an existing issue for this? 8 | description: Please search to see if an issue related to this already exists. 9 | options: 10 | - label: I have searched the existing issues 11 | required: true 12 | - type: textarea 13 | attributes: 14 | label: What is your question? 15 | validations: 16 | required: false 17 | - type: textarea 18 | attributes: 19 | label: Anything else? 20 | description: Add any other context, code examples, or references about the question? 21 | validations: 22 | required: false 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | > Pull Request Template 2 | > 3 | > Use this template to quickly create a well written pull request. Delete all quotes before creating the pull request. 4 | 5 | ## Description 6 | 7 | > Please include a summary of the changes and which issue has been fixed. Please also include relevant motivation 8 | > and context. List any dependencies that are required for this change. 9 | 10 | Fixes # (issue) 11 | 12 | > if no issue exists, please create an issue and ask the maintainers about this first 13 | 14 | ## Type of change 15 | 16 | > Please delete options that are not relevant. 17 | 18 | - Bug fix (non-breaking change which fixes an issue) 19 | - New feature (non-breaking change which adds functionality) 20 | - Breaking change (fix or feature that would cause existing functionality to not work as expected) 21 | - This change requires a documentation update 22 | 23 | ## How Has This Been Tested? 24 | 25 | > Please describe the tests that you ran to verify your changes. Provide instructions, so we can reproduce. 26 | > Please also provide code samples if applicable to the PR. 27 | 28 | - Test A 29 | - Test B 30 | 31 | ## Checklist: 32 | 33 | - [ ] My code follows the style guidelines of this project 34 | - [ ] I have performed a self-review of my own code 35 | - [ ] I have commented my code, particularly in hard-to-understand areas 36 | - [ ] I have made corresponding changes to the documentation 37 | - [ ] My changes generate no new warnings 38 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | 4 | # Maintain dependencies for NuGet packages 5 | - package-ecosystem: "nuget" 6 | directory: "/" 7 | schedule: 8 | interval: "daily" 9 | time: "04:00" 10 | open-pull-requests-limit: 10 11 | assignees: 12 | - OlegRa 13 | 14 | # Maintain dependencies for GitHub Actions 15 | - package-ecosystem: "github-actions" 16 | directory: "/" 17 | schedule: 18 | interval: "weekly" 19 | open-pull-requests-limit: 10 20 | assignees: 21 | - OlegRa 22 | -------------------------------------------------------------------------------- /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | name: C# CodeQL Analyis 2 | 3 | on: 4 | push: 5 | pull_request: 6 | branches: [ develop ] 7 | schedule: 8 | - cron: '0 8 * * 1' 9 | 10 | jobs: 11 | analyze: 12 | name: Analyze 13 | runs-on: ubuntu-latest 14 | permissions: 15 | actions: read 16 | contents: read 17 | security-events: write 18 | 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | language: [ 'csharp' ] 23 | 24 | steps: 25 | - name: Checkout repository 26 | uses: actions/checkout@v4 27 | 28 | - name: Setup .NET 9.0.x 29 | uses: actions/setup-dotnet@v4 30 | with: 31 | dotnet-version: '9.0.x' 32 | 33 | - name: Initialize CodeQL 34 | uses: github/codeql-action/init@v3 35 | with: 36 | languages: ${{ matrix.language }} 37 | 38 | - name: Cache NuGet Packages 39 | uses: actions/cache@v4 40 | with: 41 | path: ~/.nuget/packages 42 | key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} 43 | restore-keys: | 44 | ${{ runner.os }}-nuget- 45 | 46 | - name: Dotnet Build 47 | run: dotnet build -c Release 48 | 49 | - name: Perform CodeQL Analysis 50 | uses: github/codeql-action/analyze@v3 51 | -------------------------------------------------------------------------------- /.github/workflows/lockfiles.yml: -------------------------------------------------------------------------------- 1 | name: Update NuGet Lock Files 2 | 3 | on: 4 | pull_request: 5 | branches: [ develop ] 6 | 7 | permissions: 8 | contents: write 9 | 10 | jobs: 11 | lockfiles: 12 | name: Update and Commit 13 | runs-on: ubuntu-latest 14 | if: github.actor == 'dependabot[bot]' 15 | 16 | steps: 17 | - name: Checkout Code 18 | uses: actions/checkout@v4 19 | 20 | - name: Setup .NET 9.0.x 21 | uses: actions/setup-dotnet@v4 22 | with: 23 | dotnet-version: '9.0.x' 24 | 25 | - name: Restore Dependencies 26 | run: dotnet restore --force-evaluate 27 | 28 | - name: Auto-commit changed files 29 | uses: stefanzweifel/git-auto-commit-action@v5 30 | with: 31 | commit_message: Update NuGet lock files after Dependabot dependency update. 32 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaDataStreamingClientTest.Cancellations.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed partial class AlpacaDataStreamingClientTest 4 | { 5 | [Fact] 6 | public void GetCancellationSubscriptionWorks() 7 | { 8 | var client = createMockClient( 9 | client => client.GetCancellationSubscription(It.IsAny())); 10 | 11 | var subscriptionOne = client.Object.GetCancellationSubscription(_symbols); 12 | var subscriptionTwo = client.Object.GetCancellationSubscription(Stock, Other); 13 | 14 | verifySubscriptions(subscriptionOne, subscriptionTwo); 15 | verifySubscriptionEvents(subscriptionOne, ExpectedNumberOfEventsForAllSymbols); 16 | 17 | client.VerifyAll(); 18 | } 19 | 20 | [Fact] 21 | public async Task SubscribeCancellationAsyncWorks() 22 | { 23 | var client = createMockClient( 24 | client => client.GetCancellationSubscription(It.IsAny())); 25 | 26 | await using var subscription = await client.Object.SubscribeCancellationAsync(Stock); 27 | await using var subscriptionOne = await client.Object.SubscribeCancellationAsync(_symbols); 28 | // ReSharper disable once UseAwaitUsing 29 | using var subscriptionTwo = await client.Object.SubscribeCancellationAsync(Stock, Other); 30 | 31 | verifySubscriptions(subscriptionOne, subscriptionTwo); 32 | verifySubscriptionEvents(subscription, ExpectedNumberOfEventsForOneSymbol); 33 | 34 | client.VerifyAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaDataStreamingClientTest.Corrections.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed partial class AlpacaDataStreamingClientTest 4 | { 5 | [Fact] 6 | public void GetCorrectionSubscriptionWorks() 7 | { 8 | var client = createMockClient( 9 | client => client.GetCorrectionSubscription(It.IsAny())); 10 | 11 | var subscriptionOne = client.Object.GetCorrectionSubscription(_symbols); 12 | var subscriptionTwo = client.Object.GetCorrectionSubscription(Stock, Other); 13 | 14 | verifySubscriptions(subscriptionOne, subscriptionTwo); 15 | verifySubscriptionEvents(subscriptionOne, ExpectedNumberOfEventsForAllSymbols); 16 | 17 | client.VerifyAll(); 18 | } 19 | 20 | [Fact] 21 | public async Task SubscribeCorrectionAsyncWorks() 22 | { 23 | var client = createMockClient( 24 | client => client.GetCorrectionSubscription(It.IsAny())); 25 | 26 | await using var subscription = await client.Object.SubscribeCorrectionAsync(Stock); 27 | await using var subscriptionOne = await client.Object.SubscribeCorrectionAsync(_symbols); 28 | // ReSharper disable once UseAwaitUsing 29 | using var subscriptionTwo = await client.Object.SubscribeCorrectionAsync(Stock, Other); 30 | 31 | verifySubscriptions(subscriptionOne, subscriptionTwo); 32 | verifySubscriptionEvents(subscription, ExpectedNumberOfEventsForOneSymbol); 33 | 34 | client.VerifyAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaDataStreamingClientTest.Lulds.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed partial class AlpacaDataStreamingClientTest 4 | { 5 | [Fact] 6 | public void GetLimitUpLimitDownSubscriptionWorks() 7 | { 8 | var client = createMockClient( 9 | client => client.GetLimitUpLimitDownSubscription(It.IsAny())); 10 | 11 | var subscriptionOne = client.Object.GetLimitUpLimitDownSubscription(_symbols); 12 | var subscriptionTwo = client.Object.GetLimitUpLimitDownSubscription(Stock, Other); 13 | 14 | verifySubscriptions(subscriptionOne, subscriptionTwo); 15 | verifySubscriptionEvents(subscriptionOne, ExpectedNumberOfEventsForAllSymbols); 16 | 17 | client.VerifyAll(); 18 | } 19 | 20 | [Fact] 21 | public async Task SubscribeLimitUpLimitDownAsyncWorks() 22 | { 23 | var client = createMockClient( 24 | client => client.GetLimitUpLimitDownSubscription(It.IsAny())); 25 | 26 | await using var subscription = await client.Object.SubscribeLimitUpLimitDownAsync(Stock); 27 | await using var subscriptionOne = await client.Object.SubscribeLimitUpLimitDownAsync(_symbols); 28 | // ReSharper disable once UseAwaitUsing 29 | using var subscriptionTwo = await client.Object.SubscribeLimitUpLimitDownAsync(Stock, Other); 30 | 31 | verifySubscriptions(subscriptionOne, subscriptionTwo); 32 | verifySubscriptionEvents(subscription, ExpectedNumberOfEventsForOneSymbol); 33 | 34 | client.VerifyAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaDataStreamingClientTest.Quotes.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed partial class AlpacaDataStreamingClientTest 4 | { 5 | [Fact] 6 | public void GetQuoteSubscriptionWorks() 7 | { 8 | var client = createMockClient( 9 | client => client.GetQuoteSubscription(It.IsAny())); 10 | 11 | var subscriptionOne = client.Object.GetQuoteSubscription(_symbols); 12 | var subscriptionTwo = client.Object.GetQuoteSubscription(Stock, Other); 13 | 14 | verifySubscriptions(subscriptionOne, subscriptionTwo); 15 | verifySubscriptionEvents(subscriptionOne, ExpectedNumberOfEventsForAllSymbols); 16 | 17 | client.VerifyAll(); 18 | } 19 | 20 | [Fact] 21 | public async Task SubscribeQuoteAsyncWorks() 22 | { 23 | var client = createMockClient( 24 | client => client.GetQuoteSubscription(It.IsAny())); 25 | 26 | await using var subscription = await client.Object.SubscribeQuoteAsync(Stock); 27 | await using var subscriptionOne = await client.Object.SubscribeQuoteAsync(_symbols); 28 | // ReSharper disable once UseAwaitUsing 29 | using var subscriptionTwo = await client.Object.SubscribeQuoteAsync(Stock, Other); 30 | 31 | verifySubscriptions(subscriptionOne, subscriptionTwo); 32 | verifySubscriptionEvents(subscription, ExpectedNumberOfEventsForOneSymbol); 33 | 34 | client.VerifyAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaDataStreamingClientTest.Statuses.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed partial class AlpacaDataStreamingClientTest 4 | { 5 | [Fact] 6 | public void GetStatusSubscriptionWorks() 7 | { 8 | var client = createMockClient( 9 | client => client.GetStatusSubscription(It.IsAny())); 10 | 11 | var subscriptionOne = client.Object.GetStatusSubscription(_symbols); 12 | var subscriptionTwo = client.Object.GetStatusSubscription(Stock, Other); 13 | 14 | verifySubscriptions(subscriptionOne, subscriptionTwo); 15 | verifySubscriptionEvents(subscriptionOne, ExpectedNumberOfEventsForAllSymbols); 16 | 17 | client.VerifyAll(); 18 | } 19 | 20 | [Fact] 21 | public async Task SubscribeStatusAsyncWorks() 22 | { 23 | var client = createMockClient( 24 | client => client.GetStatusSubscription(It.IsAny())); 25 | 26 | await using var subscription = await client.Object.SubscribeStatusAsync(Stock); 27 | await using var subscriptionOne = await client.Object.SubscribeStatusAsync(_symbols); 28 | // ReSharper disable once UseAwaitUsing 29 | using var subscriptionTwo = await client.Object.SubscribeStatusAsync(Stock, Other); 30 | 31 | verifySubscriptions(subscriptionOne, subscriptionTwo); 32 | verifySubscriptionEvents(subscription, ExpectedNumberOfEventsForOneSymbol); 33 | 34 | client.VerifyAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaDataStreamingClientTest.Trades.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed partial class AlpacaDataStreamingClientTest 4 | { 5 | [Fact] 6 | public void GetTradesSubscriptionWorks() 7 | { 8 | var client = createMockClient( 9 | client => client.GetTradeSubscription(It.IsAny())); 10 | 11 | var subscriptionOne = client.Object.GetTradeSubscription(_symbols); 12 | var subscriptionTwo = client.Object.GetTradeSubscription(Stock, Other); 13 | 14 | verifySubscriptions(subscriptionOne, subscriptionTwo); 15 | verifySubscriptionEvents(subscriptionOne, ExpectedNumberOfEventsForAllSymbols); 16 | 17 | client.VerifyAll(); 18 | } 19 | 20 | [Fact] 21 | public async Task SubscribeTradeAsyncWorks() 22 | { 23 | var client = createMockClient( 24 | client => client.GetTradeSubscription(It.IsAny())); 25 | 26 | await using var subscription = await client.Object.SubscribeTradeAsync(Stock); 27 | await using var subscriptionOne = await client.Object.SubscribeTradeAsync(_symbols); 28 | // ReSharper disable once UseAwaitUsing 29 | using var subscriptionTwo = await client.Object.SubscribeTradeAsync(Stock, Other); 30 | 31 | verifySubscriptions(subscriptionOne, subscriptionTwo); 32 | verifySubscriptionEvents(subscription, ExpectedNumberOfEventsForOneSymbol); 33 | 34 | client.VerifyAll(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/AlpacaValueTaskTest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed class AlpacaValueTaskTest 4 | { 5 | [Fact] 6 | public void DefaultValueWorks() 7 | { 8 | var valueTask = new AlpacaValueTask(); 9 | 10 | Assert.True(valueTask.GetAwaiter().IsCompleted); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/EnvironmentTest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed class EnvironmentTest 4 | { 5 | [Fact] 6 | public void WithProxyForAlpacaDataStreamingClientWorks() 7 | { 8 | var paper = Environments.Paper; 9 | var proxy = paper.WithProxyForAlpacaDataStreamingClient(); 10 | 11 | Assert.Equal(paper.AlpacaDataApi, proxy.AlpacaDataApi); 12 | Assert.Equal(paper.AlpacaTradingApi, proxy.AlpacaTradingApi); 13 | Assert.Equal(paper.AlpacaStreamingApi, proxy.AlpacaStreamingApi); 14 | Assert.Equal(paper.AlpacaNewsStreamingApi, proxy.AlpacaNewsStreamingApi); 15 | Assert.Equal(paper.AlpacaCryptoStreamingApi, proxy.AlpacaCryptoStreamingApi); 16 | 17 | Assert.NotEqual(paper.AlpacaDataStreamingApi, proxy.AlpacaDataStreamingApi); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Newtonsoft.Json.Linq; 2 | global using Xunit; 3 | global using Moq; 4 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/MockClient.cs: -------------------------------------------------------------------------------- 1 | using RichardSzalay.MockHttp; 2 | 3 | namespace Alpaca.Markets.Extensions.Tests; 4 | 5 | public sealed class MockClient : IDisposable 6 | where TClientConfiguration : AlpacaClientConfigurationBase 7 | where TClient : class, IDisposable 8 | { 9 | private readonly MockHttpMessageHandler _handler = new(); 10 | 11 | public MockClient( 12 | TClientConfiguration configuration, 13 | Func factory) 14 | { 15 | if (configuration is null) 16 | { 17 | throw new ArgumentNullException(nameof(configuration)); 18 | } 19 | 20 | configuration.HttpClient = _handler.ToHttpClient(); 21 | Client = factory(configuration); 22 | } 23 | 24 | public TClient Client { get; } 25 | 26 | public void AddGet( 27 | String request, 28 | JToken response) => 29 | addExpectRespond(HttpMethod.Get, request, response); 30 | 31 | public void Dispose() 32 | { 33 | _handler.VerifyNoOutstandingExpectation(); 34 | _handler.Dispose(); 35 | 36 | Client.Dispose(); 37 | } 38 | 39 | private void addExpectRespond( 40 | HttpMethod method, 41 | String request, 42 | JToken response) => 43 | _handler.Expect(method, request) 44 | .Respond("application/json", response.ToString()); 45 | } 46 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions.Tests/StreamingDataClientTest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions.Tests; 2 | 3 | public sealed class StreamingDataClientTest 4 | { 5 | [Fact] 6 | public async Task SubscribeAsyncWorks() 7 | { 8 | var cts = new CancellationTokenSource(); 9 | var client = new Mock(); 10 | 11 | client.Setup(dataClient => dataClient.SubscribeAsync( 12 | It.IsAny>(), 13 | It.Is(token => token.Equals(cts.Token)))) 14 | .Returns(ValueTask.CompletedTask); 15 | 16 | await client.Object.SubscribeAsync(createSubscription(), createSubscription()) 17 | .WithCancellation(cts.Token); 18 | 19 | client.VerifyAll(); 20 | } 21 | 22 | [Fact] 23 | public async Task UnsubscribeAsyncWorks() 24 | { 25 | var cts = new CancellationTokenSource(); 26 | var client = new Mock(); 27 | 28 | client.Setup(dataClient => dataClient.UnsubscribeAsync( 29 | It.IsAny>(), 30 | It.Is(token => token.Equals(cts.Token)))) 31 | .Returns(ValueTask.CompletedTask); 32 | 33 | await client.Object.UnsubscribeAsync(createSubscription(), createSubscription()) 34 | .WithCancellation(cts.Token); 35 | 36 | client.VerifyAll(); 37 | } 38 | 39 | private static IAlpacaDataSubscription createSubscription() => 40 | new Mock().Object; 41 | } 42 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage attributes that are applied to this project. 2 | 3 | #if NETFRAMEWORK 4 | global using System.Net.Http; 5 | #endif 6 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions/PublicAPI.Unshipped.txt: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | -------------------------------------------------------------------------------- /Alpaca.Markets.Extensions/Subscriptions/IDisposableAlpacaDataSubscription.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Extensions; 2 | 3 | /// 4 | /// Extends the interface with disposing support 5 | /// so caller can use instance of this interface in using and await using statements. 6 | /// 7 | /// 8 | public interface IDisposableAlpacaDataSubscription 9 | : IAlpacaDataSubscription, IAsyncDisposable, IDisposable; 10 | -------------------------------------------------------------------------------- /Alpaca.Markets.Tests/AlpacaCryptoDataClientTest.Other.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Tests; 2 | 3 | public sealed partial class AlpacaCryptoDataClientTest 4 | { 5 | [Fact] 6 | public async Task GetTopMarketMoversAsyncWorks() 7 | { 8 | const Int32 numberOfLosersAndGainers = 5; 9 | 10 | using var mock = mockClientsFactory.GetAlpacaCryptoDataClientMock(); 11 | 12 | mock.AddGet("/v1beta1/screener/crypto/movers", new JObject( 13 | new JProperty("gainers", new JArray(Enumerable.Repeat( 14 | Crypto.CreateStockMover(), numberOfLosersAndGainers))), 15 | new JProperty("losers", new JArray(Enumerable.Repeat( 16 | Crypto.CreateStockMover(), numberOfLosersAndGainers))))); 17 | 18 | var movers = await mock.Client.GetTopMarketMoversAsync(numberOfLosersAndGainers); 19 | 20 | Assert.NotNull(movers); 21 | Assert.Equal(numberOfLosersAndGainers, movers.Losers.Count); 22 | Assert.Equal(numberOfLosersAndGainers, movers.Gainers.Count); 23 | 24 | movers.Gainers.Validate(Crypto); 25 | movers.Losers.Validate(Crypto); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Alpaca.Markets.Tests/AlpacaCryptoDataClientTest.Snapshot.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Tests; 2 | 3 | public sealed partial class AlpacaCryptoDataClientTest 4 | { 5 | [Fact] 6 | public async Task ListSnapshotsAsyncWorks() 7 | { 8 | using var mock = mockClientsFactory.GetAlpacaCryptoDataClientMock(); 9 | 10 | mock.AddCryptoSnapshotsExpectation(PathPrefix, _symbols); 11 | 12 | var snapshots = await mock.Client.ListSnapshotsAsync( 13 | new SnapshotDataListRequest(_symbols)); 14 | 15 | Assert.NotNull(snapshots); 16 | Assert.NotEmpty(snapshots); 17 | 18 | Assert.True(snapshots[Crypto].Validate(Crypto)); 19 | Assert.True(snapshots[Other].Validate(Other)); 20 | } 21 | 22 | [Fact] 23 | public async Task ListLatestOrderBooksAsyncWorks() 24 | { 25 | using var mock = mockClientsFactory.GetAlpacaCryptoDataClientMock(); 26 | 27 | mock.AddOrderBooksExpectation(PathPrefix, _symbols); 28 | 29 | #pragma warning disable CS0618 30 | var orderBooks = await mock.Client.ListLatestOrderBooksAsync( 31 | new LatestOrderBooksRequest(_symbols, _exchangesList)); 32 | #pragma warning restore CS0618 33 | 34 | Assert.NotNull(orderBooks); 35 | Assert.NotEmpty(orderBooks); 36 | 37 | Assert.True(HistoricalDataHelpers.Validate(orderBooks[Crypto], Crypto)); 38 | Assert.True(HistoricalDataHelpers.Validate(orderBooks[Other], Other)); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Alpaca.Markets.Tests/AlpacaDataClientTest.Snapshot.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Tests; 2 | 3 | public sealed partial class AlpacaDataClientTest 4 | { 5 | [Fact] 6 | public async Task GetSnapshotAsyncWorks() 7 | { 8 | using var mock = mockClientsFactory.GetAlpacaDataClientMock(); 9 | 10 | mock.AddSnapshotExpectation(PathPrefix, Stock); 11 | 12 | var snapshot = await mock.Client.GetSnapshotAsync(new LatestMarketDataRequest(Stock) 13 | { 14 | Feed = MarketDataFeed.Otc, 15 | Currency = Currency 16 | }); 17 | 18 | Assert.True(snapshot.Validate(Stock)); 19 | } 20 | 21 | [Fact] 22 | public async Task ListSnapshotsAsyncWorks() 23 | { 24 | using var mock = mockClientsFactory.GetAlpacaDataClientMock(); 25 | 26 | mock.AddSnapshotsExpectation(PathPrefix, _symbols); 27 | 28 | var snapshots = await mock.Client 29 | .ListSnapshotsAsync(new LatestMarketDataListRequest(_symbols) 30 | { 31 | Feed = MarketDataFeed.DelayedSip, 32 | Currency = Currency 33 | }); 34 | 35 | Assert.NotNull(snapshots); 36 | Assert.NotEmpty(snapshots); 37 | 38 | Assert.True(snapshots[Stock].Validate(Stock)); 39 | Assert.True(snapshots[Other].Validate(Other)); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Alpaca.Markets.Tests/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using RichardSzalay.MockHttp; 2 | global using Newtonsoft.Json.Linq; 3 | global using Newtonsoft.Json; 4 | global using System.Net; 5 | global using Xunit; 6 | global using Moq; 7 | -------------------------------------------------------------------------------- /Alpaca.Markets.Tests/IMock.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Tests; 2 | 3 | internal interface IMock 4 | { 5 | void AddGet( 6 | String request, 7 | JToken response); 8 | } 9 | -------------------------------------------------------------------------------- /Alpaca.Markets.Tests/IntervalTest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets.Tests; 2 | 3 | public sealed class IntervalTest 4 | { 5 | [Fact] 6 | public void IntervalConversionsWorks() 7 | { 8 | var dateOnlyInterval = DateOnly.FromDateTime(DateTime.Today).GetIntervalFromThat(); 9 | Assert.NotNull(dateOnlyInterval.From); 10 | Assert.Null(dateOnlyInterval.Into); 11 | 12 | var dateTimeInterval = dateOnlyInterval.AsTimeInterval(); 13 | Assert.NotNull(dateTimeInterval.From); 14 | Assert.Null(dateTimeInterval.Into); 15 | 16 | Assert.Equal(dateOnlyInterval.From!.Value.ToDateTime(TimeOnly.MinValue), dateTimeInterval.From!.Value); 17 | Assert.Equal(dateOnlyInterval, dateTimeInterval.AsDateInterval()); 18 | 19 | dateOnlyInterval = dateOnlyInterval.From.Value.GetIntervalTillThat(); 20 | Assert.NotEqual(dateOnlyInterval, dateTimeInterval.AsDateInterval()); 21 | } 22 | 23 | [Fact] 24 | public void InvalidIntervalValidationWorks() => 25 | Assert.Throws(() => 26 | new Interval().WithFrom(DateTime.MaxValue).WithInto(DateTime.MinValue)); 27 | } 28 | -------------------------------------------------------------------------------- /Alpaca.Markets.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpacahq/alpaca-trade-api-csharp/7697596c24bc112180b00c8c7ab64be537fd2c88/Alpaca.Markets.snk -------------------------------------------------------------------------------- /Alpaca.Markets/AlpacaCryptoStreamingClient.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class AlpacaCryptoStreamingClient : 4 | DataStreamingClientBase, 5 | IAlpacaCryptoStreamingClient 6 | { 7 | internal AlpacaCryptoStreamingClient( 8 | AlpacaCryptoStreamingClientConfiguration configuration) 9 | : base(configuration.EnsureNotNull()) 10 | { 11 | } 12 | 13 | public IAlpacaDataSubscription GetQuoteSubscription() => 14 | GetSubscription(QuotesChannel, WildcardSymbolString); 15 | 16 | public IAlpacaDataSubscription GetQuoteSubscription( 17 | String symbol) => 18 | GetSubscription(QuotesChannel, symbol.EnsureNotNull()); 19 | 20 | public IAlpacaDataSubscription GetOrderBookSubscription( 21 | String symbol) => 22 | GetSubscription(OrderBooksChannel, symbol.EnsureNotNull()); 23 | } 24 | -------------------------------------------------------------------------------- /Alpaca.Markets/AlpacaNewsStreamingClient.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class AlpacaNewsStreamingClient : 4 | DataStreamingClientBase, 5 | IAlpacaNewsStreamingClient 6 | { 7 | internal AlpacaNewsStreamingClient( 8 | AlpacaNewsStreamingClientConfiguration configuration) 9 | : base(configuration.EnsureNotNull()) 10 | { 11 | } 12 | 13 | public IAlpacaDataSubscription GetNewsSubscription() => 14 | GetSubscription(NewsChannel, WildcardSymbolString); 15 | 16 | public IAlpacaDataSubscription GetNewsSubscription( 17 | String symbol) => 18 | GetSubscription(NewsChannel, symbol.EnsureNotNull()); 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/AlpacaTradingClient.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed partial class AlpacaTradingClient : IAlpacaTradingClient 4 | { 5 | private readonly RateLimitHandler _rateLimitHandler = new(); 6 | 7 | private readonly HttpClient _httpClient; 8 | 9 | internal AlpacaTradingClient( 10 | AlpacaTradingClientConfiguration configuration) => 11 | _httpClient = configuration.EnsureNotNull().GetConfiguredHttpClient(); 12 | 13 | public IRateLimitValues GetRateLimitValues() => _rateLimitHandler.GetCurrent(); 14 | 15 | public void Dispose() 16 | { 17 | _httpClient.Dispose(); 18 | _rateLimitHandler.Dispose(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Alpaca.Markets/Authentication/BasicKey.cs: -------------------------------------------------------------------------------- 1 | using System.Text; 2 | using System.Net; 3 | 4 | namespace Alpaca.Markets; 5 | 6 | /// 7 | /// Basie key for Alpaca Broker API authentication. 8 | /// 9 | [UsedImplicitly] 10 | public sealed class BasicKey : SecurityKey 11 | { 12 | /// 13 | /// Creates new instance of object. 14 | /// 15 | /// User credentials (name and password). 16 | /// 17 | /// The argument is null. 18 | /// 19 | public BasicKey( 20 | NetworkCredential credential) 21 | : base(Convert.ToBase64String(Encoding.ASCII.GetBytes( 22 | $"{credential.EnsureNotNull().UserName}:{credential.Password}"))) 23 | { 24 | } 25 | 26 | internal override IEnumerable> GetAuthenticationHeaders() 27 | { 28 | yield return new KeyValuePair( 29 | "Authorization", "Basic " + Value); 30 | } 31 | 32 | internal override JsonAuthRequest.JsonData GetAuthenticationData() => 33 | throw new InvalidOperationException(); 34 | 35 | [ExcludeFromCodeCoverage] 36 | internal override JsonAuthentication GetAuthentication() => 37 | throw new InvalidOperationException(); 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Authentication/OAuthKey.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// OAuth key for Alpaca API authentication. 5 | /// 6 | [UsedImplicitly] 7 | public sealed class OAuthKey : SecurityKey 8 | { 9 | /// 10 | /// Creates new instance of object. 11 | /// 12 | /// OAuth key. 13 | /// 14 | /// The argument is null. 15 | /// 16 | public OAuthKey( 17 | String value) 18 | : base(value) 19 | { 20 | } 21 | 22 | internal override IEnumerable> GetAuthenticationHeaders() 23 | { 24 | yield return new KeyValuePair( 25 | "Authorization", "Bearer " + Value); 26 | } 27 | 28 | internal override JsonAuthRequest.JsonData GetAuthenticationData() => 29 | new() 30 | { 31 | OAuthToken = Value 32 | }; 33 | 34 | [ExcludeFromCodeCoverage] 35 | internal override JsonAuthentication GetAuthentication() => 36 | throw new InvalidOperationException(); 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Authentication/SecurityKey.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Base class for 'security key' abstraction. 5 | /// 6 | public abstract class SecurityKey 7 | { 8 | /// 9 | /// Creates new instance of object. 10 | /// 11 | /// Security key value. 12 | /// 13 | /// The argument is null. 14 | /// 15 | protected SecurityKey(String value) => Value = value.EnsureNotNull(); 16 | 17 | internal String Value { get; } 18 | 19 | internal abstract IEnumerable> GetAuthenticationHeaders(); 20 | 21 | internal abstract JsonAuthRequest.JsonData GetAuthenticationData(); 22 | 23 | internal abstract JsonAuthentication GetAuthentication(); 24 | } 25 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/Adjustment.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported bar corporate action adjustment types for Alpaca Data API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum Adjustment 8 | { 9 | /// 10 | /// Raw data - no adjustment. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "raw")] 14 | Nothing, 15 | 16 | /// 17 | /// Stock split adjustments. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "split")] 21 | SplitsOnly, 22 | 23 | /// 24 | /// Stock dividend adjustments. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "dividend")] 28 | DividendsOnly, 29 | 30 | /// 31 | /// Stock splits and dividend adjustments. 32 | /// 33 | [UsedImplicitly] 34 | [EnumMember(Value = "all")] 35 | SplitsAndDividends 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/AssetAttributes.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Unique asset characteristics for Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(AssetAttributesEnumConverter))] 7 | public enum AssetAttributes 8 | { 9 | /// 10 | /// Unknown asset attribute. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "-")] 14 | Unknown, 15 | 16 | /// 17 | /// PTP asset accepting orders without exception. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "ptp_no_exception")] 21 | PtpNoException, 22 | 23 | /// 24 | /// PTP asset accepting orders with exception. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "ptp_with_exception")] 28 | PtpWithException, 29 | 30 | /// 31 | /// IPO asset, only limit orders are allowed prior to an IPO being traded on secondary market 32 | /// 33 | [UsedImplicitly] 34 | [EnumMember(Value = "ipo")] 35 | Ipo, 36 | 37 | /// 38 | /// Asset supports options trading. 39 | /// 40 | [UsedImplicitly] 41 | [EnumMember(Value = "options_enabled")] 42 | OptionsEnabled, 43 | 44 | /// 45 | /// Asset supports fractional trading at extended hours. 46 | /// 47 | [UsedImplicitly] 48 | [EnumMember(Value = "fractional_eh_enabled")] 49 | FractionalAtExtended 50 | } 51 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/AssetClass.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported asset classes for Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum AssetClass 8 | { 9 | /// 10 | /// US equity asset class. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "us_equity")] 14 | UsEquity, 15 | 16 | /// 17 | /// Cryptocurrency asset class. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "crypto")] 21 | Crypto, 22 | 23 | /// 24 | /// US option asset class. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "us_option")] 28 | UsOption 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/AssetStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Single asset status in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum AssetStatus 8 | { 9 | /// 10 | /// Active asset. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "active")] 14 | Active, 15 | 16 | /// 17 | /// Inactive asset. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "inactive")] 21 | Inactive, 22 | 23 | /// 24 | /// Delisted asset. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "delisted")] 28 | Delisted 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/AuthStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Authorization status for Alpaca streaming API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | [SuppressMessage("ReSharper", "UnusedMember.Global")] 8 | public enum AuthStatus 9 | { 10 | /// 11 | /// Client successfully authorized. 12 | /// 13 | [EnumMember(Value = "authorized")] 14 | Authorized, 15 | 16 | /// 17 | /// Client is not authorized. 18 | /// 19 | [EnumMember(Value = "unauthorized")] 20 | Unauthorized, 21 | 22 | /// 23 | /// Connection limit exceeded. 24 | /// 25 | [EnumMember(Value = "exceeded")] 26 | TooManyConnections 27 | } 28 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/BarTimeFrameUnit.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported bar duration for Alpaca Data API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum BarTimeFrameUnit 8 | { 9 | /// 10 | /// Minute bars. 11 | /// 12 | [EnumMember(Value = "Min")] 13 | Minute, 14 | 15 | /// 16 | /// Hour bars. 17 | /// 18 | [EnumMember(Value = "Hour")] 19 | Hour, 20 | 21 | /// 22 | /// Daily bars. 23 | /// 24 | [EnumMember(Value = "Day")] 25 | Day, 26 | 27 | /// 28 | /// Weekly bars. 29 | /// 30 | [UsedImplicitly] 31 | [EnumMember(Value = "Week")] 32 | Week, 33 | 34 | /// 35 | /// Monthly bars. 36 | /// 37 | [UsedImplicitly] 38 | [EnumMember(Value = "Month")] 39 | Month 40 | } 41 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/CorporateActionDateType.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Corporate action type in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum CorporateActionDateType 8 | { 9 | /// 10 | /// Date the corporate action or subsequent terms update was announced. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "declaration_date")] 14 | DeclarationDate, 15 | 16 | /// 17 | /// The first date that purchasing a security will not 18 | /// result in a corporate action entitlement. 19 | /// 20 | [UsedImplicitly] 21 | [EnumMember(Value = "ex_date")] 22 | ExecutionDate, 23 | 24 | /// 25 | /// The date an account must hold a settled position in the security 26 | /// in order to receive the corporate action entitlement. 27 | /// 28 | [UsedImplicitly] 29 | [EnumMember(Value = "record_date")] 30 | RecordDate, 31 | 32 | /// 33 | /// The date the announcement will take effect. On this date, account 34 | /// stock and cash balances are expected to be processed accordingly. 35 | /// 36 | [UsedImplicitly] 37 | [EnumMember(Value = "payable_date")] 38 | PayableDate 39 | } 40 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/CorporateActionType.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Corporate action type in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum CorporateActionType 8 | { 9 | /// 10 | /// Dividends payment. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "dividend")] 14 | Dividend, 15 | 16 | /// 17 | /// Merge another symbol. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "merger")] 21 | Merger, 22 | 23 | /// 24 | /// Spin off another symbol. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "spinoff")] 28 | SpinOff, 29 | 30 | /// 31 | /// Split company shares. 32 | /// 33 | [UsedImplicitly] 34 | [EnumMember(Value = "split")] 35 | Split 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/CryptoExchange.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Crypto currency exchanges supported by Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(CryptoExchangeEnumConverter))] 7 | [SuppressMessage("ReSharper", "IdentifierTypo")] 8 | [SuppressMessage("ReSharper", "StringLiteralTypo")] 9 | public enum CryptoExchange 10 | { 11 | /// 12 | /// Unknown exchange (i.e. one not supported by this version of SDK). 13 | /// 14 | [UsedImplicitly] 15 | [EnumMember(Value = "UNKNOWN")] 16 | Unknown, 17 | 18 | /// 19 | /// ErisX Exchange. 20 | /// 21 | [UsedImplicitly] 22 | [EnumMember(Value = "ERSX")] 23 | Ersx, 24 | 25 | /// 26 | /// FTX US Exchange. 27 | /// 28 | [UsedImplicitly] 29 | [EnumMember(Value = "FTXU")] 30 | Ftx, 31 | 32 | /// 33 | /// Coinbase Exchange. 34 | /// 35 | [UsedImplicitly] 36 | [EnumMember(Value = "CBSE")] 37 | Cbse 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/DayTradeMarginCallProtection.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Day trade margin call protection mode for account. See more information here: 5 | /// https://docs.alpaca.markets/user-protections/#day-trade-margin-call-dtmc-protection-at-alpaca 6 | /// 7 | [JsonConverter(typeof(StringEnumConverter))] 8 | public enum DayTradeMarginCallProtection 9 | { 10 | /// 11 | /// Check rules on position entry. 12 | /// 13 | [UsedImplicitly] 14 | [EnumMember(Value = "entry")] 15 | Entry, 16 | 17 | /// 18 | /// Check rules on position exit. 19 | /// 20 | [UsedImplicitly] 21 | [EnumMember(Value = "exit")] 22 | Exit, 23 | 24 | /// 25 | /// Check rules on position entry and exit. 26 | /// 27 | [UsedImplicitly] 28 | [EnumMember(Value = "both")] 29 | Both 30 | } 31 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/HistoryPeriodUnit.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Period units for portfolio history in the Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum HistoryPeriodUnit 8 | { 9 | /// 10 | /// Day 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "D")] 14 | Day, 15 | 16 | /// 17 | /// Week 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "W")] 21 | Week, 22 | 23 | /// 24 | /// Month 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "M")] 28 | Month, 29 | 30 | /// 31 | /// Year 32 | /// 33 | [UsedImplicitly] 34 | [EnumMember(Value = "A")] 35 | Year 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/IntradayProfitLoss.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Intraday profit/loss calculation for portfolio history in the Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum IntradayProfitLoss 8 | { 9 | /// 10 | /// Don't reset the profit/los value to the previous day's closing equity for each trading day. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "no_reset")] 14 | NoReset, 15 | 16 | /// 17 | /// Reset the profit/los value to the previous day's closing equity for each trading day. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "per_day")] 21 | PerDay 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/IntradayReporting.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Intraday reporting styles for portfolio history in the Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum IntradayReporting 8 | { 9 | /// 10 | /// Only timestamps for the core equity trading hours are returned (usually 9:30am to 4:00pm, trading days only). 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "market_hours")] 14 | MarketHours, 15 | 16 | /// 17 | /// Returns timestamps for the whole session including extended hours (usually 4:00am to 8:00pm, trading days only). 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "extended_hours")] 21 | ExtendedHours, 22 | 23 | /// 24 | /// Returns price data points 24/7 (for off-session times too). To calculate the equity values we are using the following prices: 25 | /// - Between 4:00am and 10:00pm on trading days the valuation will be calculated based on the last trade (extended hours and normal hours respectively). 26 | /// - After 10:00pm, until the next session open the equities will be valued at their official closing price on the primary exchange. 27 | /// 28 | [UsedImplicitly] 29 | [EnumMember(Value = "continuous")] 30 | Continuous 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/JsonAction.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [JsonConverter(typeof(StringEnumConverter))] 4 | internal enum JsonAction 5 | { 6 | [EnumMember(Value = "authenticate")] 7 | Authenticate, 8 | 9 | [EnumMember(Value = "listen")] 10 | Listen, 11 | 12 | [UsedImplicitly] 13 | [EnumMember(Value = "unlisten")] 14 | Unlisten, 15 | 16 | [EnumMember(Value = "auth")] 17 | StreamingAuthenticate, 18 | 19 | [EnumMember(Value = "subscribe")] 20 | Subscribe, 21 | 22 | [EnumMember(Value = "unsubscribe")] 23 | Unsubscribe 24 | } 25 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/MarketDataFeed.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported market feed data types for Alpaca Data API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum MarketDataFeed 8 | { 9 | /// 10 | /// IEX feed - the only option available for the free data (no subscription). 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "iex")] 14 | Iex, 15 | 16 | /// 17 | /// SIP feed - option available for the subscribed clients. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "sip")] 21 | Sip, 22 | 23 | /// 24 | /// OTC feed - option available for the subscribed clients. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "otc")] 28 | Otc, 29 | 30 | /// 31 | /// DelayedSIP feed - 15-minute delayed . It can only be used 32 | /// in the latest endpoints and on the stream. For historical endpoints you can 33 | /// simply use and set the end parameter to 15 minutes ago. 34 | /// 35 | [UsedImplicitly] 36 | [EnumMember(Value = "delayed_sip")] 37 | DelayedSip 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/Multiplier.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Account multiplier value (enum values can be cast to related integer values). 5 | /// 6 | [Flags] 7 | [SuppressMessage("Naming", "CA1720:Identifier contains type name", 8 | Justification = "We use these names because they explain situation better.")] 9 | public enum Multiplier 10 | { 11 | /// 12 | /// Invalid default value of enum. 13 | /// 14 | [UsedImplicitly] 15 | None = 0, 16 | 17 | /// 18 | /// Standard limited margin account with 1x buying power. 19 | /// 20 | [UsedImplicitly] 21 | Single = 1, 22 | 23 | /// 24 | /// Regular T margin account with 2x intraday and overnight buying power; 25 | /// this is the default for all non-PDT accounts with $2,000 or more equity. 26 | /// 27 | [UsedImplicitly] 28 | Double = 2, 29 | 30 | /// 31 | /// PDT account with 4x intraday buying power and 2x reg T overnight buying power. 32 | /// 33 | [UsedImplicitly] 34 | Quadruple = 4 35 | } 36 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OptionStyle.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported option contract styles for Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum OptionStyle 8 | { 9 | /// 10 | /// American option contract execution style. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "american")] 14 | American, 15 | 16 | /// 17 | /// European option contract execution style. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "european")] 21 | European 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OptionType.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported option contract types for Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum OptionType 8 | { 9 | /// 10 | /// Call option contract. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "call")] 14 | Call, 15 | 16 | /// 17 | /// Put option contract. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "put")] 21 | Put 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OptionsFeed.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported options feed for Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum OptionsFeed 8 | { 9 | /// 10 | /// Options Price Reporting Authority. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "opra")] 14 | Opra, 15 | 16 | /// 17 | /// Indicative options data. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "indicative")] 21 | Indicative 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OptionsTradingLevel.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Options trading level for Alpaca REST API. 5 | /// 6 | public enum OptionsTradingLevel 7 | { 8 | /// 9 | /// US options trading completely disabled. 10 | /// 11 | [UsedImplicitly] 12 | Disabled = 0, 13 | 14 | /// 15 | /// Us options trading with covered call / cash-secured put. 16 | /// 17 | [UsedImplicitly] 18 | CoveredCallCashSecuredPut, 19 | 20 | /// 21 | /// US options trading with long call and put support. 22 | /// 23 | [UsedImplicitly] 24 | LongCallPut 25 | } 26 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OrderClass.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Order class for advanced orders in the Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | [SuppressMessage("ReSharper", "StringLiteralTypo")] 8 | public enum OrderClass 9 | { 10 | /// 11 | /// Simple order 12 | /// 13 | [UsedImplicitly] 14 | [EnumMember(Value = "simple")] 15 | Simple, 16 | 17 | /// 18 | /// Bracket order 19 | /// 20 | [EnumMember(Value = "bracket")] 21 | Bracket, 22 | 23 | /// 24 | /// One Cancels Other order 25 | /// 26 | [EnumMember(Value = "oco")] 27 | OneCancelsOther, 28 | 29 | /// 30 | /// One Triggers Other order 31 | /// 32 | [EnumMember(Value = "oto")] 33 | OneTriggersOther, 34 | 35 | /// 36 | /// Multi-leg options order 37 | /// 38 | [EnumMember(Value = "mleg")] 39 | MultiLegOptions 40 | } 41 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OrderSide.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Order side in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(OrderSideEnumConverter))] 7 | public enum OrderSide 8 | { 9 | /// 10 | /// Buy order. 11 | /// 12 | [EnumMember(Value = "buy")] 13 | Buy, 14 | 15 | /// 16 | /// Sell order. 17 | /// 18 | [EnumMember(Value = "sell")] 19 | Sell 20 | } 21 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OrderStatusFilter.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Order statuses filter for call from Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum OrderStatusFilter 8 | { 9 | /// 10 | /// Returns only open orders. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "open")] 14 | Open, 15 | 16 | /// 17 | /// Returns only closed orders. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "closed")] 21 | Closed, 22 | 23 | /// 24 | /// Returns all orders. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "all")] 28 | All 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/OrderType.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported order types in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum OrderType 8 | { 9 | /// 10 | /// Market order (no prices required). 11 | /// 12 | [EnumMember(Value = "market")] 13 | Market, 14 | 15 | /// 16 | /// Stop order (stop price required). 17 | /// 18 | [EnumMember(Value = "stop")] 19 | Stop, 20 | 21 | /// 22 | /// Limit order (limit price required). 23 | /// 24 | [EnumMember(Value = "limit")] 25 | Limit, 26 | 27 | /// 28 | /// Stop limit order (both stop and limit prices required). 29 | /// 30 | [EnumMember(Value = "stop_limit")] 31 | StopLimit, 32 | 33 | /// 34 | /// Trailing stop order (dollars or percent offset required). 35 | /// 36 | [EnumMember(Value = "trailing_stop")] 37 | TrailingStop 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/PositionIntent.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Position intent for order placement in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum PositionIntent 8 | { 9 | /// 10 | /// Buy to open a long position. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "buy_to_open")] 14 | BuyToOpen, 15 | 16 | /// 17 | /// Buy to close a short position. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "buy_to_close")] 21 | BuyToClose, 22 | 23 | /// 24 | /// Sell to open a short position. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "sell_to_open")] 28 | SellToOpen, 29 | 30 | /// 31 | /// Sell to close a long position. 32 | /// 33 | [UsedImplicitly] 34 | [EnumMember(Value = "sell_to_close")] 35 | SellToClose 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/PositionSide.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Position side in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | [SuppressMessage( 8 | "Naming", "CA1720:Identifier contains type name", 9 | Justification = "Both names are trading terms not CLR type names.")] 10 | public enum PositionSide 11 | { 12 | /// 13 | /// Long position. 14 | /// 15 | [UsedImplicitly] 16 | [EnumMember(Value = "long")] 17 | Long, 18 | 19 | /// 20 | /// Short position. 21 | /// 22 | [UsedImplicitly] 23 | [EnumMember(Value = "short")] 24 | Short 25 | } 26 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/SortDirection.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported sort directions in Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum SortDirection 8 | { 9 | /// 10 | /// Descending sort order 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "desc")] 14 | Descending, 15 | 16 | /// 17 | /// Ascending sort order 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "asc")] 21 | Ascending 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/TakerSide.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Possible crypto taker side types for Alpaca Crypto Data API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum TakerSide 8 | { 9 | /// 10 | /// Unspecified crypto trade take side. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "-")] 14 | Unknown, 15 | 16 | /// 17 | /// Buy crypto trade take side. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "B")] 21 | Buy, 22 | 23 | /// 24 | /// Sell crypto trade take side. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "S")] 28 | Sell 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/Tape.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported tape types for Alpaca Data API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum Tape 8 | { 9 | /// 10 | /// Tape A - NYSE. 11 | /// 12 | [UsedImplicitly] 13 | A, 14 | 15 | /// 16 | /// Tape B - NYSE Arca and NYSE Amex. 17 | /// 18 | [UsedImplicitly] 19 | B, 20 | 21 | /// 22 | /// Tape C - NASDAQ. 23 | /// 24 | [UsedImplicitly] 25 | C 26 | } 27 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/TimeFrame.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Supported bar duration for Alpaca REST API. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum TimeFrame 8 | { 9 | /// 10 | /// One minute bars. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "1Min")] 14 | Minute, 15 | 16 | /// 17 | /// Five minutes bars. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "5Min")] 21 | FiveMinutes, 22 | 23 | /// 24 | /// Fifteen minutes bars. 25 | /// 26 | [UsedImplicitly] 27 | [EnumMember(Value = "15Min")] 28 | FifteenMinutes, 29 | 30 | /// 31 | /// Daily bars. 32 | /// 33 | [UsedImplicitly] 34 | [EnumMember(Value = "1D")] 35 | Day 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Enums/TradeConfirmEmail.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Notification level for order fill emails. 5 | /// 6 | [JsonConverter(typeof(StringEnumConverter))] 7 | public enum TradeConfirmEmail 8 | { 9 | /// 10 | /// Never send email notification for order fills. 11 | /// 12 | [UsedImplicitly] 13 | [EnumMember(Value = "none")] 14 | None, 15 | 16 | /// 17 | /// Send email notification for all order fills. 18 | /// 19 | [UsedImplicitly] 20 | [EnumMember(Value = "all")] 21 | All 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Environment/Environments.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Provides single entry point for obtaining information about different environments. 5 | /// 6 | public static class Environments 7 | { 8 | /// 9 | /// Gets live trading environment. 10 | /// 11 | public static IEnvironment Live { get; } = new LiveEnvironment(); 12 | 13 | /// 14 | /// Gets paper trading environment. Paper trading is a simulation environment that does not use real money. 15 | /// See Alpaca Paper Trading Documentation for more information. 16 | /// 17 | [UsedImplicitly] 18 | public static IEnvironment Paper { get; } = new PaperEnvironment(); 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Environment/IEnvironment.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Provides URLs for different APIs available for this SDK on specific environment. 5 | /// 6 | public interface IEnvironment 7 | { 8 | /// 9 | /// Gets Alpaca trading REST API base URL for this environment. 10 | /// 11 | Uri AlpacaTradingApi { get; } 12 | 13 | /// 14 | /// Gets Alpaca data REST API base URL for this environment. 15 | /// 16 | Uri AlpacaDataApi { get; } 17 | 18 | /// 19 | /// Gets Alpaca streaming API base URL for this environment. 20 | /// 21 | Uri AlpacaStreamingApi { get; } 22 | 23 | /// 24 | /// Gets Alpaca data streaming API base URL for this environment. 25 | /// 26 | Uri AlpacaDataStreamingApi { get; } 27 | 28 | /// 29 | /// Gets Alpaca crypto streaming API base URL for this environment. 30 | /// 31 | Uri AlpacaCryptoStreamingApi { get; } 32 | 33 | /// 34 | /// Gets Alpaca news streaming API base URL for this environment. 35 | /// 36 | Uri AlpacaNewsStreamingApi { get; } 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Environment/LiveEnvironment.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class LiveEnvironment : IEnvironment 4 | { 5 | public Uri AlpacaTradingApi => new("https://api.alpaca.markets"); 6 | 7 | public Uri AlpacaDataApi => new("https://data.alpaca.markets"); 8 | 9 | public Uri AlpacaStreamingApi => new("wss://api.alpaca.markets/stream"); 10 | 11 | public Uri AlpacaDataStreamingApi => new("wss://stream.data.alpaca.markets/v2/sip"); 12 | 13 | public Uri AlpacaCryptoStreamingApi => new("wss://stream.data.alpaca.markets/v1beta3/crypto/us"); 14 | 15 | public Uri AlpacaNewsStreamingApi => new("wss://stream.data.alpaca.markets/v1beta1/news"); 16 | } 17 | -------------------------------------------------------------------------------- /Alpaca.Markets/Environment/PaperEnvironment.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class PaperEnvironment : IEnvironment 4 | { 5 | public Uri AlpacaTradingApi => new("https://paper-api.alpaca.markets"); 6 | 7 | public Uri AlpacaDataApi => Environments.Live.AlpacaDataApi; 8 | 9 | public Uri AlpacaStreamingApi => new("wss://paper-api.alpaca.markets/stream"); 10 | 11 | public Uri AlpacaDataStreamingApi => new("wss://stream.data.alpaca.markets/v2/iex"); 12 | 13 | public Uri AlpacaCryptoStreamingApi => Environments.Live.AlpacaCryptoStreamingApi; 14 | 15 | public Uri AlpacaNewsStreamingApi => Environments.Live.AlpacaNewsStreamingApi; 16 | } 17 | -------------------------------------------------------------------------------- /Alpaca.Markets/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage attributes that are applied to this project. 2 | 3 | global using System.Runtime.Serialization; 4 | global using Newtonsoft.Json.Converters; 5 | global using System.Diagnostics; 6 | global using Newtonsoft.Json; 7 | 8 | #if NETFRAMEWORK 9 | global using System.Net.Http; 10 | #endif 11 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/AccountActivityTypeEnumConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class AccountActivityTypeEnumConverter : StringEnumConverter 7 | { 8 | public override Object ReadJson( 9 | JsonReader reader, 10 | Type objectType, 11 | Object? existingValue, 12 | JsonSerializer serializer) => 13 | AccountActivityType.Unknown.FromEnumString(reader); 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/ActionExtensions.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | internal static class ActionExtensions 6 | { 7 | public static void DeserializeAndInvoke( 8 | this Action? eventHandler, 9 | JToken eventArg) 10 | where TJson : class, TApi => 11 | eventHandler?.Invoke(eventArg.ToObject() ?? throw new RestClientErrorException( 12 | "Unable to deserialize JSON response message.")); 13 | } 14 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/ActiveStocksExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class ActiveStocksExtensions 4 | { 5 | public static async Task> ListMostActiveStocksAsync( 6 | this HttpClient httpClient, 7 | RateLimitHandler rateLimitHandler, 8 | String orderByFieldForRankingMostActive, 9 | Int32? numberOfTopMostActiveStocks = null, 10 | CancellationToken cancellationToken = default) => 11 | (await httpClient.GetAsync( 12 | await getUriBuilderAsync(httpClient, orderByFieldForRankingMostActive, numberOfTopMostActiveStocks).ConfigureAwait(false), 13 | rateLimitHandler, cancellationToken).ConfigureAwait(false)) 14 | .MostActives.EmptyIfNull(); 15 | 16 | private static async ValueTask getUriBuilderAsync( 17 | HttpClient httpClient, 18 | String orderByField, 19 | Int32? top = null) => 20 | new UriBuilder(httpClient.BaseAddress!) 21 | { 22 | Query = await new QueryBuilder() 23 | .AddParameter("by", orderByField) 24 | .AddParameter("top", top) 25 | .AsStringAsync().ConfigureAwait(false) 26 | }.WithPath("v1beta1/screener/stocks/most-actives"); 27 | } 28 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/AlpacaScreenerClientExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class AlpacaScreenerClientExtensions 4 | { 5 | public static async Task GetTopMarketMoversAsync( 6 | this HttpClient httpClient, 7 | RateLimitHandler rateLimitHandler, 8 | String marketType, 9 | Int32? numberOfLosersAndGainersInResponse = null, 10 | CancellationToken cancellationToken = default) => 11 | await httpClient.GetAsync( 12 | await getUriBuilderAsync(httpClient, marketType, numberOfLosersAndGainersInResponse).ConfigureAwait(false), 13 | rateLimitHandler, cancellationToken).ConfigureAwait(false); 14 | 15 | private static async ValueTask getUriBuilderAsync( 16 | HttpClient httpClient, 17 | String marketType, 18 | Int32? top = null) => 19 | new UriBuilder(httpClient.BaseAddress!) 20 | { 21 | Query = await new QueryBuilder() 22 | .AddParameter("top", top) 23 | .AsStringAsync().ConfigureAwait(false) 24 | }.WithPath($"v1beta1/screener/{marketType}/movers"); 25 | } 26 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/AssetAttributesEnumConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class AssetAttributesEnumConverter : StringEnumConverter 7 | { 8 | public override Object ReadJson( 9 | JsonReader reader, 10 | Type objectType, 11 | Object? existingValue, 12 | JsonSerializer serializer) => 13 | AssetAttributes.Unknown.FromEnumString(reader); 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/AssumeUtcIsoDateTimeConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | [SuppressMessage( 6 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 7 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 8 | internal sealed class AssumeUtcIsoDateTimeConverter : DateTimeConverterBase 9 | { 10 | public override void WriteJson( 11 | JsonWriter writer, 12 | Object? value, 13 | JsonSerializer serializer) 14 | { 15 | if (value is DateTime dateTimeValue) 16 | { 17 | writer.WriteValue(dateTimeValue.ToString("O")); 18 | } 19 | } 20 | 21 | public override Object? ReadJson( 22 | JsonReader reader, 23 | Type objectType, 24 | Object? existingValue, 25 | JsonSerializer serializer) => 26 | DateTimeOffset.TryParse(reader.Value?.ToString(), 27 | CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal, 28 | out var dateTimeOffset) 29 | ? dateTimeOffset.UtcDateTime 30 | : null; 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/CryptoExchangeEnumConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class CryptoExchangeEnumConverter : StringEnumConverter 7 | { 8 | public override Object ReadJson( 9 | JsonReader reader, 10 | Type objectType, 11 | Object? existingValue, 12 | JsonSerializer serializer) => 13 | CryptoExchange.Unknown.FromEnumString(reader); 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/CustomTimeZone.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class CustomTimeZone 4 | { 5 | private const String WindowsTimeZoneId = "Eastern Standard Time"; 6 | 7 | private const String IanaTimeZoneId = "America/New_York"; 8 | 9 | private static TimeZoneInfo Est { get; } = 10 | TimeZoneInfo.FindSystemTimeZoneById( 11 | shouldUseWindowsTimeZoneId() ? WindowsTimeZoneId : IanaTimeZoneId); 12 | 13 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 14 | public static DateTime ConvertFromEstToUtc( 15 | DateTime estDateTime) => 16 | TimeZoneInfo.ConvertTimeToUtc(estDateTime, Est); 17 | 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public static DateTimeOffset AsDateTimeOffset( 20 | in DateOnly date, in TimeOnly time) => 21 | date.ToDateTime(time, DateTimeKind.Unspecified).asDateTimeOffset(); 22 | 23 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 24 | private static DateTimeOffset asDateTimeOffset( 25 | this DateTime estDateTime) => 26 | new(estDateTime, Est.GetUtcOffset(estDateTime)); 27 | 28 | private static Boolean shouldUseWindowsTimeZoneId() => 29 | #if NETFRAMEWORK 30 | true; // The .NET Framework 4.x exists only on Windows platform 31 | #elif NET6_0_OR_GREATER 32 | false; // The .NET 6 can use both IANA and Windows time zone names 33 | #else 34 | System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform( 35 | System.Runtime.InteropServices.OSPlatform.Windows); 36 | #endif 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/DateOnlyConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | [SuppressMessage( 6 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 7 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 8 | internal sealed class DateOnlyConverter : JsonConverter 9 | { 10 | private const String DateFormat = "O"; 11 | 12 | public override void WriteJson( 13 | JsonWriter writer, 14 | Object? value, 15 | JsonSerializer serializer) 16 | { 17 | // ReSharper disable once ConvertIfStatementToSwitchStatement 18 | if (value is DateOnly dateOnlyValue) 19 | { 20 | writer.WriteValue(dateOnlyValue.ToString(DateFormat, CultureInfo.InvariantCulture)); 21 | } 22 | } 23 | 24 | public override Object? ReadJson( 25 | JsonReader reader, 26 | Type objectType, 27 | Object? existingValue, 28 | JsonSerializer serializer) => 29 | DateOnly.TryParseExact(reader.Value?.ToString(), DateFormat, out var dateOnlyValue) 30 | ? dateOnlyValue 31 | : null; 32 | 33 | [ExcludeFromCodeCoverage] 34 | public override Boolean CanConvert(Type objectType) => 35 | objectType == typeof(DateOnly) || objectType == typeof(DateOnly?); 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/DateTimeHelper.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class DateTimeHelper 4 | { 5 | public static DateTime AsUtcDateTime( 6 | this in DateTime value) => 7 | DateTime.SpecifyKind(value, DateTimeKind.Utc); 8 | 9 | public static DateTime FromUnixTimeSeconds( 10 | this in Int64 linuxTimeStamp) => 11 | DateTimeOffset.FromUnixTimeSeconds(linuxTimeStamp).UtcDateTime; 12 | 13 | public static Int64 IntoUnixTimeSeconds( 14 | this in DateTime dateTime) => 15 | new DateTimeOffset(dateTime).ToUnixTimeSeconds(); 16 | 17 | public static DateOnly? AsDateOnly( 18 | this in DateTime? dateTime) 19 | => dateTime.HasValue ? DateOnly.FromDateTime(dateTime.Value) : null; 20 | 21 | public static DateTime? AsDateTime( 22 | this in DateOnly? dateOnly) 23 | => dateOnly?.ToDateTime(TimeOnly.MinValue); 24 | } 25 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/DecimalExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class DecimalExtensions 4 | { 5 | public static Int64 AsInteger(this Decimal value) => 6 | (Int64)Math.Round(value, MidpointRounding.ToEven); 7 | } 8 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/DictionaryExtensions.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json.Linq; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | internal static class DictionaryExtensions 6 | { 7 | private static IEnumerable getConditions( 8 | Object? conditions) => 9 | conditions switch 10 | { 11 | JArray jArray => jArray.SelectMany(getConditions), 12 | JValue jValue => getConditions(jValue.Value), 13 | String value => Enumerable.Repeat(value, 1), 14 | _ => [] 15 | }; 16 | 17 | public static IReadOnlyDictionary> SetSymbol( 18 | this Dictionary?>? dictionary) 19 | where TFrom : TInto, ISymbolMutable => 20 | dictionary?.ToDictionary( 21 | pair => pair.Key, 22 | pair => pair.Value.SetSymbol(pair.Key).EmptyIfNull(), 23 | StringComparer.Ordinal) 24 | ?? new Dictionary>(StringComparer.Ordinal); 25 | 26 | #if NETFRAMEWORK || NETSTANDARD2_0 27 | public static TValue GetValueOrDefault( 28 | this IReadOnlyDictionary dictionary, 29 | TKey key, TValue defaultValue) => 30 | dictionary.TryGetValue(key, out var value) ? value : defaultValue; 31 | #endif 32 | 33 | public static IEnumerable GetConditions( 34 | this IReadOnlyDictionary extensionData) => 35 | extensionData.TryGetValue("c", out var conditions) 36 | ? getConditions(conditions) : []; 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | #if !NET6_0_OR_GREATER 2 | namespace Alpaca.Markets; 3 | 4 | internal static class EnumerableExtensions 5 | { 6 | public static IEnumerable Chunk( 7 | this IEnumerable source, 8 | Int32 size) 9 | { 10 | using var e = source.EnsureNotNull().GetEnumerator(); 11 | while (e.MoveNext()) 12 | { 13 | var chunk = new TSource[size]; 14 | chunk[0] = e.Current; 15 | 16 | var i = 1; 17 | for (; i < chunk.Length && e.MoveNext(); i++) 18 | { 19 | chunk[i] = e.Current; 20 | } 21 | 22 | if (i == chunk.Length) 23 | { 24 | yield return chunk; 25 | } 26 | else 27 | { 28 | Array.Resize(ref chunk, i); 29 | yield return chunk; 30 | yield break; 31 | } 32 | } 33 | } 34 | } 35 | #endif 36 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/ExchangeEnumConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class ExchangeEnumConverter : StringEnumConverter 7 | { 8 | public override Object ReadJson( 9 | JsonReader reader, 10 | Type objectType, 11 | Object? existingValue, 12 | JsonSerializer serializer) => 13 | Exchange.Unknown.FromEnumString(reader); 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/HttpClientExtensions.Patch.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static partial class HttpClientExtensions 4 | { 5 | private static readonly HttpMethod _httpMethodPatch = 6 | #if NETSTANDARD2_1 || NET6_0_OR_GREATER 7 | HttpMethod.Patch; 8 | #else 9 | new("PATCH"); 10 | #endif 11 | 12 | public static Task PatchAsync( 13 | this HttpClient httpClient, 14 | String endpointUri, 15 | TRequest request, 16 | RateLimitHandler rateLimitHandler, 17 | CancellationToken cancellationToken) 18 | where TJson : TApi => 19 | callAndDeserializeAsync( 20 | httpClient, _httpMethodPatch, asUri(endpointUri), request, rateLimitHandler, cancellationToken); 21 | } 22 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/HttpStatusCodeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System.Net; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | internal static class HttpStatusCodeExtensions 6 | { 7 | private static Boolean isSuccessHttpStatusCode( 8 | this HttpStatusCode httpStatusCode) => 9 | httpStatusCode is >= HttpStatusCode.OK and < HttpStatusCode.Ambiguous; 10 | 11 | public static Boolean IsSuccessHttpStatusCode( 12 | this Int64 httpStatusCode) => 13 | isSuccessHttpStatusCode((HttpStatusCode)httpStatusCode); 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/KeyValuePairExtensions.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK || NETSTANDARD2_0 2 | 3 | namespace Alpaca.Markets; 4 | 5 | internal static class KeyValuePairExtensions 6 | { 7 | public static void Deconstruct( 8 | // ReSharper disable once UseDeconstructionOnParameter 9 | this KeyValuePair keyValuePair, 10 | out TKey key, 11 | out TValue value) 12 | { 13 | key = keyValuePair.Key; 14 | value = keyValuePair.Value; 15 | } 16 | } 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/ListExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class ListExtensions 4 | { 5 | public static IReadOnlyList EmptyIfNull(this List? list) 6 | where TFrom : TInto => EmptyIfNull((IReadOnlyList?)list); 7 | 8 | public static IReadOnlyList EmptyIfNull(this IReadOnlyList? list) => 9 | list ?? Array.Empty(); 10 | 11 | public static List? NullIfEmpty(this List list) => 12 | list.Count != 0 ? list : null; 13 | 14 | public static List? SetSymbol(this List? list, String symbol) 15 | where T : ISymbolMutable 16 | { 17 | list?.ForEach(symbolMutable => symbolMutable.SetSymbol(symbol)); 18 | return list; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/OrderExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Set of extension methods for interface. 5 | /// 6 | public static class OrderExtensions 7 | { 8 | /// 9 | /// Gets order quantity as instance of the structure. 10 | /// 11 | /// Order for reading quantity value. 12 | /// 13 | /// The argument is null. 14 | /// 15 | /// 16 | /// Both fractional and notional order quantity values are null. 17 | /// 18 | /// Fractional or notional order quantity value. 19 | [UsedImplicitly] 20 | [CLSCompliant(false)] 21 | public static OrderQuantity GetOrderQuantity( 22 | this IOrder order) 23 | { 24 | var notNullOrder = order.EnsureNotNull(); 25 | return notNullOrder.Quantity.HasValue 26 | ? OrderQuantity.Fractional(notNullOrder.Quantity.Value) 27 | : notNullOrder.Notional.HasValue 28 | ? OrderQuantity.Notional(notNullOrder.Notional.Value) 29 | : throw new InvalidOperationException(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/OrderSideEnumConverter.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class OrderSideEnumConverter : StringEnumConverter 7 | { 8 | public override Object ReadJson( 9 | JsonReader reader, 10 | Type objectType, 11 | Object? existingValue, 12 | JsonSerializer serializer) => 13 | OrderSide.Sell.FromEnumString(reader); 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/TimeOnlyConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | [SuppressMessage( 6 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 7 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 8 | internal sealed class TimeOnlyConverter : JsonConverter 9 | { 10 | private static readonly String[] _timeFormats = [ "HH:mm", "HHmm" ]; 11 | 12 | public override void WriteJson( 13 | JsonWriter writer, 14 | Object? value, 15 | JsonSerializer serializer) 16 | { 17 | // ReSharper disable once ConvertIfStatementToSwitchStatement 18 | if (value is TimeOnly timeOnlyValue) 19 | { 20 | writer.WriteValue(timeOnlyValue.ToString(_timeFormats[0], CultureInfo.InvariantCulture)); 21 | } 22 | } 23 | 24 | public override Object? ReadJson( 25 | JsonReader reader, 26 | Type objectType, 27 | Object? existingValue, 28 | JsonSerializer serializer) => 29 | TimeOnly.TryParseExact(reader.Value?.ToString(), _timeFormats, out var timeOnlyValue) 30 | ? timeOnlyValue 31 | : null; 32 | 33 | [ExcludeFromCodeCoverage] 34 | public override Boolean CanConvert(Type objectType) => 35 | objectType == typeof(TimeOnly); 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/UnixSecondsDateTimeConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | [SuppressMessage( 6 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 7 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 8 | internal sealed class UnixSecondsDateTimeConverter : DateTimeConverterBase 9 | { 10 | public override void WriteJson( 11 | JsonWriter writer, 12 | Object? value, 13 | JsonSerializer serializer) 14 | { 15 | if (value is DateTime dateTimeValue) 16 | { 17 | writer.WriteValue(dateTimeValue.IntoUnixTimeSeconds()); 18 | } 19 | } 20 | 21 | public override Object? ReadJson( 22 | JsonReader reader, 23 | Type objectType, 24 | Object? existingValue, 25 | JsonSerializer serializer) => 26 | Int64.TryParse(reader.Value?.ToString(), 27 | NumberStyles.Integer, CultureInfo.InvariantCulture, out var unixTimeStamp) 28 | ? unixTimeStamp.FromUnixTimeSeconds() 29 | : null; 30 | } 31 | -------------------------------------------------------------------------------- /Alpaca.Markets/Helpers/UriBuilderExtensions.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal static class UriBuilderExtensions 4 | { 5 | public static UriBuilder AppendPath( 6 | this UriBuilder uriBuilder, 7 | String pathSegment) 8 | { 9 | uriBuilder.Path += pathSegment; 10 | return uriBuilder; 11 | } 12 | public static UriBuilder WithPath( 13 | this UriBuilder uriBuilder, 14 | String path) 15 | { 16 | uriBuilder.Path = path; 17 | return uriBuilder; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAccountConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates account configuration settings from Alpaca REST API. 5 | /// 6 | public interface IAccountConfiguration 7 | { 8 | /// 9 | /// Gets or sets day trade margin call protection mode for account. 10 | /// 11 | [UsedImplicitly] 12 | DayTradeMarginCallProtection DayTradeMarginCallProtection { get; set; } 13 | 14 | /// 15 | /// Gets or sets notification level for order fill emails. 16 | /// 17 | [UsedImplicitly] 18 | TradeConfirmEmail TradeConfirmEmail { get; set; } 19 | 20 | /// 21 | /// Gets or sets control flag for blocking new orders placement. 22 | /// 23 | [UsedImplicitly] 24 | Boolean IsSuspendTrade { get; set; } 25 | 26 | /// 27 | /// Gets or sets control flag for enabling long-only account mode. 28 | /// 29 | [UsedImplicitly] 30 | Boolean IsNoShorting { get; set; } 31 | 32 | /// 33 | /// Gets or sets control flag for enabling orders acceptance for PTP symbols with no exception. 34 | /// 35 | [UsedImplicitly] 36 | public Boolean IsPtpNoExceptionEntry { get; set; } 37 | 38 | /// 39 | /// Gets the desired maximum options trading level. 40 | /// 41 | [UsedImplicitly] 42 | OptionsTradingLevel? MaxOptionsTradingLevel { get; } 43 | } 44 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IActiveStock.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the single active stock information from Alpaca APIs. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IActiveStock 8 | { 9 | /// 10 | /// Gets the stock instrument symbol name. 11 | /// 12 | [UsedImplicitly] 13 | String Symbol { get; } 14 | 15 | /// 16 | /// Gets the current instrument volume value. 17 | /// 18 | [UsedImplicitly] 19 | Decimal Volume { get; } 20 | 21 | /// 22 | /// Gets the current instrument trade count value. 23 | /// 24 | [UsedImplicitly] 25 | UInt64 TradeCount { get; } 26 | } 27 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAlpacaCryptoStreamingClient.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Provides unified type-safe access for Alpaca crypto data streaming API via websockets. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IAlpacaCryptoStreamingClient : IStreamingDataClient 8 | { 9 | /// 10 | /// Gets the order book updates subscription for the asset. 11 | /// 12 | /// Alpaca asset name. 13 | /// 14 | /// The underlying subscriptions dictionary contains too many elements. 15 | /// 16 | /// 17 | /// The argument is null. 18 | /// 19 | /// 20 | /// Subscription object for tracking updates via the event. 21 | /// 22 | [UsedImplicitly] 23 | public IAlpacaDataSubscription GetOrderBookSubscription( 24 | String symbol); 25 | } 26 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAlpacaDataSubscription.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates generic Alpaca Data streaming API subscription item. 5 | /// 6 | public interface IAlpacaDataSubscription 7 | { 8 | /// 9 | /// Gets the stream names - updates type (channel name) and asset name (symbol) list. 10 | /// 11 | IEnumerable Streams { get; } 12 | 13 | /// 14 | /// Gets boolean flag indicating the current subscription status of this item. 15 | /// An unsubscribed subscription does not receive streaming data. 16 | /// 17 | [UsedImplicitly] 18 | Boolean Subscribed { get; } 19 | 20 | /// 21 | /// Occurs when a property value has changed. 22 | /// 23 | [UsedImplicitly] 24 | event Action? OnSubscribedChanged; 25 | } 26 | 27 | /// 28 | /// Encapsulates strongly-typed Alpaca Data streaming API subscription item. 29 | /// 30 | /// Streaming update concrete type. 31 | public interface IAlpacaDataSubscription : IAlpacaDataSubscription 32 | { 33 | /// 34 | /// Occurs when a new item is received from the stream. 35 | /// 36 | [UsedImplicitly] 37 | event Action? Received; 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAlpacaNewsStreamingClient.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Provides unified type-safe access for Alpaca data streaming API via websockets. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IAlpacaNewsStreamingClient : IStreamingClient, ISubscriptionHandler 8 | { 9 | /// 10 | /// Gets the news articles' updates subscription for all stock and crypto assets. 11 | /// 12 | /// 13 | /// Subscription object for tracking updates via the event. 14 | /// 15 | [UsedImplicitly] 16 | IAlpacaDataSubscription GetNewsSubscription(); 17 | 18 | /// 19 | /// Gets the news articles' updates subscription for the asset. 20 | /// 21 | /// Alpaca asset symbol. 22 | /// 23 | /// The underlying subscriptions dictionary contains too many elements. 24 | /// 25 | /// 26 | /// The argument is null. 27 | /// 28 | /// 29 | /// Subscription object for tracking updates via the event. 30 | /// 31 | [UsedImplicitly] 32 | IAlpacaDataSubscription GetNewsSubscription( 33 | String symbol); 34 | } 35 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAlpacaStreamingClient.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Provides unified type-safe access for Alpaca streaming API. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IAlpacaStreamingClient : IStreamingClient 8 | { 9 | /// 10 | /// Occurs when a new trade update is received from the stream. 11 | /// 12 | [UsedImplicitly] 13 | event Action? OnTradeUpdate; 14 | } 15 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAuction.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the basic auction information from Alpaca APIs. 5 | /// 6 | public interface IAuction 7 | { 8 | /// 9 | /// Gets asset symbol. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Gets auction date in UTC. 16 | /// 17 | [UsedImplicitly] 18 | [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", 19 | Justification = "This can cause problem only in VB.NET source code.")] 20 | DateOnly Date { get; } 21 | 22 | /// 23 | /// Gets daily auction openings. 24 | /// 25 | [UsedImplicitly] 26 | IReadOnlyList Openings { get; } 27 | 28 | /// 29 | /// Gets daily auction closings. 30 | /// 31 | [UsedImplicitly] 32 | IReadOnlyList Closings { get; } 33 | } 34 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IAuctionEntry.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the auction entry information from Alpaca APIs. 5 | /// 6 | public interface IAuctionEntry 7 | { 8 | /// 9 | /// Gets auction timestamp in UTC. 10 | /// 11 | [UsedImplicitly] 12 | DateTime TimestampUtc { get; } 13 | 14 | /// 15 | /// Gets identifier of auction source exchange. 16 | /// 17 | [UsedImplicitly] 18 | String Exchange { get; } 19 | 20 | /// 21 | /// Gets auction price level. 22 | /// 23 | [UsedImplicitly] 24 | Decimal Price { get; } 25 | 26 | /// 27 | /// Gets auction quantity. 28 | /// 29 | [UsedImplicitly] 30 | Decimal Size { get; } 31 | 32 | /// 33 | /// Gets auction condition. 34 | /// 35 | [UsedImplicitly] 36 | String Condition { get; } 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IBar.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates basic bar information for Alpaca APIs. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IBar 8 | { 9 | /// 10 | /// Gets asset symbol. 11 | /// 12 | [UsedImplicitly] 13 | String Symbol { get; } 14 | 15 | /// 16 | /// Gets the beginning time of this bar in UTC. 17 | /// 18 | [UsedImplicitly] 19 | DateTime TimeUtc { get; } 20 | 21 | /// 22 | /// Gets bar open price. 23 | /// 24 | [UsedImplicitly] 25 | Decimal Open { get; } 26 | 27 | /// 28 | /// Gets bar high price. 29 | /// 30 | [UsedImplicitly] 31 | Decimal High { get; } 32 | 33 | /// 34 | /// Gets bar low price. 35 | /// 36 | [UsedImplicitly] 37 | Decimal Low { get; } 38 | 39 | /// 40 | /// Gets bar close price. 41 | /// 42 | [UsedImplicitly] 43 | Decimal Close { get; } 44 | 45 | /// 46 | /// Gets bar trading volume. 47 | /// 48 | [UsedImplicitly] 49 | Decimal Volume { get; } 50 | 51 | /// 52 | /// Gets bar volume weighted average price. 53 | /// 54 | [UsedImplicitly] 55 | Decimal Vwap { get; } 56 | 57 | /// 58 | /// Gets total trades count for this bar. 59 | /// 60 | [UsedImplicitly] 61 | UInt64 TradeCount { get; } 62 | } 63 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ICashDividend.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the cash dividend information from Alpaca APIs. 5 | /// 6 | public interface ICashDividend 7 | { 8 | /// 9 | /// Gets the symbol 10 | /// 11 | public String Symbol { get; } 12 | 13 | /// 14 | /// Gets the dividend rate 15 | /// 16 | public Decimal Rate { get; } 17 | 18 | /// 19 | /// Gets the foreign flag 20 | /// 21 | public Boolean IsForeign { get; } 22 | 23 | /// 24 | /// Gets te special flag 25 | /// 26 | public Boolean IsSpecial { get; } 27 | 28 | /// 29 | /// Gets the cash dividend process date 30 | /// 31 | public DateOnly ProcessDate { get; } 32 | 33 | /// 34 | /// Gets the cash dividend execution date 35 | /// 36 | public DateOnly ExecutionDate { get; } 37 | 38 | /// 39 | /// Gets the cash dividend record date 40 | /// 41 | public DateOnly? RecordDate { get; } 42 | 43 | /// 44 | /// Gets the cash dividend payable date 45 | /// 46 | public DateOnly? PayableDate { get; } 47 | 48 | /// 49 | /// Gets the cash dividend due bill off date 50 | /// 51 | public DateOnly? DueBillOffDate { get; } 52 | 53 | /// 54 | /// Gets the cash dividend due bill on date 55 | /// 56 | public DateOnly? DueBillOnDate { get; } 57 | } 58 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ICashMerger.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the cash merger information from Alpaca APIs. 5 | /// 6 | public interface ICashMerger 7 | { 8 | /// 9 | /// Gets the acquirer symbol 10 | /// 11 | public String? AcquirerSymbol { get; } 12 | 13 | /// 14 | /// Gets the acquiree symbol 15 | /// 16 | public String AcquireeSymbol { get; } 17 | 18 | /// 19 | /// Gets the cash merger rate 20 | /// 21 | public Decimal Rate { get; } 22 | 23 | /// 24 | /// Gets the cash merger process date 25 | /// 26 | public DateOnly ProcessDate { get; } 27 | 28 | /// 29 | /// Gets the cash merger effective date 30 | /// 31 | public DateOnly EffectiveDate { get; } 32 | 33 | /// 34 | /// Gets the cash merger payable date 35 | /// 36 | public DateOnly? PayableDate { get; } 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IClock.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates current trading date information from Alpaca REST API. 5 | /// 6 | public interface IClock 7 | { 8 | /// 9 | /// Gets current timestamp in UTC. 10 | /// 11 | [UsedImplicitly] 12 | DateTime TimestampUtc { get; } 13 | 14 | /// 15 | /// Returns true if trading day is open now. 16 | /// 17 | [UsedImplicitly] 18 | Boolean IsOpen { get; } 19 | 20 | /// 21 | /// Gets nearest trading day open time in UTC. 22 | /// 23 | [UsedImplicitly] 24 | DateTime NextOpenUtc { get; } 25 | 26 | /// 27 | /// Gets nearest trading day close time in UTC. 28 | /// 29 | [UsedImplicitly] 30 | DateTime NextCloseUtc { get; } 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ICorrection.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates trade correction information from Alpaca APIs. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface ICorrection 8 | { 9 | /// 10 | /// Gets information about the original trade. 11 | /// 12 | [UsedImplicitly] 13 | ITrade OriginalTrade { get; } 14 | 15 | /// 16 | /// Gets information about the corrected trade. 17 | /// 18 | [UsedImplicitly] 19 | ITrade CorrectedTrade { get; } 20 | } 21 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IDictionaryPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates single page response in Alpaca Data API v2. 5 | /// 6 | /// Type of paged item (bar, trade or quote) 7 | public interface IDictionaryPage 8 | { 9 | /// 10 | /// Gets the next page token for continuation. If value of this property 11 | /// equals to null this page is the last one and no more data is available. 12 | /// 13 | [UsedImplicitly] 14 | public String? NextPageToken { get; } 15 | 16 | /// 17 | /// Gets list of items for this response grouped by asset symbols. 18 | /// 19 | public IReadOnlyDictionary Items { get; } 20 | } 21 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IErrorInformation.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates extended error information from Alpaca error REST response. 5 | /// 6 | public interface IErrorInformation 7 | { 8 | /// 9 | /// Gets the symbol name related for the error. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Gets the number of opened orders if this value related to the error. 16 | /// 17 | [UsedImplicitly] 18 | Int32? OpenOrdersCount { get; } 19 | 20 | /// 21 | /// Gets the day trading buying power if this value related to the error. 22 | /// 23 | [UsedImplicitly] 24 | Decimal? DayTradingBuyingPower { get; } 25 | 26 | /// 27 | /// Gets the maximal day trading buying power if this value related to the error. 28 | /// 29 | [UsedImplicitly] 30 | Decimal? MaxDayTradingBuyingPowerUsed { get; } 31 | 32 | /// 33 | /// Gets the used maximal day trading buying power if this value related to the error. 34 | /// 35 | [UsedImplicitly] 36 | Decimal? MaxDayTradingBuyingPowerUsedSoFar { get; } 37 | } 38 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IForwardSplit.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the forward split information from Alpaca APIs. 5 | /// 6 | public interface IForwardSplit 7 | { 8 | /// 9 | /// Gets the symbol 10 | /// 11 | public String Symbol { get; } 12 | 13 | /// 14 | /// Gets the forward split new rate 15 | /// 16 | public Decimal NewRate { get; } 17 | 18 | /// 19 | /// Gets the forward split old rate 20 | /// 21 | public Decimal OldRate { get; } 22 | 23 | /// 24 | /// Gets the forward split process date 25 | /// 26 | public DateOnly ProcessDate { get; } 27 | 28 | /// 29 | /// Gets the forward split execution date 30 | /// 31 | public DateOnly ExecutionDate { get; } 32 | 33 | /// 34 | /// Gets the forward split record date 35 | /// 36 | public DateOnly? RecordDate { get; } 37 | 38 | /// 39 | /// Gets the forward split payable date 40 | /// 41 | public DateOnly? PayableDate { get; } 42 | 43 | /// 44 | /// Gets the forward split due bill redemption date 45 | /// 46 | public DateOnly? DueBillRedemptionDate { get; } 47 | } 48 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IGreeks.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Options Greeks are a set of risk measures that are used in the options market to evaluate the risk and reward of an option. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IGreeks 8 | { 9 | /// 10 | /// Gets the rate of change of an option's price relative to a change in the price of the underlying asset. 11 | /// 12 | [UsedImplicitly] 13 | Decimal? Delta { get; } 14 | 15 | /// 16 | /// Gets the rate of change in an option's delta relative to a change in the price of the underlying asset. 17 | /// 18 | [UsedImplicitly] 19 | Decimal? Gamma { get; } 20 | 21 | /// 22 | /// Gets the rate of change in an option's price relative to a change in the risk-free rate of interest. 23 | /// 24 | [UsedImplicitly] 25 | Decimal? Rho { get; } 26 | 27 | /// 28 | /// Gets the rate of change in an option's price relative to a change in time. 29 | /// 30 | [UsedImplicitly] 31 | Decimal? Theta { get; } 32 | 33 | /// 34 | /// Gets the rate of change in an option's price relative to a change in the volatility of the underlying asset. 35 | /// 36 | [UsedImplicitly] 37 | Decimal? Vega { get; } 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IHistoricalRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | // TODO: olegra - rename this interface into IRequestWithPagination 4 | 5 | /// 6 | /// Provides unified type-safe access to the historical data request parameters. 7 | /// 8 | public interface IHistoricalRequest 9 | { 10 | /// 11 | /// Gets the pagination parameters for the request (page size and token). 12 | /// 13 | Pagination Pagination { get; } 14 | } 15 | 16 | /// 17 | /// Provides unified type-safe access to the historical data request parameters. 18 | /// 19 | /// Historical data request type. 20 | /// Historical response data item type. 21 | // ReSharper disable once UnusedTypeParameter 22 | public interface IHistoricalRequest : IHistoricalRequest 23 | { 24 | /// 25 | /// Gets copy of the current request without page token and max allowed page size. 26 | /// 27 | [UsedImplicitly] 28 | [SuppressMessage("Design", 29 | "CA1024:Use properties where appropriate", Justification = "Factory method")] 30 | TRequest GetValidatedRequestWithoutPageToken(); 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IIntervalCalendar.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates single trading day information from Alpaca REST API. 5 | /// 6 | public interface IIntervalCalendar 7 | { 8 | /// 9 | /// Gets trading open and close times in EST time zone. 10 | /// 11 | public OpenClose Trading { get; } 12 | 13 | /// 14 | /// Gets session open and close times in EST time zone. 15 | /// 16 | public OpenClose Session { get; } 17 | } 18 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ILimitUpLimitDown.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the basic LULD update information from Alpaca APIs. 5 | /// 6 | public interface ILimitUpLimitDown 7 | { 8 | /// 9 | /// Gets asset symbol. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Gets the LULD update timestamp in UTC. 16 | /// 17 | [UsedImplicitly] 18 | DateTime TimestampUtc { get; } 19 | 20 | /// 21 | /// Gets the current limit up price. 22 | /// 23 | [UsedImplicitly] 24 | Decimal LimitUpPrice { get; } 25 | 26 | /// 27 | /// Gets the current limit down price. 28 | /// 29 | [UsedImplicitly] 30 | Decimal LimitDownPrice { get; } 31 | 32 | /// 33 | /// Gets the indicator name. 34 | /// 35 | [UsedImplicitly] 36 | String Indicator { get; } 37 | 38 | /// 39 | /// Gets tape. 40 | /// 41 | [UsedImplicitly] 42 | String Tape { get; } 43 | } 44 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IMarketMover.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the single market mover information from Alpaca APIs. 5 | /// 6 | public interface IMarketMover 7 | { 8 | /// 9 | /// Gets the instrument symbol name. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Gets the current instrument price value. 16 | /// 17 | [UsedImplicitly] 18 | Decimal Price { get; } 19 | 20 | /// 21 | /// Gets the current instrument price change value. 22 | /// 23 | [UsedImplicitly] 24 | Decimal Change { get; } 25 | 26 | /// 27 | /// Gets the current instrument price change value in percents. 28 | /// 29 | [UsedImplicitly] 30 | Decimal PercentChange { get; } 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IMarketMovers.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates two lists of market movers from Alpaca APIs. 5 | /// 6 | public interface IMarketMovers 7 | { 8 | /// 9 | /// Gets list of the top market losers. 10 | /// 11 | [UsedImplicitly] 12 | IReadOnlyList Losers { get; } 13 | 14 | /// 15 | /// Gets list of the top market gainers. 16 | /// 17 | [UsedImplicitly] 18 | IReadOnlyList Gainers { get; } 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IMultiPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates single page response in Alpaca Data API v2. 5 | /// 6 | /// Type of paged item (bar, trade or quote) 7 | public interface IMultiPage 8 | { 9 | /// 10 | /// Gets the next page token for continuation. If value of this property 11 | /// equals to null this page is the last one and no more data is available. 12 | /// 13 | [UsedImplicitly] 14 | public String? NextPageToken { get; } 15 | 16 | /// 17 | /// Gets list of items for this response grouped by asset symbols. 18 | /// 19 | public IReadOnlyDictionary> Items { get; } 20 | } 21 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IMultiPageMutable.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal interface IMultiPageMutable : IMultiPage 4 | { 5 | public new String? NextPageToken { [UsedImplicitly] get; set; } 6 | 7 | public new IReadOnlyDictionary> Items { [UsedImplicitly] get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/INameChange.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the name change information from Alpaca APIs. 5 | /// 6 | public interface INameChange 7 | { 8 | /// 9 | /// Gets the old symbol 10 | /// 11 | public String OldSymbol { get; } 12 | 13 | /// 14 | /// Gets the new symbol 15 | /// 16 | public String NewSymbol { get; } 17 | 18 | /// 19 | /// Gets the name change process date 20 | /// 21 | public DateOnly ProcessDate { get; } 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IOptionSnapshot.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates option snapshot information from the Alpaca REST API. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface IOptionSnapshot 8 | { 9 | /// 10 | /// Gets the snapshot's option symbol. 11 | /// 12 | [UsedImplicitly] 13 | String Symbol { get; } 14 | 15 | /// 16 | /// Gets the latest quote information. 17 | /// 18 | [UsedImplicitly] 19 | IQuote? Quote { get; } 20 | 21 | /// 22 | /// Gets the latest trade information. 23 | /// 24 | [UsedImplicitly] 25 | ITrade? Trade { get; } 26 | 27 | /// 28 | /// Gets the option greeks data. 29 | /// 30 | [UsedImplicitly] 31 | IGreeks? Greeks { get; } 32 | 33 | /// 34 | /// Gets the implied volatility of the option. 35 | /// 36 | [UsedImplicitly] 37 | Decimal? ImpliedVolatility { get; } 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IOrderActionStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates order action status information from Alpaca REST API. 5 | /// 6 | public interface IOrderActionStatus 7 | { 8 | /// 9 | /// Gets unique server-side order identifier. 10 | /// 11 | [UsedImplicitly] 12 | Guid OrderId { get; } 13 | 14 | /// 15 | /// Returns true if requested action completed successfully. 16 | /// 17 | [UsedImplicitly] 18 | Boolean IsSuccess { get; } 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IOrderBook.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the basic order book information from Alpaca APIs. 5 | /// 6 | public interface IOrderBook 7 | { 8 | /// 9 | /// Gets asset name. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Gets quote timestamp in UTC time zone. 16 | /// 17 | [UsedImplicitly] 18 | DateTime TimestampUtc { get; } 19 | 20 | /// 21 | /// Gets identifier of source exchange. 22 | /// 23 | [UsedImplicitly] 24 | String Exchange { get; } 25 | 26 | /// 27 | /// Gets bids price/quantity pairs list. 28 | /// 29 | [UsedImplicitly] 30 | IReadOnlyList Bids { get; } 31 | 32 | /// 33 | /// Gets asks price/quantity pairs list. 34 | /// 35 | [UsedImplicitly] 36 | IReadOnlyList Asks { get; } 37 | 38 | /// 39 | /// Gets the order book reset flag. 40 | /// 41 | [UsedImplicitly] 42 | Boolean IsReset { get; } 43 | } 44 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IOrderBookEntry.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the order book price/size pair information. 5 | /// 6 | public interface IOrderBookEntry 7 | { 8 | /// 9 | /// Gets price level. 10 | /// 11 | [UsedImplicitly] 12 | Decimal Price { get; } 13 | 14 | /// 15 | /// Gets quantity. 16 | /// 17 | [UsedImplicitly] 18 | Decimal Size { get; } 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates single page response in Alpaca Data API v2. 5 | /// 6 | /// Type of paged item (bar, trade or quote) 7 | public interface IPage 8 | { 9 | /// 10 | /// Gets the asset symbol for all items on page. 11 | /// 12 | [UsedImplicitly] 13 | public String Symbol { get; } 14 | 15 | /// 16 | /// Gets the next page token for continuation. If value of this property 17 | /// equals to null this page is the last one and no more data is available. 18 | /// 19 | [UsedImplicitly] 20 | public String? NextPageToken { get; } 21 | 22 | /// 23 | /// Gets list of items for this response. 24 | /// 25 | public IReadOnlyList Items { get; } 26 | } 27 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IPageMutable.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal interface IPageMutable : IPage 4 | { 5 | public new String? NextPageToken { [UsedImplicitly] get; set; } 6 | 7 | public new IReadOnlyList Items { [UsedImplicitly] get; set; } 8 | } 9 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IPortfolioHistory.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates portfolio history information from Alpaca REST API. 5 | /// 6 | public interface IPortfolioHistory 7 | { 8 | /// 9 | /// Gets historical information items list with timestamps. 10 | /// 11 | [UsedImplicitly] 12 | IReadOnlyList Items { get; } 13 | 14 | /// 15 | /// Gets time frame value for this historical view. 16 | /// 17 | [UsedImplicitly] 18 | TimeFrame TimeFrame { get; } 19 | 20 | /// 21 | /// Gets base value for this historical view. 22 | /// 23 | [UsedImplicitly] 24 | Decimal BaseValue { get; } 25 | } 26 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IPortfolioHistoryItem.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates portfolio history information item from Alpaca REST API. 5 | /// 6 | public interface IPortfolioHistoryItem 7 | { 8 | /// 9 | /// Gets historical equity value. 10 | /// 11 | [UsedImplicitly] 12 | Decimal? Equity { get; } 13 | 14 | /// 15 | /// Gets historical profit/loss value. 16 | /// 17 | [UsedImplicitly] 18 | Decimal? ProfitLoss { get; } 19 | 20 | /// 21 | /// Gets historical profit/loss value as percentages. 22 | /// 23 | [UsedImplicitly] 24 | Decimal? ProfitLossPercentage { get; } 25 | 26 | /// 27 | /// Gets historical timestamp value in UTC time zone. 28 | /// 29 | [UsedImplicitly] 30 | DateTime TimestampUtc { get; } 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IPositionActionStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates position action status information from Alpaca REST API. 5 | /// 6 | public interface IPositionActionStatus 7 | { 8 | /// 9 | /// Gets processed position asset symbol. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Returns true if requested action completed successfully. 16 | /// 17 | [UsedImplicitly] 18 | Boolean IsSuccess { get; } 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IRedemption.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the redemption information from Alpaca APIs. 5 | /// 6 | public interface IRedemption 7 | { 8 | /// 9 | /// Gets the symbol 10 | /// 11 | public String Symbol { get; } 12 | 13 | /// 14 | /// Gets the dividend rate 15 | /// 16 | public Decimal Rate { get; } 17 | 18 | /// 19 | /// Gets the redemption process date 20 | /// 21 | public DateOnly ProcessDate { get; } 22 | 23 | /// 24 | /// Gets the redemption payable date 25 | /// 26 | public DateOnly? PayableDate { get; } 27 | } 28 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IReverseSplit.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the reverse split information from Alpaca APIs. 5 | /// 6 | public interface IReverseSplit 7 | { 8 | /// 9 | /// Gets the symbol 10 | /// 11 | public String Symbol { get; } 12 | 13 | /// 14 | /// Gets the reverse split new rate 15 | /// 16 | public Decimal NewRate { get; } 17 | 18 | /// 19 | /// Gets the reverse split old rate 20 | /// 21 | public Decimal OldRate { get; } 22 | 23 | /// 24 | /// Gets the reverse split process date 25 | /// 26 | public DateOnly ProcessDate { get; } 27 | 28 | /// 29 | /// Gets the reverse split execution date 30 | /// 31 | public DateOnly ExecutionDate { get; } 32 | 33 | /// 34 | /// Gets the reverse split record date 35 | /// 36 | public DateOnly? RecordDate { get; } 37 | 38 | /// 39 | /// Gets the reverse split payable date 40 | /// 41 | public DateOnly? PayableDate { get; } 42 | } 43 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IRightsDistribution.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the right distribution information from Alpaca APIs. 5 | /// 6 | public interface IRightsDistribution 7 | { 8 | /// 9 | /// Gets the source symbol 10 | /// 11 | public String SourceSymbol { get; } 12 | 13 | /// 14 | /// Gets the new symbol 15 | /// 16 | public String NewSymbol { get; } 17 | 18 | /// 19 | /// Gets the right distribution rate 20 | /// 21 | public Decimal Rate { get; } 22 | 23 | /// 24 | /// Gets the right distribution process date 25 | /// 26 | public DateOnly ProcessDate { get; } 27 | 28 | /// 29 | /// Gets the right distribution execution date 30 | /// 31 | public DateOnly ExecutionDate { get; } 32 | 33 | /// 34 | /// Gets the right distribution payable date 35 | /// 36 | public DateOnly? PayableDate { get; } 37 | 38 | /// 39 | /// Gets the right distribution record date 40 | /// 41 | public DateOnly? RecordDate { get; } 42 | 43 | /// 44 | /// Gets the right distribution expiration date 45 | /// 46 | public DateOnly? ExpirationDate { get; } 47 | } 48 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ISnapshot.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates snapshot information from the Alpaca REST API. 5 | /// 6 | [CLSCompliant(false)] 7 | public interface ISnapshot 8 | { 9 | /// 10 | /// Gets the snapshot's asset symbol. 11 | /// 12 | [UsedImplicitly] 13 | String Symbol { get; } 14 | 15 | /// 16 | /// Gets the latest quote information. 17 | /// 18 | [UsedImplicitly] 19 | IQuote? Quote { get; } 20 | 21 | /// 22 | /// Gets the latest trade information. 23 | /// 24 | [UsedImplicitly] 25 | ITrade? Trade { get; } 26 | 27 | /// 28 | /// Gets the current minute bar information. 29 | /// 30 | [UsedImplicitly] 31 | IBar? MinuteBar { get; } 32 | 33 | /// 34 | /// Gets the current daily bar information. 35 | /// 36 | [UsedImplicitly] 37 | IBar? CurrentDailyBar { get; } 38 | 39 | /// 40 | /// Gets the previous daily bar information. 41 | /// 42 | [UsedImplicitly] 43 | IBar? PreviousDailyBar { get; } 44 | } 45 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ISpinOff.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the spin-off information from Alpaca APIs. 5 | /// 6 | public interface ISpinOff 7 | { 8 | /// 9 | /// Gets the source symbol 10 | /// 11 | public String SourceSymbol { get; } 12 | 13 | /// 14 | /// Gets the new symbol 15 | /// 16 | public String NewSymbol { get; } 17 | 18 | /// 19 | /// Gets the spin-off source rate 20 | /// 21 | public Decimal SourceRate { get; } 22 | 23 | /// 24 | /// Gets the spin-off new rate 25 | /// 26 | public Decimal NewRate { get; } 27 | 28 | /// 29 | /// Gets the spin-off process date 30 | /// 31 | public DateOnly ProcessDate { get; } 32 | 33 | /// 34 | /// Gets the spin-off execution date 35 | /// 36 | public DateOnly ExecutionDate { get; } 37 | 38 | /// 39 | /// Gets the spin-off payable date 40 | /// 41 | public DateOnly? PayableDate { get; } 42 | 43 | /// 44 | /// Gets the spin-off record date 45 | /// 46 | public DateOnly? RecordDate { get; } 47 | 48 | /// 49 | /// Gets the spin-off due bill redemption date 50 | /// 51 | public DateOnly? DueBillRedemptionDate { get; } 52 | } 53 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the basic trading status update information from Alpaca APIs. 5 | /// 6 | public interface IStatus 7 | { 8 | /// 9 | /// Gets asset symbol. 10 | /// 11 | [UsedImplicitly] 12 | String Symbol { get; } 13 | 14 | /// 15 | /// Gets status timestamp in UTC. 16 | /// 17 | [UsedImplicitly] 18 | DateTime TimestampUtc { get; } 19 | 20 | /// 21 | /// Gets status code. 22 | /// 23 | [UsedImplicitly] 24 | String StatusCode { get; } 25 | 26 | /// 27 | /// Gets status message. 28 | /// 29 | [UsedImplicitly] 30 | String StatusMessage { get; } 31 | 32 | /// 33 | /// Gets reason code. 34 | /// 35 | [UsedImplicitly] 36 | String ReasonCode { get; } 37 | 38 | /// 39 | /// Gets reason message. 40 | /// 41 | [UsedImplicitly] 42 | String ReasonMessage { get; } 43 | 44 | /// 45 | /// Gets tape. 46 | /// 47 | [UsedImplicitly] 48 | String Tape { get; } 49 | } 50 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IStockAndCashMerger.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the stock and cash merger information from Alpaca APIs. 5 | /// 6 | public interface IStockAndCashMerger 7 | { 8 | /// 9 | /// Gets the acquirer symbol 10 | /// 11 | public String AcquirerSymbol { get; } 12 | 13 | /// 14 | /// Gets the acquiree symbol 15 | /// 16 | public String AcquireeSymbol { get; } 17 | 18 | /// 19 | /// Gets the acquirer rate 20 | /// 21 | public Decimal AcquirerRate { get; } 22 | 23 | /// 24 | /// Gets the acquiree rate 25 | /// 26 | public Decimal AcquireeRate { get; } 27 | 28 | /// 29 | /// Gets the cash rate 30 | /// 31 | public Decimal CashRate { get; } 32 | 33 | /// 34 | /// Gets the stock and cash merger process date 35 | /// 36 | public DateOnly ProcessDate { get; } 37 | 38 | /// 39 | /// Gets the stock and cash merger effective date 40 | /// 41 | public DateOnly EffectiveDate { get; } 42 | 43 | /// 44 | /// Gets the stock and cash merger payable date 45 | /// 46 | public DateOnly? PayableDate { get; } 47 | } 48 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IStockDividend.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the stock dividend information from Alpaca APIs. 5 | /// 6 | public interface IStockDividend 7 | { 8 | /// 9 | /// Gets the symbol 10 | /// 11 | public String Symbol { get; } 12 | 13 | /// 14 | /// Gets the dividend rate 15 | /// 16 | public Decimal Rate { get; } 17 | 18 | /// 19 | /// Gets the stock dividend process date 20 | /// 21 | public DateOnly ProcessDate { get; } 22 | 23 | /// 24 | /// Gets the stock dividend execution date 25 | /// 26 | public DateOnly ExecutionDate { get; } 27 | 28 | /// 29 | /// Gets the stock dividend record date 30 | /// 31 | public DateOnly? RecordDate { get; } 32 | 33 | /// 34 | /// Gets the stock dividend payable date 35 | /// 36 | public DateOnly? PayableDate { get; } 37 | } -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IStockMerger.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the stock merger information from Alpaca APIs. 5 | /// 6 | public interface IStockMerger 7 | { 8 | /// 9 | /// Gets the acquirer symbol 10 | /// 11 | public String AcquirerSymbol { get; } 12 | 13 | /// 14 | /// Gets the acquiree symbol 15 | /// 16 | public String AcquireeSymbol { get; } 17 | 18 | /// 19 | /// Gets the acquirer rate 20 | /// 21 | public Decimal AcquirerRate { get; } 22 | 23 | /// 24 | /// Gets the acquiree rate 25 | /// 26 | public Decimal AcquireeRate { get; } 27 | 28 | /// 29 | /// Gets the stock merger process date 30 | /// 31 | public DateOnly ProcessDate { get; } 32 | 33 | /// 34 | /// Gets the stock merger effective date 35 | /// 36 | public DateOnly EffectiveDate { get; } 37 | 38 | /// 39 | /// Gets the stock merger payable date 40 | /// 41 | public DateOnly? PayableDate { get; } 42 | } 43 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/ISymbolMutable.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal interface ISymbolMutable 4 | { 5 | void SetSymbol( 6 | String symbol); 7 | } 8 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IUnitSplit.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the unit split information from Alpaca APIs. 5 | /// 6 | public interface IUnitSplit 7 | { 8 | /// 9 | /// Gets the new symbol 10 | /// 11 | public String NewSymbol { get; } 12 | 13 | /// 14 | /// Gets the old symbol 15 | /// 16 | public String OldSymbol { get; } 17 | 18 | /// 19 | /// Gets the alternate symbol 20 | /// 21 | public String AlternateSymbol { get; } 22 | 23 | /// 24 | /// Gets the unit split new rate 25 | /// 26 | public Decimal NewRate { get; } 27 | 28 | /// 29 | /// Gets the unit split old rate 30 | /// 31 | public Decimal OldRate { get; } 32 | 33 | /// 34 | /// Gets the unit split alternate rate 35 | /// 36 | public Decimal AlternateRate { get; } 37 | 38 | /// 39 | /// Gets the unit split process date 40 | /// 41 | public DateOnly ProcessDate { get; } 42 | 43 | /// 44 | /// Gets the unit split effective date 45 | /// 46 | public DateOnly EffectiveDate { get; } 47 | 48 | /// 49 | /// Gets the unit split payable date 50 | /// 51 | public DateOnly? PayableDate { get; } 52 | } 53 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IWatchList.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates watch list information from Alpaca REST API. 5 | /// 6 | public interface IWatchList 7 | { 8 | /// 9 | /// Gets unique watch list identifier. 10 | /// 11 | [UsedImplicitly] 12 | Guid WatchListId { get; } 13 | 14 | /// 15 | /// Gets watch list creation time in UTC. 16 | /// 17 | [UsedImplicitly] 18 | DateTime CreatedUtc { get; } 19 | 20 | /// 21 | /// Gets watch list last update time in UTC. 22 | /// 23 | [UsedImplicitly] 24 | DateTime? UpdatedUtc { get; } 25 | 26 | /// 27 | /// Gets watch list user-defined name. 28 | /// 29 | [UsedImplicitly] 30 | String Name { get; } 31 | 32 | /// 33 | /// Gets for this watch list. 34 | /// 35 | [UsedImplicitly] 36 | Guid AccountId { get; } 37 | 38 | /// 39 | /// Gets the content of this watchlist, in the order as registered by the client. 40 | /// 41 | [UsedImplicitly] 42 | IReadOnlyList Assets { get; } 43 | } 44 | -------------------------------------------------------------------------------- /Alpaca.Markets/Interfaces/IWorthlessRemoval.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the worthless removal information from Alpaca APIs. 5 | /// 6 | public interface IWorthlessRemoval 7 | { 8 | /// 9 | /// Gets the symbol 10 | /// 11 | public String Symbol { get; } 12 | 13 | /// 14 | /// Gets the worthless removal process date 15 | /// 16 | public DateOnly ProcessDate { get; } 17 | } 18 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonActiveStock.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IActiveStock))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonActiveStock : IActiveStock 8 | { 9 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 10 | public String Symbol { get; set; } = String.Empty; 11 | 12 | [JsonProperty(PropertyName = "volume", Required = Required.Always)] 13 | public Decimal Volume { get; set; } 14 | 15 | [JsonProperty(PropertyName = "trade_count", Required = Required.Always)] 16 | public UInt64 TradeCount { get; set; } 17 | 18 | [ExcludeFromCodeCoverage] 19 | public override String ToString() => 20 | JsonConvert.SerializeObject(this); 21 | 22 | [ExcludeFromCodeCoverage] 23 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 24 | private String DebuggerDisplay => 25 | $"{nameof(IActiveStock)} {{ Symbol = \"{Symbol}\", Volume = {Volume}, TradeCount = {TradeCount} }}"; 26 | } 27 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonActiveStocks.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonActiveStocks 7 | { 8 | [JsonProperty(PropertyName = "most_actives", Required = Required.Always)] 9 | public List MostActives { get; } = []; 10 | } 11 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonAuctionEntry.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IAuctionEntry))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonAuctionEntry : IAuctionEntry 8 | { 9 | [JsonProperty(PropertyName = "t", Required = Required.Always)] 10 | public DateTime TimestampUtc { get; set; } 11 | 12 | [JsonProperty(PropertyName = "p", Required = Required.Always)] 13 | public Decimal Price { get; set; } 14 | 15 | [JsonProperty(PropertyName = "s", Required = Required.Always)] 16 | public Decimal Size { get; set; } 17 | 18 | [JsonProperty(PropertyName = "x", Required = Required.Default)] 19 | public String Exchange { get; set; } = String.Empty; 20 | 21 | [JsonProperty(PropertyName = "c", Required = Required.Always)] 22 | public String Condition { get; set; } = String.Empty; 23 | 24 | [ExcludeFromCodeCoverage] 25 | public override String ToString() => 26 | JsonConvert.SerializeObject(this); 27 | 28 | [ExcludeFromCodeCoverage] 29 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 30 | private String DebuggerDisplay => 31 | $"{{ Price = {Price}, Size = {Size} }}"; 32 | } 33 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonAuctionsPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(IAuction) + ">")] 4 | internal sealed class JsonAuctionsPage : IPageMutable, ISymbolMutable 5 | { 6 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 7 | [JsonProperty(PropertyName = "auctions", Required = Required.Default)] 8 | public List ItemsList { get; [ExcludeFromCodeCoverage] set; } = []; 9 | 10 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 11 | public String Symbol { get; set; } = String.Empty; 12 | 13 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 14 | public String? NextPageToken { get; set; } 15 | 16 | [JsonIgnore] 17 | public IReadOnlyList Items { get; set; } = new List(); 18 | 19 | public void SetSymbol(String symbol) => Symbol = symbol; 20 | 21 | [OnDeserialized] 22 | [UsedImplicitly] 23 | internal void OnDeserializedMethod( 24 | StreamingContext _) => 25 | Items = ItemsList.SetSymbol(Symbol).EmptyIfNull(); 26 | 27 | [ExcludeFromCodeCoverage] 28 | public override String ToString() => 29 | JsonConvert.SerializeObject(this); 30 | 31 | [ExcludeFromCodeCoverage] 32 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 33 | private String DebuggerDisplay => 34 | this.ToDebuggerDisplayString(); 35 | } 36 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonAuthRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class JsonAuthRequest 4 | { 5 | internal sealed class JsonData 6 | { 7 | [JsonProperty(PropertyName = "key_id", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 8 | public String? KeyId { get; set; } 9 | 10 | [JsonProperty(PropertyName = "secret_key", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 11 | public String? SecretKey { get; set; } 12 | 13 | [JsonProperty(PropertyName = "oauth_token", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 14 | public String? OAuthToken { get; set; } 15 | } 16 | 17 | [JsonProperty(PropertyName = "action", Required = Required.Always)] 18 | public JsonAction Action { get; set; } 19 | 20 | [JsonProperty(PropertyName = "data", Required = Required.Default)] 21 | public JsonData? Data { get; set; } 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonAuthResponse.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonAuthResponse 7 | { 8 | [JsonProperty(PropertyName = "status", Required = Required.Always)] 9 | public AuthStatus Status { get; set; } 10 | 11 | [JsonProperty(PropertyName = "message", Required = Required.Default)] 12 | public String Message { [ExcludeFromCodeCoverage] get; set; } = String.Empty; 13 | } 14 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonAuthentication.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class JsonAuthentication 4 | { 5 | [JsonProperty(PropertyName = "action", Required = Required.Always)] 6 | public JsonAction Action { get; set; } 7 | 8 | [JsonProperty(PropertyName = "key", Required = Required.Always)] 9 | public String KeyId { get; set; } = String.Empty; 10 | 11 | [JsonProperty(PropertyName = "secret", Required = Required.Always)] 12 | public String SecretKey { get; set; } = String.Empty; 13 | } 14 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonBarsPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(IBar) + ">")] 4 | internal sealed class JsonBarsPage : IPageMutable, ISymbolMutable 5 | { 6 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 7 | [JsonProperty(PropertyName = "bars", Required = Required.Default)] 8 | public List ItemsList { get; [ExcludeFromCodeCoverage] set; } = []; 9 | 10 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 11 | public String Symbol { get; set; } = String.Empty; 12 | 13 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 14 | public String? NextPageToken { get; set; } 15 | 16 | [JsonIgnore] 17 | public IReadOnlyList Items { get; set; } = new List(); 18 | 19 | public void SetSymbol(String symbol) => Symbol = symbol; 20 | 21 | [OnDeserialized] 22 | [UsedImplicitly] 23 | internal void OnDeserializedMethod( 24 | StreamingContext _) => 25 | Items = ItemsList.SetSymbol(Symbol).EmptyIfNull(); 26 | 27 | [ExcludeFromCodeCoverage] 28 | public override String ToString() => 29 | JsonConvert.SerializeObject(this); 30 | 31 | [ExcludeFromCodeCoverage] 32 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 33 | private String DebuggerDisplay => 34 | this.ToDebuggerDisplayString(); 35 | } 36 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonClock.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IClock))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonClock : IClock 8 | { 9 | [JsonProperty(PropertyName = "timestamp", Required = Required.Always)] 10 | [JsonConverter(typeof(AssumeUtcIsoDateTimeConverter))] 11 | public DateTime TimestampUtc { get; set; } 12 | 13 | [JsonProperty(PropertyName = "is_open", Required = Required.Always)] 14 | public Boolean IsOpen { get; set; } 15 | 16 | [JsonProperty(PropertyName = "next_open", Required = Required.Always)] 17 | [JsonConverter(typeof(AssumeUtcIsoDateTimeConverter))] 18 | public DateTime NextOpenUtc { get; set; } 19 | 20 | [JsonProperty(PropertyName = "next_close", Required = Required.Always)] 21 | [JsonConverter(typeof(AssumeUtcIsoDateTimeConverter))] 22 | public DateTime NextCloseUtc { get; set; } 23 | 24 | [ExcludeFromCodeCoverage] 25 | public override String ToString() => 26 | JsonConvert.SerializeObject(this); 27 | 28 | [ExcludeFromCodeCoverage] 29 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 30 | private String DebuggerDisplay => 31 | $"{nameof(IClock)} {{ Timestamp = {TimestampUtc:O}, IsOpen = {IsOpen}, NextOpen = {NextOpenUtc:0}, NextClose = {NextCloseUtc:0} }}"; 32 | } 33 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonConnectionSuccess.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonConnectionSuccess 7 | { 8 | [JsonProperty(PropertyName = "msg", Required = Required.Always)] 9 | public ConnectionStatus Status { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonError.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonError : IErrorInformation 7 | { 8 | [JsonProperty(PropertyName = "code", Required = Required.Default)] 9 | public Int32? Code { get; set; } 10 | 11 | [JsonProperty(PropertyName = "message", Required = Required.Default)] 12 | public String Message { get; set; } = String.Empty; 13 | 14 | [JsonProperty(PropertyName = "symbol", Required = Required.Default)] 15 | public String Symbol { get; set; } = String.Empty; 16 | 17 | [JsonProperty(PropertyName = "open_orders", Required = Required.Default)] 18 | public Int32? OpenOrdersCount { get; set; } 19 | 20 | [JsonProperty(PropertyName = "day_trading_buying_power", Required = Required.Default)] 21 | public Decimal? DayTradingBuyingPower { get; set; } 22 | 23 | [JsonProperty(PropertyName = "max_dtbp_used", Required = Required.Default)] 24 | public Decimal? MaxDayTradingBuyingPowerUsed { get; set; } 25 | 26 | [JsonProperty(PropertyName = "max_dtbp_used_so_far", Required = Required.Default)] 27 | public Decimal? MaxDayTradingBuyingPowerUsedSoFar { get; set; } 28 | } 29 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonGreeks.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IGreeks))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonGreeks : IGreeks 8 | { 9 | [JsonProperty(PropertyName = "delta", Required = Required.Default)] 10 | public Decimal? Delta { get; set; } 11 | 12 | [JsonProperty(PropertyName = "gamma", Required = Required.Default)] 13 | public Decimal? Gamma { get; set; } 14 | 15 | [JsonProperty(PropertyName = "rho", Required = Required.Default)] 16 | public Decimal? Rho { get; set; } 17 | 18 | [JsonProperty(PropertyName = "theta", Required = Required.Default)] 19 | public Decimal? Theta { get; set; } 20 | 21 | [JsonProperty(PropertyName = "vega", Required = Required.Default)] 22 | public Decimal? Vega { get; set; } 23 | 24 | [ExcludeFromCodeCoverage] 25 | public override String ToString() => 26 | JsonConvert.SerializeObject(this); 27 | 28 | [ExcludeFromCodeCoverage] 29 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 30 | private String DebuggerDisplay => 31 | $"{nameof(IGreeks)} {{ Delta = {Delta}, Gamma = {Gamma}, Rho = {Rho}, Theta = {Theta}, Vega = {Vega} }}"; 32 | } 33 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonLatestBar.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IBar))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonLatestBar : IBar 8 | { 9 | [JsonProperty(PropertyName = "bar", Required = Required.Always)] 10 | public JsonHistoricalBar Nested { get; [ExcludeFromCodeCoverage] set; } = new(); 11 | 12 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 13 | public String Symbol { get; set; } = String.Empty; 14 | 15 | [JsonIgnore] 16 | public DateTime TimeUtc => Nested.TimeUtc; 17 | 18 | [JsonIgnore] 19 | public Decimal Open => Nested.Open; 20 | 21 | [JsonIgnore] 22 | public Decimal High => Nested.High; 23 | 24 | [JsonIgnore] 25 | public Decimal Low => Nested.Low; 26 | 27 | [JsonIgnore] 28 | public Decimal Close => Nested.Close; 29 | 30 | [JsonIgnore] 31 | public Decimal Volume => Nested.Volume; 32 | 33 | [JsonIgnore] 34 | public Decimal Vwap => Nested.Vwap; 35 | 36 | [JsonIgnore] 37 | public UInt64 TradeCount => Nested.TradeCount; 38 | 39 | [ExcludeFromCodeCoverage] 40 | public override String ToString() => 41 | JsonConvert.SerializeObject(this); 42 | 43 | [ExcludeFromCodeCoverage] 44 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 45 | private String DebuggerDisplay => 46 | this.ToDebuggerDisplayString(); 47 | } 48 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonLatestData.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonLatestData 7 | { 8 | [JsonProperty(PropertyName = "quotes", Required = Required.Default)] 9 | public Dictionary Quotes { get; [ExcludeFromCodeCoverage] set; } = new(); 10 | 11 | [JsonProperty(PropertyName = "bars", Required = Required.Default)] 12 | public Dictionary Bars { get; [ExcludeFromCodeCoverage] set; } = new(); 13 | 14 | [JsonProperty(PropertyName = "trades", Required = Required.Default)] 15 | public Dictionary Trades { get; [ExcludeFromCodeCoverage] set; } = new(); 16 | 17 | [JsonProperty(PropertyName = "snapshots", Required = Required.Default)] 18 | public Dictionary Snapshots { get; [ExcludeFromCodeCoverage] set; } = new(); 19 | 20 | [JsonProperty(PropertyName = "orderbooks", Required = Required.Default)] 21 | public Dictionary OrderBooks { get; [ExcludeFromCodeCoverage] set; } = new(); 22 | } 23 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonLimitUpLimitDown.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(ILimitUpLimitDown))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonLimitUpLimitDown : JsonRealTimeBase, ILimitUpLimitDown 8 | { 9 | [JsonProperty(PropertyName = "u", Required = Required.Default)] 10 | public Decimal LimitUpPrice { get; set; } 11 | 12 | [JsonProperty(PropertyName = "d", Required = Required.Default)] 13 | public Decimal LimitDownPrice { get; set; } 14 | 15 | [JsonProperty(PropertyName = "i", Required = Required.Default)] 16 | public String Indicator { get; set; } = String.Empty; 17 | 18 | [JsonProperty(PropertyName = "z", Required = Required.Default)] 19 | public String Tape { get; set; } = String.Empty; 20 | 21 | [ExcludeFromCodeCoverage] 22 | public override String ToString() => 23 | JsonConvert.SerializeObject(this); 24 | 25 | [ExcludeFromCodeCoverage] 26 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 27 | private String DebuggerDisplay => 28 | $"{nameof(ILimitUpLimitDown)} {{ LimitUpPrice = {LimitUpPrice}, LimitDownPrice = {LimitDownPrice}, Tape = \"{Tape}\" }}"; 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonListenRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class JsonListenRequest 4 | { 5 | internal sealed class JsonData 6 | { 7 | [JsonProperty(PropertyName = "streams", Required = Required.Always)] 8 | public List Streams { get; set; } = []; 9 | } 10 | 11 | [JsonProperty(PropertyName = "action", Required = Required.Always)] 12 | public JsonAction Action { get; set; } 13 | 14 | [JsonProperty(PropertyName = "data", Required = Required.Default)] 15 | public JsonData? Data { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonMarketMover.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IMarketMover))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonMarketMover : IMarketMover 8 | { 9 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 10 | public String Symbol { get; set; } = String.Empty; 11 | 12 | [JsonProperty(PropertyName = "price", Required = Required.Always)] 13 | public Decimal Price { get; set; } 14 | 15 | [JsonProperty(PropertyName = "change", Required = Required.Always)] 16 | public Decimal Change { get; set; } 17 | 18 | [JsonProperty(PropertyName = "percent_change", Required = Required.Always)] 19 | public Decimal PercentChange { get; set; } 20 | 21 | [ExcludeFromCodeCoverage] 22 | public override String ToString() => 23 | JsonConvert.SerializeObject(this); 24 | 25 | [ExcludeFromCodeCoverage] 26 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 27 | private String DebuggerDisplay => 28 | $"{nameof(IMarketMover)} {{ Symbol = \"{Symbol}\", Price = {Price}, Change = {Change}, PercentChange = {PercentChange:F2}% }}"; 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonMarketMovers.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IMarketMovers))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonMarketMovers : IMarketMovers 8 | { 9 | [JsonProperty(PropertyName = "losers", Required = Required.Always)] 10 | public List LosersList { get; [ExcludeFromCodeCoverage] set; } = []; 11 | 12 | [JsonProperty(PropertyName = "gainers", Required = Required.Always)] 13 | public List GainersList { get; [ExcludeFromCodeCoverage] set; } = []; 14 | 15 | public IReadOnlyList Losers => 16 | LosersList.EmptyIfNull(); 17 | 18 | public IReadOnlyList Gainers => 19 | GainersList.EmptyIfNull(); 20 | 21 | [ExcludeFromCodeCoverage] 22 | public override String ToString() => 23 | JsonConvert.SerializeObject(this); 24 | 25 | [ExcludeFromCodeCoverage] 26 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 27 | private String DebuggerDisplay => 28 | $"{nameof(IMarketMovers)} {{ Losers.Count = {Losers.Count}, Gainers.Count = {Gainers.Count} }}"; 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonMultiAuctionsPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(IAuction) + ">")] 4 | internal sealed class JsonMultiAuctionsPage : IMultiPageMutable 5 | { 6 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 7 | [JsonProperty(PropertyName = "auctions", Required = Required.Default)] 8 | public Dictionary?> ItemsDictionary { get; [ExcludeFromCodeCoverage] set; } = new(); 9 | 10 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 11 | public String? NextPageToken { get; set; } 12 | 13 | [JsonIgnore] 14 | public IReadOnlyDictionary> Items { get; set; } = 15 | new Dictionary>(); 16 | 17 | [OnDeserialized] 18 | [UsedImplicitly] 19 | internal void OnDeserializedMethod( 20 | StreamingContext _) => 21 | Items = ItemsDictionary.SetSymbol(); 22 | 23 | [ExcludeFromCodeCoverage] 24 | public override String ToString() => 25 | JsonConvert.SerializeObject(this); 26 | 27 | [ExcludeFromCodeCoverage] 28 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 29 | private String DebuggerDisplay => 30 | this.ToDebuggerDisplayString(); 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonMultiBarsPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(IBar) + ">")] 4 | internal sealed class JsonMultiBarsPage : IMultiPageMutable 5 | { 6 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 7 | [JsonProperty(PropertyName = "bars", Required = Required.Default)] 8 | public Dictionary?> ItemsDictionary { get; [ExcludeFromCodeCoverage] set; } = new(); 9 | 10 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 11 | public String? NextPageToken { get; set; } 12 | 13 | [JsonIgnore] 14 | public IReadOnlyDictionary> Items { get; set; } = 15 | new Dictionary>(); 16 | 17 | [OnDeserialized] 18 | [UsedImplicitly] 19 | internal void OnDeserializedMethod( 20 | StreamingContext _) => 21 | Items = ItemsDictionary.SetSymbol(); 22 | 23 | [ExcludeFromCodeCoverage] 24 | public override String ToString() => 25 | JsonConvert.SerializeObject(this); 26 | 27 | [ExcludeFromCodeCoverage] 28 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 29 | private String DebuggerDisplay => 30 | this.ToDebuggerDisplayString(); 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonMultiQuotesPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(IQuote) + ">")] 4 | internal sealed class JsonMultiQuotesPage : IMultiPageMutable 5 | where TQuote : IQuote, ISymbolMutable 6 | { 7 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 8 | [JsonProperty(PropertyName = "quotes", Required = Required.Default)] 9 | public Dictionary?> ItemsDictionary { get; [ExcludeFromCodeCoverage] set; } = new(); 10 | 11 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 12 | public String? NextPageToken { get; set; } 13 | 14 | [JsonIgnore] 15 | public IReadOnlyDictionary> Items { get; set; } = 16 | new Dictionary>(); 17 | 18 | [OnDeserialized] 19 | [UsedImplicitly] 20 | internal void OnDeserializedMethod( 21 | StreamingContext _) => 22 | Items = ItemsDictionary.SetSymbol(); 23 | 24 | [ExcludeFromCodeCoverage] 25 | public override String ToString() => 26 | JsonConvert.SerializeObject(this); 27 | 28 | [ExcludeFromCodeCoverage] 29 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 30 | private String DebuggerDisplay => 31 | this.ToDebuggerDisplayString(); 32 | } 33 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonMultiTradesPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(ITrade) + ">")] 4 | internal sealed class JsonMultiTradesPage : IMultiPageMutable 5 | where TTrade : ITrade, ISymbolMutable 6 | { 7 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 8 | [JsonProperty(PropertyName = "trades", Required = Required.Default)] 9 | public Dictionary?> ItemsDictionary { get; [ExcludeFromCodeCoverage] set; } = new(); 10 | 11 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 12 | public String? NextPageToken { get; set; } 13 | 14 | [JsonIgnore] 15 | public IReadOnlyDictionary> Items { get; set; } = 16 | new Dictionary>(); 17 | 18 | [OnDeserialized] 19 | [UsedImplicitly] 20 | internal void OnDeserializedMethod( 21 | StreamingContext _) => 22 | Items = ItemsDictionary.SetSymbol(); 23 | 24 | [ExcludeFromCodeCoverage] 25 | public override String ToString() => 26 | JsonConvert.SerializeObject(this); 27 | 28 | [ExcludeFromCodeCoverage] 29 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 30 | private String DebuggerDisplay => 31 | this.ToDebuggerDisplayString(); 32 | } 33 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonNameChange.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(INameChange))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonNameChange : INameChange 8 | { 9 | [JsonProperty(PropertyName = "old_symbol", Required = Required.Always)] 10 | public String OldSymbol { get; set; } = String.Empty; 11 | 12 | [JsonProperty(PropertyName = "new_symbol", Required = Required.Always)] 13 | public String NewSymbol { get; set; } = String.Empty; 14 | 15 | [JsonConverter(typeof(DateOnlyConverter))] 16 | [JsonProperty(PropertyName = "process_date", Required = Required.Always)] 17 | public DateOnly ProcessDate { get; set; } 18 | 19 | [ExcludeFromCodeCoverage] 20 | public override String ToString() => 21 | JsonConvert.SerializeObject(this); 22 | 23 | [ExcludeFromCodeCoverage] 24 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 25 | private String DebuggerDisplay => 26 | $"{nameof(INameChange)} {{ OldSymbol = {OldSymbol}, NewSymbol = {NewSymbol} }}"; 27 | } 28 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonNewOrderAdvancedAttributes.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class JsonNewOrderAdvancedAttributes 4 | { 5 | [JsonProperty(PropertyName = "limit_price", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 6 | public Decimal? LimitPrice { get; set; } 7 | 8 | [JsonProperty(PropertyName = "stop_price", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 9 | public Decimal? StopPrice { get; set; } 10 | } 11 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonNewsPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(INewsArticle) + ">")] 7 | internal sealed class JsonNewsPage : IPage 8 | { 9 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 10 | [JsonProperty(PropertyName = "news", Required = Required.Default)] 11 | public List ItemsList { get; [ExcludeFromCodeCoverage] set; } = []; 12 | 13 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 14 | public String? NextPageToken { get; [ExcludeFromCodeCoverage] set; } 15 | 16 | [JsonIgnore] 17 | public IReadOnlyList Items => ItemsList.EmptyIfNull(); 18 | 19 | [JsonIgnore] 20 | public String Symbol => String.Empty; 21 | 22 | [ExcludeFromCodeCoverage] 23 | public override String ToString() => 24 | JsonConvert.SerializeObject(this); 25 | 26 | [ExcludeFromCodeCoverage] 27 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 28 | private String DebuggerDisplay => 29 | this.ToDebuggerDisplayString(); 30 | } 31 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonOptionContractsPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonOptionContractsPage : IPage 7 | { 8 | [JsonProperty(PropertyName = "option_contracts", Required = Required.Always)] 9 | public List Contracts { get; [ExcludeFromCodeCoverage] set; } = []; 10 | 11 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 12 | public String? NextPageToken { get; set; } 13 | 14 | [JsonIgnore] 15 | [ExcludeFromCodeCoverage] 16 | public String Symbol => String.Empty; 17 | 18 | public IReadOnlyList Items => Contracts.EmptyIfNull(); 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonOrderActionStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IOrderActionStatus))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonOrderActionStatus : IOrderActionStatus 8 | { 9 | [JsonProperty(PropertyName = "id", Required = Required.Always)] 10 | public Guid OrderId { get; set; } 11 | 12 | [JsonIgnore] 13 | public Boolean IsSuccess => StatusCode.IsSuccessHttpStatusCode(); 14 | 15 | [JsonProperty(PropertyName = "status", Required = Required.Always)] 16 | public Int64 StatusCode { get; set; } 17 | 18 | [ExcludeFromCodeCoverage] 19 | public override String ToString() => 20 | JsonConvert.SerializeObject(this); 21 | 22 | [ExcludeFromCodeCoverage] 23 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 24 | private String DebuggerDisplay => 25 | $"{nameof(IOrderActionStatus)} {{ ID = {OrderId:B}, StatusCode = {StatusCode} }}"; 26 | } 27 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonOrderBookEntry.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IOrderBookEntry))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonOrderBookEntry : IOrderBookEntry 8 | { 9 | [JsonProperty(PropertyName = "p", Required = Required.Always)] 10 | public Decimal Price { get; set; } 11 | 12 | [JsonProperty(PropertyName = "s", Required = Required.Always)] 13 | public Decimal Size { get; set; } 14 | 15 | [ExcludeFromCodeCoverage] 16 | public override String ToString() => 17 | JsonConvert.SerializeObject(this); 18 | 19 | [ExcludeFromCodeCoverage] 20 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 21 | private String DebuggerDisplay => 22 | $"{{ Price = {Price}, Size = {Size} }}"; 23 | } 24 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonOrderLeg.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal sealed class JsonOrderLeg 4 | { 5 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 6 | public String Symbol { get; set; } = String.Empty; 7 | 8 | [JsonProperty(PropertyName = "ratio_qty", Required = Required.Always)] 9 | public Decimal RatioQuantity { get; set; } 10 | 11 | [JsonProperty(PropertyName = "side", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 12 | public OrderSide? OrderSide { get; set; } 13 | 14 | [JsonProperty(PropertyName = "position_intent", Required = Required.Default, NullValueHandling = NullValueHandling.Ignore)] 15 | public PositionIntent? PositionIntent { get; set; } 16 | } 17 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonPositionActionStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPositionActionStatus))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonPositionActionStatus : IPositionActionStatus 8 | { 9 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 10 | public String Symbol { get; set; } = String.Empty; 11 | 12 | [JsonIgnore] 13 | public Boolean IsSuccess => StatusCode.IsSuccessHttpStatusCode(); 14 | 15 | [JsonProperty(PropertyName = "status", Required = Required.Always)] 16 | public Int64 StatusCode { get; set; } 17 | 18 | [ExcludeFromCodeCoverage] 19 | public override String ToString() => 20 | JsonConvert.SerializeObject(this); 21 | 22 | [ExcludeFromCodeCoverage] 23 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 24 | private String DebuggerDisplay => 25 | $"{nameof(IPositionActionStatus)} {{ Symbol = \"{Symbol}\", StatusCode = {StatusCode}, IsSuccess = {IsSuccess} }}"; 26 | } 27 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonQuotesPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(IQuote) + ">")] 4 | internal sealed class JsonQuotesPage : IPageMutable, ISymbolMutable 5 | where TQuote : IQuote, ISymbolMutable 6 | { 7 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 8 | [JsonProperty(PropertyName = "quotes", Required = Required.Default)] 9 | public List ItemsList { get; [ExcludeFromCodeCoverage] set; } = []; 10 | 11 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 12 | public String Symbol { get; set; } = String.Empty; 13 | 14 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 15 | public String? NextPageToken { get; set; } 16 | 17 | [JsonIgnore] 18 | public IReadOnlyList Items { get; set; } = new List(); 19 | 20 | public void SetSymbol(String symbol) => Symbol = symbol; 21 | 22 | [OnDeserialized] 23 | [UsedImplicitly] 24 | internal void OnDeserializedMethod( 25 | StreamingContext _) => 26 | Items = ItemsList.SetSymbol(Symbol).EmptyIfNull(); 27 | 28 | [ExcludeFromCodeCoverage] 29 | public override String ToString() => 30 | JsonConvert.SerializeObject(this); 31 | 32 | [ExcludeFromCodeCoverage] 33 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 34 | private String DebuggerDisplay => 35 | this.ToDebuggerDisplayString(); 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonRealTimeBar.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IBar))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonRealTimeBar : JsonRealTimeBase, IBar 8 | { 9 | [JsonProperty(PropertyName = "o", Required = Required.Always)] 10 | public Decimal Open { get; set; } 11 | 12 | [JsonProperty(PropertyName = "h", Required = Required.Always)] 13 | public Decimal High { get; set; } 14 | 15 | [JsonProperty(PropertyName = "l", Required = Required.Always)] 16 | public Decimal Low { get; set; } 17 | 18 | [JsonProperty(PropertyName = "c", Required = Required.Always)] 19 | public Decimal Close { get; set; } 20 | 21 | [JsonProperty(PropertyName = "v", Required = Required.Always)] 22 | public Decimal Volume { get; set; } 23 | 24 | [JsonProperty(PropertyName = "vw", Required = Required.Default)] 25 | public Decimal Vwap { get; set; } 26 | 27 | [JsonProperty(PropertyName = "n", Required = Required.Default)] 28 | public UInt64 TradeCount { get; set; } 29 | 30 | [ExcludeFromCodeCoverage] 31 | public override String ToString() => 32 | JsonConvert.SerializeObject(this); 33 | 34 | [ExcludeFromCodeCoverage] 35 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 36 | private String DebuggerDisplay => 37 | this.ToDebuggerDisplayString(); 38 | } 39 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonRealTimeBase.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal abstract class JsonRealTimeBase 4 | { 5 | [JsonProperty(PropertyName = "T", Required = Required.Always)] 6 | public String Channel { get; set; } = String.Empty; 7 | 8 | [JsonProperty(PropertyName = "S", Required = Required.Always)] 9 | public String Symbol { get; set; } = String.Empty; 10 | 11 | [JsonProperty(PropertyName = "t", Required = Required.Always)] 12 | public DateTime TimestampUtc { get; set; } 13 | 14 | [JsonIgnore] 15 | public DateTime TimeUtc => TimestampUtc; 16 | } 17 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonRedemption.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IRedemption))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonRedemption : IRedemption 8 | { 9 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 10 | public String Symbol { get; set; } = String.Empty; 11 | 12 | [JsonProperty(PropertyName = "rate", Required = Required.Always)] 13 | public Decimal Rate { get; set; } 14 | 15 | [JsonConverter(typeof(DateOnlyConverter))] 16 | [JsonProperty(PropertyName = "process_date", Required = Required.Always)] 17 | public DateOnly ProcessDate { get; set; } 18 | 19 | [JsonConverter(typeof(DateOnlyConverter))] 20 | [JsonProperty(PropertyName = "payable_date", Required = Required.Default)] 21 | public DateOnly? PayableDate { get; set; } 22 | 23 | [ExcludeFromCodeCoverage] 24 | public override String ToString() => 25 | JsonConvert.SerializeObject(this); 26 | 27 | [ExcludeFromCodeCoverage] 28 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 29 | private String DebuggerDisplay => 30 | $"{nameof(IRedemption)} {{ Symbol = {Symbol}, Rate = {Rate} }}"; 31 | } 32 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonStreamError.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [SuppressMessage( 4 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 5 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 6 | internal sealed class JsonStreamError 7 | { 8 | [JsonProperty(PropertyName = "code", Required = Required.Default)] 9 | public Int32 Code { get; set; } 10 | 11 | [JsonProperty(PropertyName = "msg", Required = Required.Default)] 12 | public String Message { get; set; } = String.Empty; 13 | } 14 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonTradesPage.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IPage) + "<" + nameof(ITrade) + ">")] 4 | internal sealed class JsonTradesPage : IPageMutable, ISymbolMutable 5 | where TTrade : ITrade, ISymbolMutable 6 | { 7 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 8 | [JsonProperty(PropertyName = "trades", Required = Required.Default)] 9 | public List ItemsList { get; [ExcludeFromCodeCoverage] set; } = []; 10 | 11 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 12 | public String Symbol { get; set; } = String.Empty; 13 | 14 | [JsonProperty(PropertyName = "next_page_token", Required = Required.Default)] 15 | public String? NextPageToken { get; set; } 16 | 17 | [JsonIgnore] 18 | public IReadOnlyList Items { get; set; } = new List(); 19 | 20 | public void SetSymbol(String symbol) => Symbol = symbol; 21 | 22 | [OnDeserialized] 23 | [UsedImplicitly] 24 | internal void OnDeserializedMethod( 25 | StreamingContext _) => 26 | Items = ItemsList.SetSymbol(Symbol).EmptyIfNull(); 27 | 28 | [ExcludeFromCodeCoverage] 29 | public override String ToString() => 30 | JsonConvert.SerializeObject(this); 31 | 32 | [ExcludeFromCodeCoverage] 33 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 34 | private String DebuggerDisplay => 35 | this.ToDebuggerDisplayString(); 36 | } 37 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonTradingStatus.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IStatus))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonTradingStatus : JsonRealTimeBase, IStatus 8 | { 9 | [JsonProperty(PropertyName = "sc", Required = Required.Default)] 10 | public String StatusCode { get; set; } = String.Empty; 11 | 12 | [JsonProperty(PropertyName = "sm", Required = Required.Default)] 13 | public String StatusMessage { get; set; } = String.Empty; 14 | 15 | [JsonProperty(PropertyName = "rc", Required = Required.Default)] 16 | public String ReasonCode { get; set; } = String.Empty; 17 | 18 | [JsonProperty(PropertyName = "rm", Required = Required.Default)] 19 | public String ReasonMessage { get; set; } = String.Empty; 20 | 21 | [JsonProperty(PropertyName = "z", Required = Required.Default)] 22 | public String Tape { get; set; } = String.Empty; 23 | 24 | [ExcludeFromCodeCoverage] 25 | public override String ToString() => 26 | JsonConvert.SerializeObject(this); 27 | 28 | [ExcludeFromCodeCoverage] 29 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 30 | private String DebuggerDisplay => 31 | $"{nameof(IStatus)} {{ Code = \"{StatusCode}\", Message = \"{StatusMessage}\", Tape= \"{Tape}\" }}"; 32 | } 33 | -------------------------------------------------------------------------------- /Alpaca.Markets/Messages/JsonWorthlessRemoval.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | [DebuggerDisplay("{DebuggerDisplay,nq}", Type = nameof(IWorthlessRemoval))] 4 | [SuppressMessage( 5 | "Microsoft.Performance", "CA1812:Avoid uninstantiated internal classes", 6 | Justification = "Object instances of this class will be created by Newtonsoft.JSON library.")] 7 | internal sealed class JsonWorthlessRemoval : IWorthlessRemoval 8 | { 9 | [JsonProperty(PropertyName = "symbol", Required = Required.Always)] 10 | public String Symbol { get; set; } = String.Empty; 11 | 12 | [JsonConverter(typeof(DateOnlyConverter))] 13 | [JsonProperty(PropertyName = "process_date", Required = Required.Always)] 14 | public DateOnly ProcessDate { get; set; } 15 | 16 | [ExcludeFromCodeCoverage] 17 | public override String ToString() => 18 | JsonConvert.SerializeObject(this); 19 | 20 | [ExcludeFromCodeCoverage] 21 | [DebuggerBrowsable(DebuggerBrowsableState.Never)] 22 | private String DebuggerDisplay => 23 | $"{nameof(IWorthlessRemoval)} {{ Symbol = {Symbol}, ProcessDate = {ProcessDate} }}"; 24 | } 25 | -------------------------------------------------------------------------------- /Alpaca.Markets/Orders/IStopLoss.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the price information about the stop loss order. 5 | /// 6 | public interface IStopLoss 7 | { 8 | /// 9 | /// Gets the stop loss stop price. 10 | /// 11 | Decimal StopPrice { get; } 12 | 13 | /// 14 | /// Gets the stop loss limit price. 15 | /// 16 | Decimal? LimitPrice { get; } 17 | } 18 | -------------------------------------------------------------------------------- /Alpaca.Markets/Orders/ITakeProfit.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates the price information about the take profit order. 5 | /// 6 | public interface ITakeProfit 7 | { 8 | /// 9 | /// Gets the profit taking limit price. 10 | /// 11 | Decimal LimitPrice { get; } 12 | } 13 | -------------------------------------------------------------------------------- /Alpaca.Markets/Orders/StopLossOrder.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates data required for placing stop loss order on the Alpaca REST API. 5 | /// 6 | public sealed class StopLossOrder : AdvancedOrderBase, IStopLoss 7 | { 8 | internal StopLossOrder( 9 | SimpleOrderBase baseOrder, 10 | Decimal stopPrice, 11 | Decimal? limitPrice) 12 | : base( 13 | baseOrder, 14 | OrderClass.OneTriggersOther) 15 | { 16 | LimitPrice = limitPrice; 17 | StopPrice = stopPrice; 18 | } 19 | 20 | /// 21 | public Decimal StopPrice { get; } 22 | 23 | /// 24 | public Decimal? LimitPrice { get; } 25 | 26 | /// 27 | /// Creates a new instance of the order from the current order. 28 | /// 29 | /// Take profit order limit price. 30 | /// New advanced order representing pair of original order and take profit order. 31 | [UsedImplicitly] 32 | public BracketOrder TakeProfit( 33 | Decimal takeProfitLimitPrice) => 34 | new(BaseOrder, takeProfitLimitPrice, StopPrice, LimitPrice); 35 | 36 | internal override JsonNewOrder GetJsonRequest() => 37 | base.GetJsonRequest() 38 | .WithStopLoss(this); 39 | } 40 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaCryptoDataClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for instance. 5 | /// 6 | public sealed class AlpacaCryptoDataClientConfiguration : AlpacaClientConfigurationBase 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaCryptoDataClientConfiguration() 12 | : base(Environments.Live.AlpacaDataApi) 13 | { 14 | } 15 | 16 | internal override Uri GetApiEndpoint() => 17 | 18 | new UriBuilder(ApiEndpoint) { Path = "v1beta3/crypto/us/" }.Uri; 19 | } 20 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaDataClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for instance. 5 | /// 6 | public sealed class AlpacaDataClientConfiguration : AlpacaClientConfigurationBase 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaDataClientConfiguration() 12 | : base(Environments.Live.AlpacaDataApi) 13 | { 14 | } 15 | 16 | internal override Uri GetApiEndpoint() => 17 | new UriBuilder(ApiEndpoint) { Path = "v2/stocks/" }.Uri; 18 | } 19 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaDataStreamingClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for instance. 5 | /// 6 | public sealed class AlpacaDataStreamingClientConfiguration : StreamingClientConfiguration 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaDataStreamingClientConfiguration() 12 | : base(Environments.Live.AlpacaDataStreamingApi) 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaNewsStreamingClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for implementation. 5 | /// 6 | public sealed class AlpacaNewsStreamingClientConfiguration : StreamingClientConfiguration 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaNewsStreamingClientConfiguration() 12 | : base(Environments.Live.AlpacaNewsStreamingApi) 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaOptionsDataClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for instance. 5 | /// 6 | public sealed class AlpacaOptionsDataClientConfiguration : AlpacaClientConfigurationBase 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaOptionsDataClientConfiguration() 12 | : base(Environments.Live.AlpacaDataApi) 13 | { 14 | } 15 | 16 | internal override Uri GetApiEndpoint() => 17 | new UriBuilder(ApiEndpoint) { Path = "v1beta1/options/" }.Uri; 18 | } 19 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaStreamingClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for instance. 5 | /// 6 | public sealed class AlpacaStreamingClientConfiguration : StreamingClientConfiguration 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaStreamingClientConfiguration() 12 | : base(Environments.Live.AlpacaStreamingApi) 13 | { 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/AlpacaTradingClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for instance. 5 | /// 6 | public sealed class AlpacaTradingClientConfiguration : AlpacaClientConfigurationBase 7 | { 8 | /// 9 | /// Creates new instance of class. 10 | /// 11 | public AlpacaTradingClientConfiguration() 12 | : base(Environments.Live.AlpacaTradingApi) 13 | { 14 | } 15 | 16 | internal override Uri GetApiEndpoint() => ApiEndpoint; 17 | } 18 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/DeleteAllPositionsRequest.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates request parameters for call. 5 | /// 6 | public sealed class DeleteAllPositionsRequest 7 | { 8 | /// 9 | /// Gets or sets the flag indicating that request should also cancel all open orders (false if null). 10 | /// 11 | [UsedImplicitly] 12 | public Boolean? CancelOrders { get; set; } 13 | 14 | /// 15 | /// Gets or sets the operation timeout. Useful in case of deleting a lot of positions. The default 16 | /// HTTP timeout equal to 100 seconds used if this property is equal to null. 17 | /// 18 | public TimeSpan? Timeout { get; [UsedImplicitly] set; } 19 | 20 | internal async ValueTask GetUriBuilderAsync( 21 | HttpClient httpClient) => 22 | new(httpClient.BaseAddress!) 23 | { 24 | Path = "v2/positions", 25 | Query = await new QueryBuilder() 26 | .AddParameter("cancel_orders", CancelOrders) 27 | .AsStringAsync().ConfigureAwait(false) 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/HistoryPeriod.cs: -------------------------------------------------------------------------------- 1 | using System.Globalization; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | /// 6 | /// Encapsulates account history period request duration - value and unit pair. 7 | /// 8 | public readonly record struct HistoryPeriod 9 | { 10 | /// 11 | /// Creates new instance of the structure. 12 | /// 13 | public HistoryPeriod() 14 | { 15 | Value = 0; 16 | Unit = HistoryPeriodUnit.Day; 17 | } 18 | 19 | /// 20 | /// Creates new instance of object. 21 | /// 22 | /// Duration value in units. 23 | /// Duration units (days, weeks, etc.) 24 | [UsedImplicitly] 25 | public HistoryPeriod( 26 | Int32 value, 27 | HistoryPeriodUnit unit) 28 | { 29 | Value = value; 30 | Unit = unit; 31 | } 32 | 33 | /// 34 | /// Gets specified duration units. 35 | /// 36 | [UsedImplicitly] 37 | public HistoryPeriodUnit Unit { get; } 38 | 39 | /// 40 | /// Gets specified duration value. 41 | /// 42 | [UsedImplicitly] 43 | public Int32 Value { get; } 44 | 45 | /// 46 | public override String ToString() => 47 | $"{Value.ToString("D", CultureInfo.InvariantCulture)}{Unit.ToEnumString()}"; 48 | } 49 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/Pagination.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates all data required for the pagination support in Alpaca Data API v2 5 | /// 6 | public sealed class Pagination 7 | { 8 | internal const UInt32 MinPageSize = 1; 9 | 10 | /// 11 | /// Gets the maximum valid page size for requests supported by Alpaca Data API v2. 12 | /// 13 | [CLSCompliant(false)] 14 | public static UInt32 MaxPageSize => 10_000; 15 | 16 | /// 17 | /// Gets the maximum valid page size for news requests supported by Alpaca Data API v2. 18 | /// 19 | internal static UInt32 MaxNewsPageSize => 50; 20 | 21 | /// 22 | /// Gets the maximum valid page size for corporate actions requests supported by Alpaca Data API v2. 23 | /// 24 | internal static UInt32 MaxCorporateActionsPageSize => 1_000; 25 | 26 | /// 27 | /// Gets and sets the request page size. If equals to null default size will be used. 28 | /// 29 | [CLSCompliant(false)] 30 | public UInt32? Size { get; set; } 31 | 32 | /// 33 | /// Gets and sets the page token for the request. Should be null for the first request. 34 | /// 35 | public String? Token { get; set; } 36 | 37 | internal QueryBuilder QueryBuilder => 38 | new QueryBuilder() 39 | .AddParameter("page_token", Token) 40 | .AddParameter("limit", Size); 41 | } 42 | -------------------------------------------------------------------------------- /Alpaca.Markets/Parameters/StreamingClientConfiguration.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Configuration parameters object for class. 5 | /// 6 | [SuppressMessage("ReSharper", "PropertyCanBeMadeInitOnly.Global")] 7 | public abstract class StreamingClientConfiguration 8 | { 9 | /// 10 | /// Creates new instance of class. 11 | /// 12 | protected internal StreamingClientConfiguration(Uri apiEndpoint) 13 | { 14 | SecurityId = new SecretKey(String.Empty, String.Empty); 15 | ApiEndpoint = apiEndpoint; 16 | } 17 | 18 | /// 19 | /// Gets or sets Alpaca streaming API base URL. 20 | /// 21 | public Uri ApiEndpoint { get; set; } 22 | 23 | /// 24 | /// Gets or sets Alpaca secret key identifier. 25 | /// 26 | public SecurityKey SecurityId { get; set; } 27 | 28 | /// 29 | /// Gets or sets factory for obtaining web socket client. 30 | /// 31 | public Func? WebSocketFactory { get; [UsedImplicitly] set; } 32 | 33 | internal virtual Uri GetApiEndpoint() => ApiEndpoint; 34 | 35 | internal void EnsureIsValid() 36 | { 37 | ApiEndpoint.EnsurePropertyNotNull(); 38 | SecurityId.EnsurePropertyNotNull(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Alpaca.Markets/PublicAPI.Unshipped.txt: -------------------------------------------------------------------------------- 1 | #nullable enable 2 | -------------------------------------------------------------------------------- /Alpaca.Markets/RateLimit/IRateLimitProvider.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Encapsulates access to the latest available rate limit information for this client. 5 | /// 6 | public interface IRateLimitProvider 7 | { 8 | /// 9 | /// Gets the latest available rate limit information or default values if no information is available. 10 | /// 11 | /// The latest rate limit data from the server or an empty object if no request was made. 12 | [UsedImplicitly] 13 | [SuppressMessage("Design", "CA1024:Use properties where appropriate", 14 | Justification = "Implementation returns the new object each time so it's better to not use property here.")] 15 | public IRateLimitValues GetRateLimitValues(); 16 | } 17 | -------------------------------------------------------------------------------- /Alpaca.Markets/RateLimit/IRateLimitValues.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | /// 4 | /// Provides information about client-specific rate limit values. 5 | /// 6 | public interface IRateLimitValues 7 | { 8 | /// 9 | /// Gets the total request-per-minute limit for the current client. 10 | /// 11 | [UsedImplicitly] 12 | Int32 Limit { get; } 13 | 14 | /// 15 | /// Get the remaining number of requests allowed in the current time interval. 16 | /// 17 | [UsedImplicitly] 18 | Int32 Remaining { get; } 19 | 20 | /// 21 | /// Gets end of the current time interval for requests limiting. 22 | /// 23 | [UsedImplicitly] 24 | DateTime ResetTimeUtc { get; } 25 | } 26 | -------------------------------------------------------------------------------- /Alpaca.Markets/RateLimit/RateLimitValues.cs: -------------------------------------------------------------------------------- 1 | namespace Alpaca.Markets; 2 | 3 | internal readonly record struct RateLimitValues( 4 | Int32 Limit, 5 | Int32 Remaining, 6 | DateTime ResetTimeUtc) 7 | : IRateLimitValues; 8 | -------------------------------------------------------------------------------- /Alpaca.Markets/WebSocket/ReceiveResult.cs: -------------------------------------------------------------------------------- 1 | using System.Net.WebSockets; 2 | 3 | namespace Alpaca.Markets; 4 | 5 | /// 6 | /// Helper struct for holding results of method calls. 7 | /// 8 | /// Web socket message type (text, binary, close). 9 | /// Is true for the last frame in message. 10 | /// Number of bytes in the last frame. 11 | [ExcludeFromCodeCoverage] 12 | public readonly record struct ReceiveResult( 13 | WebSocketMessageType MessageType, 14 | Boolean EndOfMessage, 15 | Int32 Count); 16 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to contribute 2 | 3 | ## Did you find a bug? 4 | 5 | - Ensure the bug was not already reported by searching on GitHub under [Issues](https://github.com/alpacahq/alpaca-trade-api-csharp/issues). 6 | - If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample or an executable test case demonstrating the expected behavior that is not occurring. 7 | - If possible, use the relevant bug report templates to create the issue. 8 | 9 | ## Did you write a patch that fixes a bug? 10 | 11 | - Open a new GitHub pull request with the patch. 12 | - Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable. 13 | 14 | ## Did you fix whitespace, format code, or make a purely cosmetic patch? 15 | 16 | Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability of will generally not be accepted. 17 | 18 | ## Do you intend to add a new feature or change an existing one? 19 | 20 | Suggest your change by opening the GitHub issue with the feature template and we will start a discussion about this feature design/implementation. 21 | 22 | Thanks! ❤️❤️❤️ 23 | -------------------------------------------------------------------------------- /Configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Alpaca.Markets.Extensions 7 | 8 | 9 | Alpaca.Markets 10 | 11 | 12 | 13 | Alpaca.Markets.Coverage.xml 14 | DetailedXml 15 | 16 | -------------------------------------------------------------------------------- /Documentation/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # folder # 3 | ############### 4 | /**/DROP/ 5 | /**/TEMP/ 6 | /**/packages/ 7 | /**/bin/ 8 | /**/obj/ 9 | log.txt 10 | /**/_site/ -------------------------------------------------------------------------------- /Documentation/Documentation.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | 9 | all 10 | runtime; build; native; contentfiles; analyzers; buildtransitive 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /Documentation/api/.gitignore: -------------------------------------------------------------------------------- 1 | ############### 2 | # temp file # 3 | ############### 4 | *.yml 5 | .manifest 6 | -------------------------------------------------------------------------------- /Documentation/api/index.md: -------------------------------------------------------------------------------- 1 | # PLACEHOLDER 2 | TODO: Add .NET projects to the *src* folder and run `docfx` to generate **REAL** *API Documentation*! 3 | -------------------------------------------------------------------------------- /Documentation/articles/intro.md: -------------------------------------------------------------------------------- 1 | # Add your introductions here 2 | -------------------------------------------------------------------------------- /Documentation/articles/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Introduction 2 | href: intro.md 3 | -------------------------------------------------------------------------------- /Documentation/docfx.json: -------------------------------------------------------------------------------- 1 | { 2 | "metadata": [ 3 | { 4 | "src": [ 5 | { 6 | "files": [ 7 | "**.csproj" 8 | ], 9 | "src": "../Alpaca.Markets" 10 | }, 11 | { 12 | "files": [ 13 | "**.csproj" 14 | ], 15 | "src": "../Alpaca.Markets.Extensions" 16 | } 17 | ], 18 | "dest": "api", 19 | "disableGitFeatures": false, 20 | "disableDefaultFilter": false 21 | } 22 | ], 23 | "build": { 24 | "content": [ 25 | { 26 | "files": [ 27 | "api/**.yml", 28 | "api/index.md" 29 | ] 30 | }, 31 | { 32 | "files": [ 33 | "articles/**.md", 34 | "articles/**/toc.yml", 35 | "toc.yml", 36 | "*.md" 37 | ] 38 | } 39 | ], 40 | "resource": [ 41 | { 42 | "files": [ 43 | "images/**" 44 | ] 45 | } 46 | ], 47 | "overwrite": [ 48 | { 49 | "files": [ 50 | "apidoc/**.md" 51 | ], 52 | "exclude": [ 53 | "obj/**", 54 | "_site/**" 55 | ] 56 | } 57 | ], 58 | "dest": "_site", 59 | "globalMetadataFiles": [], 60 | "fileMetadataFiles": [], 61 | "template": [ 62 | "default" 63 | ], 64 | "postProcessors": [], 65 | "markdownEngineName": "markdig", 66 | "noLangKeyword": false, 67 | "keepFileLink": false, 68 | "cleanupCacheHistory": false, 69 | "disableGitFeatures": false 70 | } 71 | } -------------------------------------------------------------------------------- /Documentation/index.md: -------------------------------------------------------------------------------- 1 | # This is the **HOMEPAGE** 2 | Refer to [Markdown](http://daringfireball.net/projects/markdown/) for how to write markdown files. 3 | ## Quick Start Notes 4 | 1. Add images to the *images* folder if the file is referencing an image. 5 | -------------------------------------------------------------------------------- /Documentation/toc.yml: -------------------------------------------------------------------------------- 1 | - name: Articles 2 | href: articles/ 3 | - name: Api Documentation 4 | href: api/ 5 | homepage: api/index.md 6 | -------------------------------------------------------------------------------- /Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alpacahq/alpaca-trade-api-csharp/7697596c24bc112180b00c8c7ab64be537fd2c88/Icon.png -------------------------------------------------------------------------------- /Portable.Helpers/CallerArgumentExpressionAttribute.cs: -------------------------------------------------------------------------------- 1 | #if !NET6_0_OR_GREATER 2 | 3 | namespace System.Runtime.CompilerServices; 4 | 5 | [AttributeUsage(AttributeTargets.Parameter)] 6 | internal sealed class CallerArgumentExpressionAttribute( 7 | String parameterName) : Attribute 8 | { 9 | [UsedImplicitly] 10 | public String ParameterName { get; } = parameterName; 11 | } 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /Portable.Helpers/GlobalSuppressions.cs: -------------------------------------------------------------------------------- 1 | // This file is used by Code Analysis to maintain SuppressMessage attributes that are applied to this project. 2 | 3 | global using System.Diagnostics.CodeAnalysis; 4 | global using System.Runtime.CompilerServices; 5 | global using JetBrains.Annotations; 6 | global using System.Diagnostics; 7 | global using System.Net.Sockets; 8 | 9 | [assembly: CLSCompliant(true)] 10 | 11 | [assembly: SuppressMessage("Globalization", 12 | "CA1303: Do not pass literals as localized parameters", 13 | Justification = "We do not plan to support localized exception messages in this SDK.")] 14 | [assembly: SuppressMessage("Design", 15 | "CA1003: Use generic event handler instances", 16 | Justification = "This SDK uses Action based events historically for performance reasons.")] 17 | -------------------------------------------------------------------------------- /Portable.Helpers/Index.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK || NETSTANDARD2_0 2 | 3 | namespace System; 4 | 5 | internal readonly struct Index : IEquatable 6 | { 7 | private readonly Int32 _value; 8 | 9 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 10 | public Index( 11 | Int32 value, Boolean fromEnd = false) => 12 | _value = fromEnd ? ~value : value; 13 | 14 | public Index(Int32 value) => _value = value; 15 | 16 | [UsedImplicitly] 17 | public Int32 Value => _value < 0 ? ~_value : _value; 18 | 19 | [UsedImplicitly] 20 | public Boolean IsFromEnd => _value < 0; 21 | 22 | [UsedImplicitly] 23 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 24 | public Int32 GetOffset(Int32 length) => 25 | IsFromEnd ? _value + length + 1 : _value; 26 | 27 | public override Boolean Equals(Object? value) => 28 | value is Index index && _value == index._value; 29 | 30 | public Boolean Equals(Index other) => 31 | _value == other._value; 32 | 33 | public override Int32 GetHashCode() => _value; 34 | 35 | public static implicit operator Index(Int32 value) => new(value); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /Portable.Helpers/KeyValuePairExtensions.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK || NETSTANDARD2_0 2 | 3 | namespace System; 4 | 5 | internal static class KeyValuePairExtensions 6 | { 7 | [UsedImplicitly] 8 | public static void Deconstruct( 9 | // ReSharper disable once UseDeconstructionOnParameter 10 | this KeyValuePair pair, 11 | out TKey key, 12 | out TValue value) 13 | { 14 | key = pair.Key; 15 | value = pair.Value; 16 | } 17 | } 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /Portable.Helpers/NullableHelper.cs: -------------------------------------------------------------------------------- 1 | namespace System; 2 | 3 | [ExcludeFromCodeCoverage] 4 | internal static class NullableHelper 5 | { 6 | [UsedImplicitly] 7 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 8 | public static T EnsureNotNull( 9 | [ValidatedNotNull] this T value, 10 | [CallerArgumentExpression("value")]String name = "") 11 | where T : class => value ?? throw new ArgumentNullException(name); 12 | 13 | [UsedImplicitly] 14 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 15 | public static void EnsurePropertyNotNull( 16 | [ValidatedNotNull] this T value, 17 | [CallerArgumentExpression("value")] String name = "") 18 | where T : class 19 | { 20 | if (value is null) 21 | { 22 | throw new InvalidOperationException($"The value of '{name}' property shouldn't be null."); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Portable.Helpers/Portable.Helpers.projitems: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildAllProjects);$(MSBuildThisFileFullPath) 5 | true 6 | b628bf16-ab9c-4a2c-b13f-3fcc491d15d7 7 | 8 | 9 | System 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /Portable.Helpers/Portable.Helpers.shproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | b628bf16-ab9c-4a2c-b13f-3fcc491d15d7 5 | 14.0 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /Portable.Helpers/Range.cs: -------------------------------------------------------------------------------- 1 | #if NETFRAMEWORK || NETSTANDARD2_0 2 | 3 | namespace System; 4 | 5 | internal readonly record struct Range( 6 | Index Start, Index End) 7 | { 8 | public override String ToString() => Start + ".." + End; 9 | 10 | [UsedImplicitly] 11 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 12 | public (Int32 Offset, Int32 Length) GetOffsetAndLength(Int32 length) 13 | { 14 | var startIndex = Start; 15 | var start = startIndex.IsFromEnd ? length - startIndex.Value : startIndex.Value; 16 | 17 | var endIndex = End; 18 | var end = endIndex.IsFromEnd ? length - endIndex.Value : endIndex.Value; 19 | 20 | if ((UInt32)end > (UInt32)length || (UInt32)start > (UInt32)end) 21 | { 22 | throw new ArgumentOutOfRangeException(nameof(length)); 23 | } 24 | 25 | return (start, end - start); 26 | } 27 | } 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /Portable.Helpers/ValidatedNotNullAttribute.cs: -------------------------------------------------------------------------------- 1 | namespace System; 2 | 3 | [ExcludeFromCodeCoverage] 4 | [AttributeUsage(AttributeTargets.Parameter)] 5 | internal sealed class ValidatedNotNullAttribute : Attribute; 6 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Supported Versions 4 | 5 | | Version | Supported | 6 | | ------- | ------------------ | 7 | | 8.x | :white_check_mark: | 8 | | 7.x | :white_check_mark: | 9 | | < 7.0.0 | :x: | 10 | -------------------------------------------------------------------------------- /UsageExamples/Program.cs: -------------------------------------------------------------------------------- 1 | try 2 | { 3 | var algorithm = new UsageExamples.MeanReversionBrokerage(); 4 | await algorithm.Run(); 5 | } 6 | catch (Exception e) 7 | { 8 | Console.Error.WriteLine(e); 9 | } 10 | 11 | Console.Read(); 12 | --------------------------------------------------------------------------------