public Bitstamp(IObjectSpace space, string apiKey) { this.Space = space; this.APIKey = apiKey; CurrentExchange = space.FindObject <Exchange>(new BinaryOperator("Name", "BitStamp")); bitstampClient = new BitstampClient(); }
private Bitstamp(string apikey, string apisecret, string clientId, Tools.Logging.ILogFactory factory) { ApiKey = apikey; ApiSecret = apisecret; var auth = new RequestAuthenticator(ApiKey, ApiSecret, clientId); m_api = new BitstampClient(auth, factory); m_instance = this; }
public static void Main(string[] args) { var bitstamp = new BitstampClient(); bitstamp.TradeOccured += (s, t) => Console.WriteLine(t); bitstamp.ConnectAsync().Wait(); Console.ReadLine(); }
public MainWindow() { // Set icon from the assembly Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location).ToImageSource(); InitializeComponent(); BitstampClient = new BitstampClient(); LoadMarketSummaryAsync(); }
public MainWindow() { // Set icon from the assembly Icon = System.Drawing.Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location).ToImageSource(); InitializeComponent(); BitstampClient = new BitstampClient(); LoadMarketSummaryAsync(); }
public DataClient() { Binance = new BinanceClient(); Bitfinex = new BitfinexClient(); Poloniex = new PoloniexClient(); Bitstamp = new BitstampClient(); Gdax = new GdaxClient(); Gemini = new GeminiClient(); Kraken = new KrakenClient(); Okex = new OkexClient(); }
public static readonly string _apiSecret = ""; // your api secret private static void Main(string[] args) { ILogFactory logFactory = null; IRequestAuthenticator ra = new RequestAuthenticator(_apiKey, _apiSecret, _clientId); IBitstampClient client = new BitstampClient(ra, logFactory); var ticker = client.GetTicker(); Console.WriteLine("Last bitcoin market value: " + ticker.last); Console.ReadLine(); }
public BlocktraderService(ILog log, ExchangeProxySettings settings) { binance = new BinanceClient(log); bitfinex = new BitfinexClient(log); bitstamp = new BitstampClient(log, settings); exchangeClients = new Dictionary <ExchangeTitle, IExchangeClient> { [ExchangeTitle.Binance] = binance, [ExchangeTitle.Bitfinex] = bitfinex, [ExchangeTitle.Bitstamp] = bitstamp }; }
protected void InitBitstampConfiguration(BitstampClient client) { var configs = client.GetExchangeConfiguration(); var btc = configs.Where(c => c.UrlSymbol == "btcusd").Single(); BTCUSDMinValue = btc.MinOrderSize(CurrencyName.USD); BCHUSDMinValue = configs.Where(c => c.UrlSymbol == "bchusd").Single().MinOrderSize(CurrencyName.USD); LTCUSDMinValue = configs.Where(c => c.UrlSymbol == "ltcusd").Single().MinOrderSize(CurrencyName.USD); ETHUSDMinValue = configs.Where(c => c.UrlSymbol == "ethusd").Single().MinOrderSize(CurrencyName.USD); XRPUSDMinValue = configs.Where(c => c.UrlSymbol == "xrpusd").Single().MinOrderSize(CurrencyName.USD); CountryCurrencyDecimal = btc.CountryCurrencyDecimal; CryptoCurrencyDecimal = btc.CryptoCurrencyDecimal; }
public static void Main(string[] args) { var bitstamp = new BitstampClient(); bitstamp.ConnectAsync().Wait(); bitstamp.GetTickerObservable() .Subscribe(x => Console.WriteLine(x)); //bitstamp.GetTradesObservable() // .Subscribe(x => Console.WriteLine(x)); //bitstamp.GetOrderBookObservable() // .Subscribe(x => Console.WriteLine(x)); Console.ReadLine(); }
internal XrpUsdExchange(BitstampClient client) : base(client, XrpUsdSymbol) { }
internal BchBtcExchange(BitstampClient client) : base(client, BchBtcSymbol) { }
internal BchEurExchange(BitstampClient client) : base(client, BchEurSymbol) { }
internal LtcBtcExchange(BitstampClient client) : base(client, LtcBtcSymbol) { }
public BitstampRestExchange(ExchangeSettingsData setting) : base(setting) { Client = new BitstampClient(setting); }
internal XrpBtcExchange(BitstampClient client) : base(client, XrpBtcSymbol) { }
internal BtcUsdExchange(BitstampClient client) : base(client, BtcUsdSymbol) { }
internal XrpEurExchange(BitstampClient client) : base(client, XrpEurSymbol) { }
internal EurUsdExchange(BitstampClient client) : base(client, EurUsdSymbol) { }
/// <summary>Trades on the exchange.</summary> /// <returns>The time to wait before buying the next time. Is <c>null</c> if no deposit could be found, the /// balance is insufficient or if there was a temporary error.</returns> private async Task <TimeSpan?> TradeAsync(Notification notification) { var client = new BitstampClient(this.Settings.CustomerId, this.Settings.ApiKey, this.Settings.ApiSecret); try { this.Settings.LastStatus = this.GetString(Resource.String.TradeInProgressStatus); var exchange = client.Exchanges[this.tickerSymbol]; this.Settings.LastTradeTime = DateTime.UtcNow; var balance = await exchange.GetBalanceAsync(); var firstBalance = balance.FirstCurrency; var secondBalance = balance.SecondCurrency; this.Settings.LastBalanceFirstCurrency = (float)firstBalance; this.Settings.LastBalanceSecondCurrency = (float)secondBalance; var transactions = await this.GetTransactionsAsync(exchange); var buy = this.Settings.Buy; var hasTradePeriodEnded = this.SetPeriod(transactions, buy) && ((buy ? firstBalance : secondBalance) > 0m); if (!this.Settings.PeriodEnd.HasValue) { this.Settings.RetryIntervalMilliseconds = this.Settings.MaxRetryIntervalMilliseconds; notification.Update( this, Kind.Warning, this.Settings.NotifyEvents, Resource.String.NoDepositNotification); return(null); } Info( "Current balance is {0} {1}.", buy ? this.Settings.SecondCurrency : this.Settings.FirstCurrency, buy ? secondBalance : firstBalance); var ticker = await exchange.GetTickerAsync(); var calculator = new UnitCostAveragingCalculator( this.Settings.PeriodEnd.Value, this.minTradeAmount, balance.Fee, this.feeStep); var startBalance = buy ? secondBalance : firstBalance * ticker.Bid; var start = this.GetStart(transactions); var secondAmount = calculator.GetTradeAmount(start, startBalance, startBalance); if (!secondAmount.HasValue) { this.Settings.RetryIntervalMilliseconds = this.Settings.MaxRetryIntervalMilliseconds; notification.Update( this, Kind.Warning, this.Settings.NotifyEvents, Resource.String.InsufficientBalanceNotification); return(null); } Info("Start is at {0:o}.", start); Info("Current time is {0:o}.", DateTime.UtcNow); Info("Amount to trade is {0} {1}.", this.Settings.SecondCurrency, secondAmount.Value); if (buy) { // If this is the last trade, we need to subtract the fee first, as the exchange will do the // same. if (calculator.IsLastTrade(secondBalance, secondAmount.Value)) { secondAmount -= calculator.GetFee(secondAmount.Value); } var firstAmountToTrade = Math.Round(secondAmount.Value / ticker.Ask, this.firstDecimals); var result = await exchange.CreateBuyOrderAsync(firstAmountToTrade); this.Settings.LastTradeTime = result.DateTime; firstBalance += result.Amount; var bought = result.Amount * result.Price; notification.Update( this, Kind.Trade, this.Settings.NotifyEvents, Resource.String.BoughtNotification, this.Settings.SecondCurrency, bought, this.Settings.FirstCurrency); start = result.DateTime; secondBalance -= bought + calculator.GetFee(bought); } else { var firstAmountToTrade = Math.Round(secondAmount.Value / ticker.Bid, this.firstDecimals); var result = await exchange.CreateSellOrderAsync(firstAmountToTrade); this.Settings.LastTradeTime = result.DateTime; firstBalance -= result.Amount; var sold = result.Amount * result.Price; notification.Update( this, Kind.Trade, this.Settings.NotifyEvents, Resource.String.SoldNotification, this.Settings.SecondCurrency, sold, this.Settings.FirstCurrency); start = result.DateTime; secondBalance += sold - calculator.GetFee(sold); } ++this.Settings.TradeCountSinceLastTransfer; this.Settings.LastBalanceFirstCurrency = (float)firstBalance; this.Settings.LastBalanceSecondCurrency = (float)secondBalance; this.Settings.RetryIntervalMilliseconds = this.Settings.MinRetryIntervalMilliseconds; var nextTradeTime = calculator.GetNextTime(start, buy ? secondBalance : firstBalance * ticker.Bid) - DateTime.UtcNow; if (!nextTradeTime.HasValue) { this.Settings.RetryIntervalMilliseconds = this.Settings.MaxRetryIntervalMilliseconds; hasTradePeriodEnded = true; } if (((secondAmount.Value > 0m) || hasTradePeriodEnded) && this.Settings.IsSubaccount && this.MakeTransfer(hasTradePeriodEnded)) { // Apparently, after getting confirmation for a successful trade, the traded currency is not yet // credited to the balance. Waiting for a few seconds takes care of that... await Task.Delay(5000); var currency = buy ? this.Settings.FirstCurrency : this.Settings.SecondCurrency; var factor = (decimal)Math.Pow(10, buy ? this.firstDecimals : this.secondDecimals); var amount = Math.Floor((buy ? firstBalance : secondBalance) * factor) / factor; Info("Amount to transfer is {0} {1}.", currency, amount); await exchange.TransferToMainAccountAsync(this.Settings.Buy, amount); notification.Append( this, Kind.Transfer, this.Settings.NotifyEvents, Resource.String.TransferredNotification, currency, amount); this.Settings.TradeCountSinceLastTransfer = 0; if (buy) { this.Settings.LastBalanceFirstCurrency = 0.0f; } else { this.Settings.LastBalanceSecondCurrency = 0.0f; } } return(nextTradeTime); } catch (Exception ex) when(ex is BitstampException || ex is HttpRequestException || ex is WebException || ex is TaskCanceledException) { this.Settings.RetryIntervalMilliseconds *= 2; notification.Append(this, Kind.Warning, this.Settings.NotifyEvents, ex.Message); return(null); } catch (Exception ex) { notification.Append( this, Kind.Error, this.Settings.NotifyEvents, Resource.String.UnexpectedErrorNotification, ex.GetType().Name, ex.Message); this.Settings.RetryIntervalMilliseconds = this.Settings.MaxRetryIntervalMilliseconds; this.IsEnabled = false; Warn("The service has been disabled due to an unexpected error: {0}", ex); throw; } finally { this.Settings.LastStatus = notification.ContentText; client.Dispose(); } }