From 6b0fed23603d9287f1b5087d8a295adb0df46cb8 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Fri, 6 Oct 2017 17:11:28 +0200 Subject: [PATCH] Add constants for ticker symbols Closes #28 --- Bitstamp/BitstampClient.cs | 16 +++++++++++++--- Bitstamp/BtcEurExchange.cs | 2 +- SmartTrade/BtcEurTradeService.cs | 4 +++- SmartTrade/MainActivity.cs | 7 +++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/Bitstamp/BitstampClient.cs b/Bitstamp/BitstampClient.cs index cc45bf6..dd7fef7 100644 --- a/Bitstamp/BitstampClient.cs +++ b/Bitstamp/BitstampClient.cs @@ -24,11 +24,21 @@ namespace Bitstamp /// Represents a client for the Bitstamp API. public sealed partial class BitstampClient : IDisposable { + /// Gets the BTC/EUR ticker symbol. + public static string BtcEurSymbol => "BTC/EUR"; + + /// Gets the ticker symbol for BTC/EUR. + public static IReadOnlyList TickerSymbols { get; } = new[] { BtcEurSymbol }; + /// Initializes a new instance of the class. /// An instance initialized with this constructor can be used to access the public API only. public BitstampClient() { - this.BtcEur = new BtcEurExchange(this); + this.Exchanges = + new Dictionary() + { + { BtcEurSymbol, new BtcEurExchange(this) } + }; } /// Initializes a new instance of the class. @@ -57,8 +67,8 @@ public BitstampClient(int customerId, string apiKey, string apiSecret) this.sha256 = new HMACSHA256(Encoding.ASCII.GetBytes(apiSecret)); } - /// Gets the exchange for BTCEUR. - public ICurrencyExchange BtcEur { get; } + /// Gets the supported currency exchanges. + public IReadOnlyDictionary Exchanges { get; } /// Releases all resources used by the . [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Dispose must never throw.")] diff --git a/Bitstamp/BtcEurExchange.cs b/Bitstamp/BtcEurExchange.cs index 25ca76c..01e4041 100644 --- a/Bitstamp/BtcEurExchange.cs +++ b/Bitstamp/BtcEurExchange.cs @@ -14,7 +14,7 @@ public sealed partial class BitstampClient private sealed class BtcEurExchange : CurrencyExchange { internal BtcEurExchange(BitstampClient client) - : base(client, "BTC/EUR") + : base(client, BtcEurSymbol) { } diff --git a/SmartTrade/BtcEurTradeService.cs b/SmartTrade/BtcEurTradeService.cs index 540cda8..b574ff6 100644 --- a/SmartTrade/BtcEurTradeService.cs +++ b/SmartTrade/BtcEurTradeService.cs @@ -7,12 +7,14 @@ namespace SmartTrade { using Android.App; + using Bitstamp; [Service] internal sealed class BtcEurTradeService : TradeService { public BtcEurTradeService() - : base(new ExchangeClient(new Settings("BTC/EUR"), c => c.BtcEur)) + : base(new ExchangeClient( + new Settings(BitstampClient.BtcEurSymbol), c => c.Exchanges[BitstampClient.BtcEurSymbol])) { } } diff --git a/SmartTrade/MainActivity.cs b/SmartTrade/MainActivity.cs index 00a7bb6..52d9f61 100644 --- a/SmartTrade/MainActivity.cs +++ b/SmartTrade/MainActivity.cs @@ -6,12 +6,15 @@ namespace SmartTrade { + using System.Linq; + using Android.App; using Android.Content; using Android.Content.PM; using Android.OS; using Android.Views; using Android.Widget; + using Bitstamp; [Activity(Label = "@string/AppName", MainLauncher = true, Icon = "@mipmap/icon", ScreenOrientation = ScreenOrientation.Portrait)] internal sealed class MainActivity : ActivityBase, AdapterView.IOnItemClickListener @@ -30,8 +33,8 @@ protected sealed override void OnCreate(Bundle savedInstanceState) this.SetContentView(Resource.Layout.Main); this.tickersListView = this.FindViewById(Resource.Id.TickersListView); - this.tickersListView.Adapter = - new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, new[] { "BTC/EUR" }); + this.tickersListView.Adapter = new ArrayAdapter( + this, Android.Resource.Layout.SimpleListItem1, BitstampClient.TickerSymbols.ToArray()); this.tickersListView.OnItemClickListener = this; }