public override void EvaluateTrade() { TickerChangedEventArgs lastTicker = Data.Store.GetLastTicker(pair); double lastPrice = lastTicker.MarketData.PriceLast; double buyPrice = lastTicker.MarketData.OrderTopBuy; double sellPrice = lastTicker.MarketData.OrderTopSell; double currQuoteAmount = Manager.GetWalletState(pair.QuoteCurrency); double currBaseAmount = Manager.GetWalletState(pair.BaseCurrency); double currQuoteOrdersAmount = Manager.GetWalletStateOrders(pair.QuoteCurrency); double currBaseOrdersAmount = Manager.GetWalletStateOrders(pair.BaseCurrency); double currTradableBaseAmount = currBaseAmount * 0.5; if (currTradableBaseAmount < RuleMinimumBaseAmount.MinimumAllowedTradeAmount) { currTradableBaseAmount = currBaseAmount; } double postBaseAmount = currQuoteAmount * buyPrice; double postQuoteAmount = currTradableBaseAmount / sellPrice; double minPrice = 0; double maxPrice = 0; double delta1 = 0; // -------------------------- Data.ResultSet.Variable tempVar; if (predictorExtremes.GetLastResult().variables.TryGetValue("min", out tempVar)) { minPrice = tempVar.value; } if (predictorExtremes.GetLastResult().variables.TryGetValue("max", out tempVar)) { maxPrice = tempVar.value; } if (predictorDX.GetLastResult().variables.TryGetValue("delta1", out tempVar)) { delta1 = tempVar.value; } // ------------------------------------------- // Compile all the rule variables into a dictionary // ------------------------------------------- Dictionary <string, double> ruleVariables = new Dictionary <string, double>(); ruleVariables.Add("lastBuyTimestamp", LastBuyTime); ruleVariables.Add("lastSellTimestamp", LastSellTime); ruleVariables.Add("lastTickerTimestamp", lastTicker.Timestamp); ruleVariables.Add("price", lastPrice); ruleVariables.Add("buyPrice", buyPrice); ruleVariables.Add("sellPrice", sellPrice); ruleVariables.Add("openPrice", openPosition); ruleVariables.Add("quoteAmount", currQuoteAmount); ruleVariables.Add("baseAmount", currBaseAmount); ruleVariables.Add("quoteAmountOrders", currQuoteOrdersAmount); ruleVariables.Add("baseAmountOrders", currBaseOrdersAmount); ruleVariables.Add("baseAmountTradable", currTradableBaseAmount); ruleVariables.Add("postQuoteAmount", postQuoteAmount); ruleVariables.Add("postBaseAmount", postBaseAmount); ruleVariables.Add("priceDelta1", delta1); ruleVariables.Add("minPrice", minPrice); ruleVariables.Add("maxPrice", maxPrice); ruleVariables.Add("minGUI", lastPrice / minPrice); ruleVariables.Add("maxGUI", maxPrice / lastPrice); // ----------------------- // Recalculate all the rules // ----------------------- try { for (int i = 0; i < allRules.Length; i++) { allRules[i].Recalculate(ruleVariables); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); return; } // ---------------- // Update GUI // ---------------- GUI.GUIManager.UpdateStrategyScreenPair(this.pair, ruleVariables); // ---------------- // Custom rule logic // ---------------- if (ruleDelayAllTrades.Result != RuleResult.BlockBuySell) { // look at base order amount (phase 2: buying) if (ruleMinBaseOrders.Result != RuleResult.BlockBuy) { // update the buy order if (buyPrice > orderPrice) { // price is higher then my buy price, so move mine to the top Move(orderID, buyPrice + Utility.Constants.OneSatoshi, true); return; } return; } // look at quote amount (phase 3: need to sell) if (ruleMinQuote.Result != RuleResult.BlockSell && ruleMinBasePost.Result != RuleResult.BlockSell) { // we have enough of quote and will have enough of base (after trade) to satisfy minimum trade amount (0.0001) Sell(openPosition * 1.015, currQuoteAmount); return; } // look at base amount (phase 1: need to buy) if (ruleMinBase.Result != RuleResult.BlockBuy && ruleMinQuotePost.Result != RuleResult.BlockBuy) { // we have enough of base and will have enough of quote (after trade) to satisfy minimum trade amount (0.0001) // note: this counts the volatility factor, RuleMinimumBaseAmount uses baseAmount * volatility in verification if (ruleForce.Result == RuleResult.Buy) { Buy(buyPrice + Utility.Constants.OneSatoshi, postQuoteAmount); return; } if (rulePriceDelta.currentResult == RuleResult.Buy) { // price has stopped falling and is below average Buy(buyPrice + Utility.Constants.OneSatoshi, postQuoteAmount); return; } return; } } }
public override void EvaluateTrade() { TickerChangedEventArgs lastTicker = Data.Store.GetLastTicker(pair); double lastPrice = lastTicker.MarketData.PriceLast; double buyPrice = lastTicker.MarketData.OrderTopBuy; double sellPrice = lastTicker.MarketData.OrderTopSell; double currQuoteAmount = Manager.GetWalletState(pair.QuoteCurrency); double currBaseAmount = Manager.GetWalletState(pair.BaseCurrency); double currTradableBaseAmount = currBaseAmount * 0.5; // VolatilityScore; if (currTradableBaseAmount < RuleMinimumBaseAmount.MinimumAllowedTradeAmount) { currTradableBaseAmount = currBaseAmount; } double postBaseAmount = currQuoteAmount * buyPrice; double postQuoteAmount = currTradableBaseAmount / sellPrice; double minPrice = 0; double maxPrice = 0; double delta1 = 0; double delta2 = 0; double delta3 = 0; // -------------------------- Data.ResultSet.Variable tempVar; if (predictorExtremes.GetLastResult().variables.TryGetValue("min", out tempVar)) { minPrice = tempVar.value; } if (predictorExtremes.GetLastResult().variables.TryGetValue("max", out tempVar)) { maxPrice = tempVar.value; } if (predictorDX.GetLastResult().variables.TryGetValue("delta1", out tempVar)) { delta1 = tempVar.value; } if (predictorDX.GetLastResult().variables.TryGetValue("delta2", out tempVar)) { delta2 = tempVar.value; } if (predictorDX.GetLastResult().variables.TryGetValue("delta3", out tempVar)) { delta3 = tempVar.value; } // ------------------------------------------- // Compile all the rule variables into a dictionary // ------------------------------------------- Dictionary <string, double> ruleVariables = new Dictionary <string, double>(); ruleVariables.Add("lastBuyTimestamp", LastBuyTime); ruleVariables.Add("lastSellTimestamp", LastSellTime); ruleVariables.Add("lastTickerTimestamp", lastTicker.Timestamp); ruleVariables.Add("price", lastPrice); ruleVariables.Add("buyPrice", buyPrice); ruleVariables.Add("sellPrice", sellPrice); ruleVariables.Add("openPrice", openPosition); ruleVariables.Add("quoteAmount", currQuoteAmount); ruleVariables.Add("baseAmount", currBaseAmount); ruleVariables.Add("baseAmountTradable", currTradableBaseAmount); ruleVariables.Add("postQuoteAmount", postQuoteAmount); ruleVariables.Add("postBaseAmount", postBaseAmount); ruleVariables.Add("priceDelta1", delta1); // ruleVariables.Add("priceDelta2", delta2); // ruleVariables.Add("priceDelta3", delta3); ruleVariables.Add("minPrice", minPrice); ruleVariables.Add("maxPrice", maxPrice); ruleVariables.Add("minGUI", lastPrice / minPrice); ruleVariables.Add("maxGUI", maxPrice / lastPrice); DayOfWeek dof = Utility.DateTimeHelper.UnixTimestampToDateTime(lastTicker.Timestamp).DayOfWeek; if (dof == DayOfWeek.Saturday || dof == DayOfWeek.Sunday) { return; } // ----------------------- // Recalculate all the rules // ----------------------- try { for (int i = 0; i < allRules.Length; i++) { allRules[i].Recalculate(ruleVariables); } } catch (Exception e) { Console.WriteLine("Error: " + e.Message); return; } // ---------------- // Update GUI // ---------------- GUI.GUIManager.UpdateStrategyScreenPair(this.pair, ruleVariables); // ---------------- // Custom rule logic // ---------------- #region Buy Logic Tree if (ruleMinBase.Result != RuleResult.BlockBuy && ruleMinQuotePost.Result != RuleResult.BlockBuy) { // we have enough of base and will have enough of quote (after trade) to satisfy minimum trade amount (0.0001) // note: this counts the volatility factor, RuleMinimumBaseAmount uses baseAmount * volatility in verification if (ruleForce.Result == RuleResult.Buy) { Buy(sellPrice, postQuoteAmount); return; } if (ruleDelayAllTrades.Result != RuleResult.BlockBuySell && ruleDelayBuy.Result != RuleResult.BlockBuy) { // enough time has passed since the last trades were made if (ruleMinQuote.Result == RuleResult.BlockSell) { // if it's blocking sell that means we don't own quote, so go ahead with buying if (rulePriceDelta.currentResult == RuleResult.Buy) { // price is on an upwards trend Buy(sellPrice, postQuoteAmount); return; } } } } #endregion #region Sell Logic Tree if (ruleMinQuote.Result != RuleResult.BlockSell && ruleMinBasePost.Result != RuleResult.BlockSell) { // we have enough of quote and will have enough of base (after trade) to satisfy minimum trade amount (0.0001) if (ruleForce.Result == RuleResult.Sell) { Sell(buyPrice, currQuoteAmount); return; } if (ruleDelayAllTrades.Result != RuleResult.BlockBuySell) { // enough time has passed since the last trades were made if (ruleMinSellprice.Result != RuleResult.BlockSell) { // current price is profitable Sell(buyPrice, currQuoteAmount); return; } /* * * * if (ruleSellBand.Result == RuleResult.Sell) { * // price is below the sell band * * Sell(buyPrice, currQuoteAmount); * SaveTradeData(true, LastSellTime - LastBuyTime); * return; * } * } */ if (ruleStopLoss.Result == RuleResult.Sell) { // price has dropped below stop-loss Sell(buyPrice, currQuoteAmount); return; } } } #endregion }