Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
Rename to TickerSymbol and CurrencyPair as appropriate
Browse files Browse the repository at this point in the history
TickerSymbol now always refers to all uppercase with slash while CurrencyPair is all lowercase without slash.

References #28
  • Loading branch information
andreashuber69 committed Oct 6, 2017
1 parent 220edb9 commit 2ed5096
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 35 deletions.
24 changes: 12 additions & 12 deletions Bitstamp/BitstampClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,36 +87,36 @@ internal async Task<IReadOnlyList<Transaction>> GetTransactionsAsync(int offset,
return await this.ExecutePostAsync("/api/v2/user_transactions/", args, d => new TransactionCollection(d));
}

internal Task<Ticker> GetTickerAsync(string tickerSymbol) =>
this.ExecuteGetAsync(Invariant($"/api/v2/ticker/{tickerSymbol}/"), d => new Ticker(d));
internal Task<Ticker> GetTickerAsync(string currencyPair) =>
this.ExecuteGetAsync(Invariant($"/api/v2/ticker/{currencyPair}/"), d => new Ticker(d));

[SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate", Justification = "Long-running operation.")]
internal Task<OrderBook> GetOrderBookAsync(string tickerSymbol) =>
this.ExecuteGetAsync(Invariant($"/api/v2/order_book/{tickerSymbol}/"), d => new OrderBook(d));
internal Task<OrderBook> GetOrderBookAsync(string currencyPair) =>
this.ExecuteGetAsync(Invariant($"/api/v2/order_book/{currencyPair}/"), d => new OrderBook(d));

internal Task<PrivateOrder> CreateBuyOrderAsync(string currencyPair, decimal amount, decimal price) =>
this.CreateBuyOrderAsync(currencyPair, amount, price, null);

internal Task<PrivateOrder> CreateBuyOrderAsync(
string tickerSymbol, decimal amount, decimal price, decimal? limitPrice)
string currencyPair, decimal amount, decimal price, decimal? limitPrice)
{
return this.CreateOrderAsync("buy", tickerSymbol, amount, price, limitPrice);
return this.CreateOrderAsync("buy", currencyPair, amount, price, limitPrice);
}

internal Task<PrivateOrder> CreateBuyOrderAsync(string tickerSymbol, decimal amount) =>
this.CreateOrderAsync("buy", tickerSymbol, amount);
internal Task<PrivateOrder> CreateBuyOrderAsync(string currencyPair, decimal amount) =>
this.CreateOrderAsync("buy", currencyPair, amount);

internal Task<PrivateOrder> CreateSellOrderAsync(string currencyPair, decimal amount, decimal price) =>
this.CreateSellOrderAsync(currencyPair, amount, price, null);

internal Task<PrivateOrder> CreateSellOrderAsync(
string tickerSymbol, decimal amount, decimal price, decimal? limitPrice)
string currencyPair, decimal amount, decimal price, decimal? limitPrice)
{
return this.CreateOrderAsync("sell", tickerSymbol, amount, price, limitPrice);
return this.CreateOrderAsync("sell", currencyPair, amount, price, limitPrice);
}

internal Task<PrivateOrder> CreateSellOrderAsync(string tickerSymbol, decimal amount) =>
this.CreateOrderAsync("sell", tickerSymbol, amount);
internal Task<PrivateOrder> CreateSellOrderAsync(string currencyPair, decimal amount) =>
this.CreateOrderAsync("sell", currencyPair, amount);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down
2 changes: 1 addition & 1 deletion Bitstamp/BtcEurExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed partial class BitstampClient
private sealed class BtcEurExchange : CurrencyExchange
{
internal BtcEurExchange(BitstampClient client)
: base(client, "btceur")
: base(client, "BTC/EUR")
{
}

Expand Down
31 changes: 17 additions & 14 deletions Bitstamp/CurrencyExchange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed partial class BitstampClient
{
internal abstract class CurrencyExchange : ICurrencyExchange
{
public string TickerSymbol => this.tickerSymbol.ToUpperInvariant();
public string TickerSymbol { get; }

public async Task<IBalance> GetBalanceAsync() => this.CreateBalance(await this.client.GetBalanceAsync());

Expand All @@ -25,38 +25,41 @@ public async Task<IEnumerable<ITransaction>> GetTransactionsAsync(int offset, in
return transactions.Select(t => this.CreateTransaction(t)).Where(t => t != null);
}

public Task<Ticker> GetTickerAsync() => this.client.GetTickerAsync(this.tickerSymbol);
public Task<Ticker> GetTickerAsync() => this.client.GetTickerAsync(this.CurrencyPair);

public Task<OrderBook> GetOrderBookAsync() => this.client.GetOrderBookAsync(this.tickerSymbol);
public Task<OrderBook> GetOrderBookAsync() => this.client.GetOrderBookAsync(this.CurrencyPair);

public Task<PrivateOrder> CreateBuyOrderAsync(decimal amount) =>
this.client.CreateBuyOrderAsync(this.tickerSymbol, amount);
this.client.CreateBuyOrderAsync(this.CurrencyPair, amount);

public Task<PrivateOrder> CreateBuyOrderAsync(decimal amount, decimal price) =>
this.client.CreateBuyOrderAsync(this.tickerSymbol, amount, price);
this.client.CreateBuyOrderAsync(this.CurrencyPair, amount, price);

public Task<PrivateOrder> CreateSellOrderAsync(decimal amount) =>
this.client.CreateSellOrderAsync(this.tickerSymbol, amount);
this.client.CreateSellOrderAsync(this.CurrencyPair, amount);

public Task<PrivateOrder> CreateSellOrderAsync(decimal amount, decimal price) =>
this.client.CreateSellOrderAsync(this.tickerSymbol, amount, price);
this.client.CreateSellOrderAsync(this.CurrencyPair, amount, price);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

internal CurrencyExchange(BitstampClient client, string tickerSymbol)
{
this.client = client;
this.tickerSymbol = tickerSymbol;
}

internal abstract IBalance CreateBalance(Balance balance);

internal abstract ITransaction CreateTransaction(Transaction transaction);

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

protected CurrencyExchange(BitstampClient client, string tickerSymbol)
{
this.client = client;
this.TickerSymbol = tickerSymbol;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

private readonly BitstampClient client;
private readonly string tickerSymbol;

private string CurrencyPair => this.TickerSymbol.Replace("/", string.Empty).ToLowerInvariant();
}
}
}
2 changes: 1 addition & 1 deletion SmartTrade/BtcEurTradeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SmartTrade
internal sealed class BtcEurTradeService : TradeService
{
public BtcEurTradeService()
: base(new ExchangeClient(new Settings("BtcEur"), c => c.BtcEur))
: base(new ExchangeClient(new Settings("BTC/EUR"), c => c.BtcEur))
{
}
}
Expand Down
2 changes: 1 addition & 1 deletion SmartTrade/ISettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SmartTrade
internal interface ISettings : INotifyPropertyChanged, IDisposable
{
/// <summary>Gets the ticker symbol of the currency pair associated with the settings.</summary>
string Ticker { get; }
string TickerSymbol { get; }

/// <summary>Gets the first currency symbol.</summary>
string FirstCurrency { get; }
Expand Down
16 changes: 11 additions & 5 deletions SmartTrade/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ internal sealed class Settings : Java.Lang.Object, ISettings, ISharedPreferences
{
public event PropertyChangedEventHandler PropertyChanged;

public string Ticker => this.FirstCurrency + "/" + this.SecondCurrency;
public string TickerSymbol { get; }

public string FirstCurrency => this.groupName.Substring(0, 3).ToUpperInvariant();
public string FirstCurrency => this.TickerSymbol.Substring(0, this.TickerSymbol.IndexOf('/'));

public string SecondCurrency => this.groupName.Substring(3).ToUpperInvariant();
public string SecondCurrency => this.TickerSymbol.Substring(this.TickerSymbol.IndexOf('/') + 1);

public int CustomerId
{
Expand Down Expand Up @@ -162,9 +162,12 @@ public void OnSharedPreferenceChanged(ISharedPreferences sharedPreferences, stri

////////////////////////////////////////////////////////////////////////////////////////////////////////////////

internal Settings(string groupName)
internal Settings(string tickerSymbol)
{
this.groupName = groupName;
this.TickerSymbol = tickerSymbol;
var slashPosition = tickerSymbol.IndexOf('/');
this.groupName = CamelCase(tickerSymbol.Substring(0, slashPosition)) +
CamelCase(tickerSymbol.Substring(slashPosition + 1));
this.preferences = PreferenceManager.GetDefaultSharedPreferences(Application.Context);
this.preferences.RegisterOnSharedPreferenceChangeListener(this);
this.keyStore = KeyStore.GetInstance(KeyStoreName);
Expand All @@ -185,6 +188,9 @@ protected sealed override void Dispose(bool disposing)
private const string KeyStoreName = "AndroidKeyStore";
private const string KeyName = "BitstampApiCredentials";

private static string CamelCase(string str) =>
char.ToUpperInvariant(str[0]) + str.Substring(1).ToLowerInvariant();

private static void GenerateKey()
{
var keyGenerator = KeyPairGenerator.GetInstance(KeyProperties.KeyAlgorithmRsa, KeyStoreName);
Expand Down
2 changes: 1 addition & 1 deletion SmartTrade/StatusActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ protected sealed override void OnCreate(Bundle savedInstanceState)
base.OnCreate(savedInstanceState);
this.SetContentView(Resource.Layout.Status);
this.Title = string.Format(
InvariantCulture, this.GetString(Resource.String.StatusTitle), this.service.Settings.Ticker);
InvariantCulture, this.GetString(Resource.String.StatusTitle), this.service.Settings.TickerSymbol);

this.settingsButton = this.GetSettingsButton();
this.enableDisableServiceButton = this.GetEnableDisableServiceButton();
Expand Down

0 comments on commit 2ed5096

Please sign in to comment.