public IntervalValues GetIntervals() { //IntervalValues intervals; var checkedButton = getCurrentRdoBtnSelection(); IntervalValues intervalVals = null; if (Dispatcher.Invoke(() => checkedButton.Name == "rdoBtn_5_3_1")) { intervalVals = new IntervalValues(5, 3, 1); } else if (Dispatcher.Invoke(() => checkedButton.Name == "rdoBtn_15_5_3")) { intervalVals = new IntervalValues(15, 5, 3); } else if (Dispatcher.Invoke(() => checkedButton.Name == "rdoBtn_30_15_5")) { intervalVals = new IntervalValues(30, 15, 5); } else { intervalVals = new IntervalValues(5, 3, 1);; } ProductManager.SetCurrentIntervalValues(intervalVals); return(intervalVals); }
//use big, medium or small sma to sell depending on market conditions public TradeStrategyE(ref ContextValues inputContextValues, IntervalValues intervalValues) : base(ref inputContextValues) { SetCurrentAction(inputContextValues.CurrentAction); LastBuyAtPrice = inputContextValues.CurrentBufferedPrice; LastSellAtPrice = 0; BigIntervalSmaValues = new SmaValues("BigInterval", ref inputContextValues, intervalValues.LargeIntervalInMin, intervalValues.LargeSmaSlices, intervalValues.MediumSmaSlice, intervalValues.SmallSmaSlices); SmallIntervalSmaValues = new SmaValues("SmallInterval", ref inputContextValues, intervalValues.MediumIntervalInMin, intervalValues.LargeSmaSlices, intervalValues.MediumSmaSlice, intervalValues.SmallSmaSlices); TinyIntervalSmaValues = new SmaValues("TinyInterval", ref inputContextValues, intervalValues.SmallIntervalInMin, intervalValues.LargeSmaSlices, intervalValues.MediumSmaSlice, intervalValues.SmallSmaSlices); inputContextValues.WaitTimeAfterBigSmaCrossInMin = intervalValues.LargeIntervalInMin; //LargeSmaGroup = new SmaGroup(); //LargeSmaGroup.SetGroup(SmallIntervalSmaValues, BigIntervalSmaValues); //SmallSmaGroup = new SmaGroup(); //SmallSmaGroup.SetGroup(TinyIntervalSmaValues, SmallIntervalSmaValues); try { SmallPriceIncreasedPercentage = Properties.Settings.Default.StrategyE_SmallPriceIncreasedPercent; BigPriceIncreasedPercentage = Properties.Settings.Default.StrategyE_BigPriceIncreasedPercent; } catch (Exception) { Logger.WriteLog("Couldnt read strategy E big and samll price change percentage values, using default of .75 and 1.75"); SmallPriceIncreasedPercentage = 0.75m; BigPriceIncreasedPercentage = 1.75m; } }
public void SetCurrentIntervalValues(IntervalValues inputValues) { if (CurContextValues != null) { CurContextValues.CurrentIntervalValues = inputValues; } }
public MacdStrategy(ref ContextValues inputContextValues, IntervalValues intervalValues) : base(ref inputContextValues) { //myMacdStrategy_Large = new Macd(ref inputContextValues, "macd_large"); myMacdStrategy_Small = new Macd(ref inputContextValues, "macd_small"); var genSettings = AppSettings.GetGeneralSettings(); percent_for_using_smallmacd = genSettings.price_inc_percent_for_using_smallmacd; }
public TradeStrategyF(ref ContextValues inputContextValues, IntervalValues intervalValues) : base(ref inputContextValues, intervalValues) { }
public async void InitializeManager(string productName, IntervalValues intervalValues = null) { await Task.Factory.StartNew(() => InitManager(productName, intervalValues)); await Task.Factory.StartNew(() => CheckTicker()); }
public async Task <bool> CreateUpdateStrategyInstance(IntervalValues intervalValues, bool CreateNewInstance = false) { if (isBuysyDisposingCurStrategy) { Logger.WriteLog("Already busy updating interval, please wait for current operation to complete."); return(false); } isBuysyDisposingCurStrategy = true; if (!CreateNewInstance) //instance exists { try { currentTradeStrategy.Dispose(); } catch (Exception ex) { Logger.WriteLog("Error disposing strategy, continuing to create new instance" + ex.Message); ////dont stop creating new isntace even if erro occurs //remnants of previous sma may be active eg an un disposed sma //return false; } finally { currentTradeStrategy = null; } } if (CurContextValues.UserStartedTrading) { CurContextValues.StartAutoTrading = false; } ConfigStrategyInUse = Properties.Settings.Default.StrategyInUse; await Task.Run(() => { //currentTradeStrategy = new TradeStrategyE(ref CurContextValues, intervalValues); switch (ConfigStrategyInUse) { case "E": //////Logger.WriteLog("Setting Current Strategy to E"); //////currentTradeStrategy = new TradeStrategyE(ref CurContextValues, intervalValues); //////break; Logger.WriteLog("Setting Current Strategy to MACD"); var gSettings = AppSettings.GetGeneralSettings(); try { currentTradeStrategy = new MacdStrategy(ref CurContextValues, intervalValues); } catch (Exception ex) { Logger.WriteLog("Cant initialize current strategy, please check settings json file... exiting"); System.Environment.Exit(0); //throw ex; } break; case "F": Logger.WriteLog("Setting Current Strategy to F"); currentTradeStrategy = new TradeStrategyF(ref CurContextValues, intervalValues); break; default: Logger.WriteLog("Using Default Strategy: F"); currentTradeStrategy = new TradeStrategyF(ref CurContextValues, intervalValues); break; } //Logger.WriteLog("Waiting 20 sec for data download to complete "); //Thread.Sleep(20 * 1000); }).ContinueWith((t) => t.Wait()); //await createNewTradeInstance(intervalValues); var x = UpdateDisplaySmaParameters(CurrentDisplaySmaTimeInterval, CurrentDisplaySmaSlices, true); x.Wait(); isBuysyDisposingCurStrategy = false; Logger.WriteLog("Done updating intervals"); writeCurrentStrategySmaValues(); return(true); }
private void InitManager(string ProductName, IntervalValues intervalValues) { //try to get ticker first //Logger.WriteLog("Init Manager Thread ID: " + Thread.CurrentThread.ManagedThreadId.ToString()); try { Logger.WriteLog("Initializing ticker"); ProductTickerClient = new TickerClient(ProductName); } catch (Exception ex) { Logger.WriteLog("Manager cant initialize ticker"); return; } ProductTickerClient.PriceUpdated += ProductTickerClient_UpdateHandler; AvoidExchangeFees = true; ProductTickerClient.TickerConnectedEvent += TickerConnectedHandler; ProductTickerClient.TickerDisconnectedEvent += TickerDisconnectedHandler; MyAuth = new CBAuthenticationContainer(MyKey, MyPassphrase, MySecret); MyProductOrderBook = new MyOrderBook(MyAuth, ProductName, ref ProductTickerClient); MyProductOrderBook.OrderUpdateEvent += FillUpdateEventHandler; CurContextValues = new ContextValues(ref MyProductOrderBook, ref ProductTickerClient); CurContextValues.ProductName = ProductName; CurContextValues.Auth = MyAuth; CurContextValues.AutoTradingStartEvent += autoTradeStartEventHandler; CurContextValues.AutoTradingStopEvent += autoTradeStopEventHandler; ////update ui with initial prices ProductTickerClient_UpdateHandler(this, new TickerMessage(ProductTickerClient.CurrentPrice)); CurrentDisplaySmaTimeInterval = intervalValues.LargeIntervalInMin; CurrentDisplaySmaSlices = intervalValues.LargeSmaSlices; //default large sma slice value //SmaSmall = new MovingAverage(ref ProductTickerClient, ProductName, CurContextValues.CurrentSmallSmaTimeInterval, CurContextValues.CurrentSmallSmaSlices); //SmaSmall.MovingAverageUpdated += SmaSmallChangedEventHandler; Logger.WriteLog(string.Format("{0} manager started", ProductName)); //currentTradeStrategy = new TradeStrategyA(ref CurContextValues); //currentTradeStrategy = new TradeStrategyB(ref CurContextValues); //currentTradeStrategy = new TradeStrategyC(ref CurContextValues); //currentTradeStrategy = new TradeStrategyB(ref CurContextValues); //currentTradeStrategy = new TradeStrategyD(ref CurContextValues); if (intervalValues == null) { intervalValues = new IntervalValues(30, 15, 5);//IntervalValues(5, 3, 1); } //currentTradeStrategy = new TradeStrategyE(ref CurContextValues, intervalValues); CreateUpdateStrategyInstance(intervalValues, true).Wait(); currentTradeStrategy.CurrentActionChangedEvent += CUrrentActionChangeEventHandler; //save the interval values for later use //CurContextValues.CurrentIntervalValues = intervalValues; SetCurrentIntervalValues(intervalValues); DisplaySma = new MovingAverage(ref ProductTickerClient, ProductName, CurrentDisplaySmaTimeInterval, CurrentDisplaySmaSlices); DisplaySma.MovingAverageUpdatedEvent += DisplaySmaChangedEventHandler; UpdateDisplaySmaParameters(CurrentDisplaySmaTimeInterval, CurrentDisplaySmaSlices); UpdateBuySellAmount(0.01m); //default //UpdateBuySellBuffer(0.03m); //default try { UpdateFunds(); } catch (Exception) { Logger.WriteLog("Error getting available funds details, please check your gdax credentials"); } AppSettings.MajorSettingsChangEvent += MajorSettingsChangedEventHandler; //writeCurrentStrategySmaValues(); //ShowGraph(gra); }