Skip to content

Commit

Permalink
removed SSEService
Browse files Browse the repository at this point in the history
- now that all of its components have homes, have moved them all out
- added comment links to their docs
- changed StockQuoteSSEInterval to use Description instead of switch
- DRY SubscribeStockQuotesUS()
- pluralized CashFlowsResponse as it contains multiple CashFlow objects
- renamed all pk to publishableToken and sk to secretToken
- reordered all publishableToken/secretToken so publishableToken comes first (for consistency)
  • Loading branch information
vslee committed May 8, 2020
1 parent e77e3c0 commit 3fbb9e9
Show file tree
Hide file tree
Showing 57 changed files with 227 additions and 265 deletions.
3 changes: 2 additions & 1 deletion IEXSharp/Helper/ExecutorREST.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ internal class ExecutorREST : ExecutorBase
private readonly bool sign;
private readonly JsonSerializerSettings jsonSerializerSettings;

public ExecutorREST(HttpClient client, string secretToken, string publishableToken, bool sign) : base(publishableToken, secretToken)
public ExecutorREST(HttpClient client, string publishableToken, string secretToken, bool sign)
: base(publishableToken: publishableToken, secretToken: secretToken)
{
this.client = client;
if (sign)
Expand Down
15 changes: 11 additions & 4 deletions IEXSharp/Helper/ExecutorSSE.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace IEXSharp.Helper
internal class ExecutorSSE : ExecutorBase
{
readonly string baseSSEURL;
public ExecutorSSE(string baseSSEURL, string sk, string pk) : base(publishableToken: pk, sk)
public ExecutorSSE(string baseSSEURL, string publishableToken, string secretToken)
: base(publishableToken: publishableToken, secretToken: secretToken)
{
this.baseSSEURL = baseSSEURL;
}
Expand All @@ -20,14 +21,20 @@ public SSEClient<T> SubscribeToSSE<T>(string urlPattern, NameValueCollection pat
return new SSEClient<T>(Configuration.Builder(new Uri(url)).Build());
}

public SSEClient<T> SymbolsSubscribeSSE<T>(string urlPattern, IEnumerable<string> symbols, string token)
public SSEClient<T> SymbolsSubscribeSSE<T>(string urlPattern, IEnumerable<string> symbols, bool forceUseSecretToken = false)
where T : class
{
var qsb = new QueryStringBuilder();
if (!string.IsNullOrEmpty(token))
if (!string.IsNullOrEmpty(publishableToken) && !forceUseSecretToken)
{
qsb.Add("token", token);
qsb.Add("token", publishableToken);
}

if (!string.IsNullOrEmpty(secretToken) && forceUseSecretToken)
{
qsb.Add("token", secretToken);
}

qsb.Add("symbols", string.Join(",", symbols));

var pathNvc = new NameValueCollection();
Expand Down
44 changes: 19 additions & 25 deletions IEXSharp/IEXCloudClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
using IEXSharp.Service.Cloud.Options;
using IEXSharp.Service.Cloud.ReferenceData;
using IEXSharp.Service.Cloud.SocialSentiment;
using IEXSharp.Service.Cloud.SSE;
using IEXSharp.Service.Cloud.StockFundamentals;
using IEXSharp.Service.Cloud.StockPrices;
using IEXSharp.Service.Cloud.StockProfiles;
Expand Down Expand Up @@ -44,7 +43,6 @@ public class IEXCloudClient : IDisposable
private IStockFundamentalsService stockFundamentalsService;
private IStockResearchService stockResearchService;
private IBatchService batchService;
private ISSEService sseService;
private ICryptoService cryptoService;
private IReferenceDataService referenceDataService;
private IForexCurrenciesService forexCurrenciesService;
Expand All @@ -61,72 +59,68 @@ public class IEXCloudClient : IDisposable
private ICommoditiesService commoditiesService;

public IAccountService Account => accountService ?? (accountService =
new AccountService(client, secretToken, publishableToken, signRequest));
new AccountService(client, publishableToken, secretToken, signRequest));

public IStockPricesService StockPrices => stockPricesService ?? (stockPricesService =
new StockPricesService(client, secretToken, publishableToken, signRequest));
new StockPricesService(client, baseSSEURL, publishableToken, secretToken, signRequest));

public IStockProfilesService StockProfiles => stockProfilesService ?? (stockProfilesService =
new StockProfilesService(client, secretToken, publishableToken, signRequest));
new StockProfilesService(client, publishableToken, secretToken, signRequest));

public IStockFundamentalsService StockFundamentals => stockFundamentalsService ?? (stockFundamentalsService =
new StockFundamentalsService(client, secretToken, publishableToken, signRequest));
new StockFundamentalsService(client, publishableToken, secretToken, signRequest));

public IStockResearchService StockResearch => stockResearchService ?? (stockResearchService =
new StockResearchService(client, secretToken, publishableToken, signRequest));
new StockResearchService(client, publishableToken, secretToken, signRequest));

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#batch-requests"/>
/// Currently only available for /stock endpoints
/// </summary>
public IBatchService Batch => batchService ?? (batchService =
new BatchService(client, secretToken, publishableToken, signRequest));

/// <summary> SSE streaming service </summary>
public ISSEService SSE => sseService ?? (sseService =
new SSEService(baseSSEURL: baseSSEURL, sk: secretToken, pk: publishableToken));
new BatchService(client, publishableToken, secretToken, signRequest));

public ICryptoService Crypto => cryptoService ??
(cryptoService = new CryptoService(client, secretToken, publishableToken, signRequest));
(cryptoService = new CryptoService(client, baseSSEURL, publishableToken, secretToken, signRequest));

public IReferenceDataService ReferenceData => referenceDataService ??
(referenceDataService = new ReferenceDataService(client, secretToken, publishableToken, signRequest));
(referenceDataService = new ReferenceDataService(client, publishableToken, secretToken, signRequest));

public IForexCurrenciesService ForexCurrencies => forexCurrenciesService ??
(forexCurrenciesService = new ForexCurrenciesService(client, secretToken, publishableToken, signRequest));
(forexCurrenciesService = new ForexCurrenciesService(client, publishableToken, secretToken, signRequest));

public IInvestorsExchangeDataService InvestorsExchangeData =>
investorsExchangeDataService ?? (investorsExchangeDataService = new InvestorsExchangeDataService(client, secretToken, publishableToken, signRequest));
investorsExchangeDataService ?? (investorsExchangeDataService = new InvestorsExchangeDataService(client, publishableToken, secretToken, signRequest));

public IAPISystemMetadataService ApiSystemMetadata => apiSystemMetadataService
?? (apiSystemMetadataService = new APISystemMetadata(client, secretToken, publishableToken, signRequest));
?? (apiSystemMetadataService = new APISystemMetadata(client, publishableToken, secretToken, signRequest));

public ICorporateActionsService CorporateActions => corporateActionsService
?? (corporateActionsService = new CorporateActionsService(client, secretToken, publishableToken, signRequest));
?? (corporateActionsService = new CorporateActionsService(client, publishableToken, secretToken, signRequest));

public IMarketInfoService MarketInfoService => marketInfoService
?? (marketInfoService = new MarketInfoService(client, secretToken, publishableToken, signRequest));
?? (marketInfoService = new MarketInfoService(client, publishableToken, secretToken, signRequest));

public IOptionsService Options => optionsService
?? (optionsService = new OptionsService(client, secretToken, publishableToken, signRequest));

public ICeoCompensationService CeoCompensation => ceoCompensationService
?? (ceoCompensationService = new CeoCompensationService(client, secretToken, publishableToken, signRequest));
?? (ceoCompensationService = new CeoCompensationService(client, publishableToken, secretToken, signRequest));

public ISocialSentimentService SocialSentiment => socialSentimentService
?? (socialSentimentService = new SocialSentimentService(client, baseSSEURL, secretToken, publishableToken, signRequest));
?? (socialSentimentService = new SocialSentimentService(client, baseSSEURL, publishableToken, secretToken, signRequest));

public ITreasuriesService Treasuries => treasuriesService
?? (treasuriesService = new TreasuriesService(client, secretToken, publishableToken, signRequest));
?? (treasuriesService = new TreasuriesService(client, publishableToken, secretToken, signRequest));

public INewsService News => newsService
?? (newsService = new NewsService(client, baseSSEURL, secretToken, publishableToken, signRequest));
?? (newsService = new NewsService(client, baseSSEURL, publishableToken, secretToken, signRequest));

public IEconomicDataService EconomicData => economicDataService
?? (economicDataService = new EconomicDataService(client, secretToken, publishableToken, signRequest));
?? (economicDataService = new EconomicDataService(client, publishableToken, secretToken, signRequest));

public ICommoditiesService Commodities => commoditiesService
?? (commoditiesService = new CommoditiesService(client, secretToken, publishableToken, signRequest));
?? (commoditiesService = new CommoditiesService(client, publishableToken, secretToken, signRequest));

/// <summary>
/// create a new IEXCloudClient
Expand Down
1 change: 1 addition & 0 deletions IEXSharp/IEXSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<Folder Include="Model\Shared\Request\" />
<Folder Include="Model\StockProfiles\Request\" />
<Folder Include="Model\StockResearch\Request\" />
<Folder Include="Model\Stock\Request\" />
<Folder Include="Service\Cloud\SocialSentiment\" />
<Folder Include="Service\Cloud\CeoCompensation\" />
<Folder Include="Service\Cloud\Treasuries\" />
Expand Down
2 changes: 1 addition & 1 deletion IEXSharp/Model/Batch/Response/BatchResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class BatchResponse
public BookResponse Book { get; set; }

[JsonProperty("cash-flow")]
public CashFlowResponse CashFlows { get; set; }
public CashFlowsResponse CashFlows { get; set; }

public List<Chart> Chart { get; set; }
public CompanyResponse Company { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace IEXSharp.Model.Shared.Response
namespace IEXSharp.Model.Crypto.Response
{
public class EventCrypto
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace IEXSharp.Model.StockFundamentals.Response
{
public class CashFlowResponse
public class CashFlowsResponse
{
public string symbol { get; set; }
public List<Cashflow> cashflow { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
namespace IEXSharp.Model.Stock.Request
using System.ComponentModel;

namespace IEXSharp.Model.StockPrices.Request
{
public enum StockQuoteSSEInterval
{
/// <summary>
/// Firehose can be about 100 million messages per day
/// </summary>
[Description("")] // no suffix needed for firehose
Firehose,
/// <summary>
/// Can be up to 54,000 messages per symbol per day
/// </summary>
[Description("1Second")]
OneSecond,
/// <summary>
/// Can be up to 10,800 messages per symbol per day
/// </summary>
[Description("5Second")]
FiveSeconds,
/// <summary>
/// Can be up to 900 messages per symbol per day
/// </summary>
[Description("1Minute")]
OneMinute,
}
}
4 changes: 2 additions & 2 deletions IEXSharp/Service/Cloud/APISystemMetadata/APISystemMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ internal class APISystemMetadata : IAPISystemMetadataService
{
private readonly ExecutorREST _executor;

public APISystemMetadata(HttpClient client, string sk, string pk, bool sign)
public APISystemMetadata(HttpClient client, string publishableToken, string secretToken, bool sign)
{
_executor = new ExecutorREST(client, sk, pk, sign);
_executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<StatusResponse>> StatusAsync() =>
Expand Down
4 changes: 2 additions & 2 deletions IEXSharp/Service/Cloud/Account/AccountService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ internal class AccountService : IAccountService
{
private readonly ExecutorREST _executor;

public AccountService(HttpClient client, string sk, string pk, bool sign)
public AccountService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
_executor = new ExecutorREST(client, sk, pk, sign);
_executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<MetadataResponse>> MetadataAsync()
Expand Down
4 changes: 2 additions & 2 deletions IEXSharp/Service/Cloud/Batch/BatchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ internal class BatchService : IBatchService
{
private readonly ExecutorREST executor;

public BatchService(HttpClient client, string sk, string pk, bool sign)
public BatchService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<BatchResponse>>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ public class CeoCompensationService : ICeoCompensationService
{
private readonly ExecutorREST executor;

public CeoCompensationService(HttpClient client, string sk, string pk, bool sign)
public CeoCompensationService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<CeoCompensationResponse>> CeoCompensationAsync(string symbol) =>
Expand Down
4 changes: 2 additions & 2 deletions IEXSharp/Service/Cloud/Commodities/CommoditiesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class CommoditiesService : ICommoditiesService
{
private readonly ExecutorREST executor;

public CommoditiesService(HttpClient client, string sk, string pk, bool sign)
public CommoditiesService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<decimal>> DataPointAsync(CommoditySymbol symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public class CorporateActionsService : ICorporateActionsService
{
private ExecutorREST executor;

public CorporateActionsService(HttpClient client, string sk, string pk, bool sign)
public CorporateActionsService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<IEnumerable<BonusIssueResponse>>> BonusIssueAsync(
Expand Down
13 changes: 11 additions & 2 deletions IEXSharp/Service/Cloud/Crypto/CryptoService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@
using System.Threading.Tasks;
using IEXSharp.Model;
using IEXSharp.Model.Crypto.Response;
using System.Collections.Generic;

namespace IEXSharp.Service.Cloud.Crypto
{
internal class CryptoService : ICryptoService
{
private readonly ExecutorREST executor;
private readonly ExecutorSSE executorSSE;

public CryptoService(HttpClient client, string sk, string pk, bool sign)
public CryptoService(HttpClient client, string baseSSEURL, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
executorSSE = new ExecutorSSE(baseSSEURL, publishableToken: publishableToken, secretToken: secretToken);
}

public async Task<IEXResponse<CryptoBookResponse>> BookAsync(string symbol) =>
Expand All @@ -23,5 +26,11 @@ public async Task<IEXResponse<CryptoPriceResponse>> PriceAsync(string symbol) =>

public async Task<IEXResponse<QuoteCryptoResponse>> QuoteAsync(string symbol) =>
await executor.SymbolExecuteAsync<QuoteCryptoResponse>("crypto/[symbol]/quote", symbol);

public SSEClient<EventCrypto> SubscribeCryptoEvents(IEnumerable<string> symbols) =>
executorSSE.SymbolsSubscribeSSE<EventCrypto>("cryptoEvents", symbols);

public SSEClient<QuoteCryptoResponse> SubscribeCryptoQuotes(IEnumerable<string> symbols) =>
executorSSE.SymbolsSubscribeSSE<QuoteCryptoResponse>("cryptoQuotes", symbols);
}
}
17 changes: 17 additions & 0 deletions IEXSharp/Service/Cloud/Crypto/ICryptoService.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using IEXSharp.Model;
using System.Threading.Tasks;
using IEXSharp.Model.Crypto.Response;
using IEXSharp.Helper;
using System.Collections.Generic;

namespace IEXSharp.Service.Cloud.Crypto
{
Expand All @@ -12,6 +14,14 @@ public interface ICryptoService
/// <returns></returns>
Task<IEXResponse<CryptoBookResponse>> BookAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#cryptocurrency-events"/>
/// Only accessible with SSE Streaming.
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
SSEClient<EventCrypto> SubscribeCryptoEvents(IEnumerable<string> symbols);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#cryptocurrency-price"/>
/// </summary>
Expand All @@ -25,5 +35,12 @@ public interface ICryptoService
/// <param name="symbol"></param>
/// <returns></returns>
Task<IEXResponse<QuoteCryptoResponse>> QuoteAsync(string symbol);

/// <summary>
/// <see cref="https://iexcloud.io/docs/api/#cryptocurrency-quote"/>
/// </summary>
/// <param name="symbol"></param>
/// <returns></returns>
SSEClient<QuoteCryptoResponse> SubscribeCryptoQuotes(IEnumerable<string> symbols);
}
}
4 changes: 2 additions & 2 deletions IEXSharp/Service/Cloud/EconomicData/EconomicDataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class EconomicDataService : IEconomicDataService
{
private readonly ExecutorREST executor;

public EconomicDataService(HttpClient client, string sk, string pk, bool sign)
public EconomicDataService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<decimal>> DataPointAsync(EconomicDataSymbol symbol)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ internal class ForexCurrenciesService : IForexCurrenciesService
{
private readonly ExecutorREST executor;

public ForexCurrenciesService(HttpClient client, string sk, string pk, bool sign)
public ForexCurrenciesService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<IEnumerable<CurrencyRateResponse>>> LatestRatesAsync(string symbols)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ internal class InvestorsExchangeDataService : IInvestorsExchangeDataService
{
private readonly ExecutorREST executor;

public InvestorsExchangeDataService(HttpClient client, string sk, string pk, bool sign)
public InvestorsExchangeDataService(HttpClient client, string publishableToken, string secretToken, bool sign)
{
executor = new ExecutorREST(client, sk, pk, sign);
executor = new ExecutorREST(client, publishableToken, secretToken, sign);
}

public async Task<IEXResponse<DeepResponse>> DeepAsync(IEnumerable<string> symbols)
Expand Down
Loading

0 comments on commit 3fbb9e9

Please sign in to comment.