public OandaRestClient(OandaServers server, SecureString token) { switch (server) { case OandaServers.Sandbox: if (token != null) { throw new ArgumentException("token"); } _restUrl = "http://api-sandbox.oanda.com"; break; case OandaServers.Practice: if (token == null) { throw new ArgumentNullException(nameof(token)); } _restUrl = "https://api-fxpractice.oanda.com"; break; case OandaServers.Real: if (token == null) { throw new ArgumentNullException(nameof(token)); } _restUrl = "https://api-fxtrade.oanda.com"; break; default: throw new ArgumentOutOfRangeException(nameof(server)); } _token = token; }
public OandaStreamingClient(OandaServers server, SecureString token, Func <string, int> getAccountId) { if (getAccountId == null) { throw new ArgumentNullException(nameof(getAccountId)); } switch (server) { case OandaServers.Sandbox: if (token != null) { throw new ArgumentException("token"); } _streamingUrl = "http://stream-sandbox.oanda.com"; break; case OandaServers.Practice: if (token == null) { throw new ArgumentNullException(nameof(token)); } _streamingUrl = "https://stream-fxpractice.oanda.com"; break; case OandaServers.Real: if (token == null) { throw new ArgumentNullException(nameof(token)); } _streamingUrl = "https://stream-fxtrade.oanda.com"; break; default: throw new ArgumentOutOfRangeException(nameof(server)); } _token = token; _pricesWorker = new StreamingWorker <string, StreamingPriceResponse>(this, "prices", (qs, instruments) => qs .Append("accountId", getAccountId(null)) .Append("instruments", instruments.Join(",")), price => { if (price.Tick == null) { return; } NewPrice.SafeInvoke(price.Tick); }); _eventsWorker = new StreamingWorker <int, StreamingEventResponse>(this, "events", (qs, accounts) => qs.Append("accountIds", accounts.Select(a => a.To <string>()).Join(",")), price => { if (price.Transaction == null) { return; } NewTransaction.SafeInvoke(price.Transaction); }); }