internal override async Task ExecuteAsync() { // get ticker var ticker = await BitstampTrader.GetTickerAsync(TradeSession.PairCode); _tickers.Add(ticker); if (ExecuteTradeHolders()) { return; } if (!PriceDropped()) { return; } // get pair info var pairInfo = CacheHelper.GetFromCache <List <TradingPairInfo> >("TradingPairInfo").First(i => i.PairCode == TradeSession.PairCode.ToLower()); // buy currency on Bitstamp exchange var orderResult = await BitstampTrader.BuyLimitOrderAsync(TradeSession, TradeSettings.GetBuyBaseAmount(ticker, pairInfo), TradeSettings.GetBuyBasePrice(ticker, pairInfo)); // update database BitstampTrader.AddNewOrderToDb(orderResult, ticker, TradeSettings, pairInfo); }
protected TradeRuleBase(BitstampTrader bitstampTrader, TradeSettings tradeSettings, params ITradeHolder[] tradeHolders) { BitstampTrader = bitstampTrader; TradeSettings = tradeSettings; TradeSession.PairCode = tradeSettings.PairCode; _tradeHolders = tradeHolders; }
static void Main() { try { // initialize logger Log.Logger = new LoggerConfiguration() .WriteTo.Console() .MinimumLevel.Debug() .CreateLogger(); // initialize trader _trader = new BitstampTrader(TimeSpan.FromSeconds(15)); var paircodes = new[] { BitstampPairCode.btceur, BitstampPairCode.xrpeur, BitstampPairCode.ltceur, BitstampPairCode.etheur, BitstampPairCode.bcheur }; foreach (var bitstampPairCode in paircodes) { var tradeSettings = new TradeSettings { PairCode = bitstampPairCode.ToString(), BuyUnderPriceMargin = 0.4M, CounterAmount = 17, BaseAmountSavingsRate = 3.0M, SellPriceRate = 6 }; var tradeRule = new BuyAfterDropTradeRule(_trader, tradeSettings, 2.5M, TimeSpan.FromMinutes(60), new WaitPeriodAfterBuyOrderHolder(TimeSpan.FromHours(6)), new MaxNumberOfBuyOrdersHolder(1), new MaxNumberOfSellOrdersHolder(12)); //var tradeRule = new BuyPeriodicTradeRule(_trader, tradeSettings, // new WaitPeriodAfterBuyOrderHolder(TimeSpan.FromHours(1)), // new MaxNumberOfBuyOrdersHolder(1)); _trader.AddTradeRule(tradeRule); } _trader.AddTradeRule(new LinearSpreadTradeRule(_trader, new TradeSettings { PairCode = BitstampPairCode.btcusd.ToString(), BuyUnderPriceMargin = 0.2M, CounterAmount = 10, BaseAmountSavingsRate = 0.75M, SellPriceRate = 2 }, 1.0M)); _trader.ErrorOccured += ErrorOccured; _trader.TickerRetrieved += TickerRetrieved; _trader.BuyLimitOrderPlaced += BuyLimitOrderPlaced; _trader.BuyLimitOrderExecuted += BuyLimitOrderExecuted; _trader.SellLimitOrderPlaced += SellLimitOrderPlaced; _trader.SellLimitOrderExecuted += SellLimitOrderExecuted; // start trader _trader.Start(); System.Console.ReadLine(); } catch (Exception e) { System.Console.WriteLine(e); } }
private async Task <bool> SpreadIsOpen(Ticker ticker) { // get pair info var pairInfo = CacheHelper.GetFromCache <List <TradingPairInfo> >("TradingPairInfo").First(i => i.PairCode == TradeSession.PairCode.ToLower()); // get open orders from database var openOrdersDb = BitstampTrader.GetOpenOrdersDb().FindAll(o => o.CurrencyPairId == BitstampTrader.GetCurrencyPairId(pairInfo.PairCode)); var tickerMax = ticker.Last * (1 + _spreadPct / 100); var tickerMin = ticker.Last * (1 - _spreadPct / 100); var openOrdersInRange = openOrdersDb.FindAll(o => o.BuyPrice > tickerMin && o.BuyPrice < tickerMax); if (openOrdersInRange.Count == 0) { return(true); } return(false); }
public LinearSpreadTradeRule(BitstampTrader bitstampTrader, TradeSettings tradeSettings, decimal spreadPct, params ITradeHolder[] tradeHolders) : base(bitstampTrader, tradeSettings, tradeHolders) { _spreadPct = spreadPct; }
public BuyAfterDropTradeRule(BitstampTrader bitstampTrader, TradeSettings tradeSettings, decimal dropRate, TimeSpan dropPeriod, params ITradeHolder[] tradeHolders) : base(bitstampTrader, tradeSettings, tradeHolders) { _dropRate = dropRate; _dropPeriod = dropPeriod; }
public BuyPeriodicTradeRule(BitstampTrader bitstampTrader, TradeSettings tradeSettings, params ITradeHolder[] tradeHolders) : base(bitstampTrader, tradeSettings, tradeHolders) { }