Esempio n. 1
0
        public void OnTradeStatus(uint targetid, TradeResults status)
        {
            Packets.Server.Trade sendPacket = new SagaMap.Packets.Server.Trade();
            sendPacket.SetActorID(targetid);
            sendPacket.SetStatus(status);

            C.netIO.SendPacket(sendPacket, C.SessionID);
        }
Esempio n. 2
0
        public void SendTradeStatus(uint targetid, TradeResults status)
        {
            Logger.ShowInfo("Sending trade status: " + status, null);

            /*Packets.Server.Trade sendPacket = new SagaMap.Packets.Server.Trade();
             * sendPacket.SetActorID(targetid);
             * sendPacket.SetStatus(status);
             * this.netIO.SendPacket(sendPacket, this.SessionID);;*/
            this.Char.e.OnTradeStatus(targetid, status);
        }
Esempio n. 3
0
        public void SendTradeResult(TradeResults result)
        {
            Packets.Server.TradeResult sendpacket = new SagaMap.Packets.Server.TradeResult();
            sendpacket.SetStatus(result);
            netIO.SendPacket(sendpacket, this.SessionID);

            // and update monies
            Packets.Server.SendZeny p1 = new SagaMap.Packets.Server.SendZeny();
            p1.SetZeny(this.Char.zeny);
            this.netIO.SendPacket(p1, this.SessionID);
        }
Esempio n. 4
0
        public void SendTradeStatusOther(uint targetid, TradeResults status)
        {
            Logger.ShowInfo("Sending trade status other: " + status, null);
            ActorPC target = (ActorPC)map.GetActor(targetid);

            if (target == null)
            {
                return;
            }
            target.e.OnTradeStatus(this.Char.id, status);
        }
Esempio n. 5
0
 void updatecompletedtrades(List <Trade> list, bool savetrades, bool saveorders)
 {
     tradeResults1.NewResultTrades(LogFile("Trades"), list);
     TradeResults.GetPortfolioPlot("Equity", _initialequity.Value, 0, 0, Util.ToTLDate(), Util.ToTLTime(), list, ref equitychart, tradeResults1.CurrentResults.ComPerShare);
     if (savetrades)
     {
         debug("writing " + list.Count + " trades...");
         Util.ClosedPLToText(list, ',', LogFile("Trades"));
     }
     if (saveorders)
     {
         List <Order> olist = SimBroker.GetOrderList();
         debug("writing " + olist.Count + " orders...");
         StreamWriter sw   = new StreamWriter(LogFile("Orders"), false);
         string[]     cols = Enum.GetNames(typeof(OrderField));
         sw.WriteLine(string.Join(",", cols));
         for (int i = 0; i < olist.Count; i++)
         {
             sw.WriteLine(OrderImpl.Serialize(olist[i]));
         }
         sw.Close();
     }
 }
Esempio n. 6
0
        public void SendTradeResult(TradeResults result)
        {
            Packets.Server.TradeResult sendpacket = new SagaMap.Packets.Server.TradeResult();
            sendpacket.SetStatus(result);
            netIO.SendPacket(sendpacket, this.SessionID);

            // and update monies
            Packets.Server.SendZeny p1 = new SagaMap.Packets.Server.SendZeny();
            p1.SetZeny(this.Char.zeny);
            this.netIO.SendPacket(p1, this.SessionID);
        }
Esempio n. 7
0
 public void OnTradeStatus(uint targetid, TradeResults status)
 {
 }
Esempio n. 8
0
        public List <TradeResults> GetActualTransactions()
        {
            List <TransactionDetails> transactionsDetails = new List <TransactionDetails>();

            var transactions = dbcontext.ActualTransactions;

            foreach (var item in transactions)
            {
                TransactionDetails details = new TransactionDetails();
                details.Date    = item.Date;
                details.EndDate = item.EndDate;

                Double StartLABU;
                Double.TryParse(item.ActualLABUStartingPrice, out StartLABU);
                details.StartingLABUPrice = StartLABU;

                Double StartLABD;
                Double.TryParse(item.ActualLABDStartingPrice, out StartLABD);
                details.StartingLABDPrice = StartLABD;

                details.Strategy     = item.Strategy;
                details.StartingType = item.StartingType;


                string myShares = item.Shares.ToString();
                Int32  NumOfShares;
                Int32.TryParse(myShares, out NumOfShares);
                details.Shares = NumOfShares;

                Double EndLABU;
                Double.TryParse(item.ActualLABUEndingPrice, out EndLABU);
                details.EndingLABUPrice = EndLABU;

                Double EndLABD;
                Double.TryParse(item.ActualLABDEndingPrice, out EndLABD);
                details.EndingLABDPrice = EndLABD;

                details.Type   = item.Type;
                details.Reason = item.Reason;

                transactionsDetails.Add(details);
            }

            List <TradeResults> tradeResults = new List <TradeResults>();
            double total           = 0;
            double percentageTotal = 0;

            foreach (var item in transactionsDetails)
            {
                TradeResults tradeResult = new TradeResults();
                tradeResult.Date     = item.Date;
                tradeResult.EndDate  = item.EndDate;
                tradeResult.Strategy = item.Strategy;
                tradeResult.Shares   = item.Shares;

                if (item.Strategy.Equals("ShortMorningSpike"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("NineFortyFiveSpike"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("TenAmSpike"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakdown"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakout"))
                {
                    tradeResult.StartingPrice = item.StartingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugBreakout"))
                {
                    tradeResult.StartingPrice = item.StartingLABUPrice;
                }
                else if (item.Strategy.Equals("GapDownReversal"))
                {
                    tradeResult.StartingPrice = item.StartingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugShort"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("GushShortTwoPercent"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }


                if (item.Strategy.Equals("ShortMorningSpike"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("NineFortyFiveSpike"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("TenAmSpike"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakdown"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakout"))
                {
                    tradeResult.EndingPrice = item.EndingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugBreakout"))
                {
                    tradeResult.EndingPrice = item.EndingLABUPrice;
                }
                else if (item.Strategy.Equals("GapDownReversal"))
                {
                    tradeResult.EndingPrice = item.EndingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugShort"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("GushShortTwoPercent"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }

                double profitLossPerShare = tradeResult.EndingPrice - tradeResult.StartingPrice;

                tradeResult.ProfitLoss = Math.Round((tradeResult.EndingPrice - tradeResult.StartingPrice) * tradeResult.Shares, 2);

                total += tradeResult.ProfitLoss;
                tradeResult.Percentage = Math.Round((profitLossPerShare / tradeResult.StartingPrice) * 100, 2);
                percentageTotal       += tradeResult.Percentage;

                tradeResults.Add(tradeResult);
            }



            return(tradeResults);
        }
Esempio n. 9
0
        /// ////////////////////////////////////////////////////////////////////////////////////////////////
        ///                                     Create Struct from line
        /// ////////////////////////////////////////////////////////////////////////////////////////////////
        private void createStructFrom(string[] oneFile, bool debug)
        {
            foreach (String rows in oneFile)
            {
                TradeResults tradeResults = new TradeResults {
                };
                //Print(rows);
                /// Trade Count, Date In, Date Out, Ticker, lastProfitCurrency, cumProfit, exit name, profit factor, winPct Consecutive losers, largest loser, largest winner, profit per month
                var columns = rows.Split(',');
                if (debug)
                {
                    Print(
                        columns[0] + "\t" +                   // count
                        columns[1] + "\t" +                   // Date In
                        columns[2] + "\t" +                   // Date out
                        columns[3] + "\t" +                   // Ticker
                        columns[4] + "\t" +                   // profit
                        columns[5] + "\t" +                   // cumulative
                        columns[6] + "\t" +                   // exit name
                        columns[7] + "\t" +                   // pf
                        columns[8] + "\t" +                   // winPct
                        columns[9] + "\t" +                   // consec loser
                        columns[10] + "\t" +                  // LL
                        columns[11] + "\t" +                  // LW
                        columns[12] + "\t");
                }                                             // monthlyProfit

                tradeResults.tradeNum  = Convert.ToInt16(columns[0]);
                tradeResults.dateEntry = columns[1];
                tradeResults.dateExit  = columns[2];
                tradeResults.ticker    = columns[3];
                tradeResults.profit    = Convert.ToDouble(columns[4]);
                tradeResults.cumProfit = Convert.ToDouble(columns[5]);

                tradeResults.exitName          = columns[6];
                tradeResults.profitFactor      = Convert.ToDouble(columns[7]);
                tradeResults.winPct            = Convert.ToDouble(columns[8]);
                tradeResults.consecutiveLosers = Convert.ToInt16(columns[9]);

                tradeResults.largestLoser   = Convert.ToDouble(columns[10]);
                tradeResults.largestWinner  = Convert.ToDouble(columns[11]);
                tradeResults.profitPerMonth = Convert.ToDouble(columns[12]);

                allTradeResults.Add(tradeResults);
                //arr.Append(tradeResults);
            }

            filesParsedCount += 1;

            ///show struct array when filished
            if (filesParsedCount == fileCount)
            {
                Print("\n" + filesParsedCount + " of " + fileCount + " ticker backtest files parsed\n");
                Print("\nFinished with creating Structs...");
                foreach (TradeResults thing in allTradeResults)
                {
                    if (debug)
                    {
                        Print(thing.tradeNum + " \t\t\t" + thing.dateEntry + "\t\t\t" + thing.dateExit + " \t\t\t" + thing.ticker + "\t\t\t" + thing.profit + "\t\t\t" + thing.cumProfit +
                              " \t\t\t" + thing.exitName + "\t\t\t" + thing.profitFactor + " \t\t\t" + thing.winPct + "\t\t\t" + thing.consecutiveLosers +
                              "\t\t\t" + thing.largestLoser + " \t\t\t" + thing.largestWinner + "\t\t\t" + thing.profitPerMonth
                              );
                    }
                }
                ListFiltering(allStructs: allTradeResults);
            }
        }
Esempio n. 10
0
 public void OnTradeResult(TradeResults result)
 {
     Packets.Server.TradeResult sendPacket = new SagaMap.Packets.Server.TradeResult();
     sendPacket.SetStatus(result);
     C.netIO.SendPacket(sendPacket, C.SessionID);
 }
Esempio n. 11
0
        public async Task ExecuteArbitrage(ArbitrageResult result)
        {
            try
            {
                //Temp bot grabbing so we can check settings (to be called from bot later?)
                Bot            bot;
                ExchangeConfig account;

                if (result.Type == ArbitrageType.Triangle)
                {
                    bot = _context.Bots
                          .Include(x => x.TradeSettings)
                          .Include(x => x.Exchanges)
                          .First(x => x.Name == "Triangle Arbitrage");
                }
                else
                {
                    bot = _context.Bots
                          .Include(x => x.TradeSettings)
                          .Include(x => x.Exchanges)
                          .First(x => x.Name == "Normal Arbitrage");
                }

                if (bot.TradeSettings.TradingEnabled)
                {
                    //Grab bot accounts for this trade
                    var exchange = bot.Exchanges.FirstOrDefault(x => x.Name == result.Exchanges.First());
                    if (exchange == null || exchange.SelectedConfig == null)
                    {
                        //_logger.LogWarning("No account chosen for " + result.Exchanges.First());
                        return;
                    }
                    else
                    {
                        account = exchange.SelectedConfig;
                    }

                    var arbitrageTradeResults = new TradeResults();

                    if (result.Type == ArbitrageType.Triangle)
                    {
                        var ex = _exchanges.First(x => x.Name == result.Exchanges.First()); //Triangle arb only has one exchange
                        if (!account.Simulated && !ex.IsAuthenticated)
                        {
                            throw new Exception("Can't create a trade, user is not authenticated.");
                        }

                        //TODO: Check that we have enough liquidity for trades (and potentially swap from available liquidity to fill them)

                        //Step 1: Buy/Sell initial coins
                        //Step 2: Swap coin into misc coin
                        //Step 3: Swap misc coin back to original
                        var previousCurrency = result.InitialCurrency;  //Set start currency for choosing buy/sell
                        var currentLiquidity = result.InitialLiquidity; //The amount of the current asset we have
                        var simDelay         = new Random().NextDouble() + 0.1;
                        foreach (var pair in result.Pairs)
                        {
                            //If we start on the base, we want to buy the alt
                            var side = pair.BaseCurrency == previousCurrency ? OrderSide.Buy : OrderSide.Sell;

                            ExchangeOrderResult orderResult;
                            if (account.Simulated)
                            {
                                orderResult = await ex.SimulateOrder(pair.MarketSymbol, side, OrderType.Market, 0, currentLiquidity, simDelay); //Use delay to simulate lag between placing and filling the order
                            }
                            else
                            {
                                orderResult = await ex.CreateOrder(pair.MarketSymbol, side, OrderType.Market, 0, currentLiquidity);
                            }

                            arbitrageTradeResults.BotId = bot.Name;
                            arbitrageTradeResults.Trades.Add(new TradeResult()
                            {
                                Amount       = orderResult.Amount,
                                AmountFilled = orderResult.AmountFilled,
                                AveragePrice = orderResult.AveragePrice,
                                Fees         = orderResult.Fees,
                                FeesCurrency = orderResult.FeesCurrency,
                                FillDate     = orderResult.FillDate,
                                OrderSide    = side,
                                MarketSymbol = pair.MarketSymbol,
                                Message      = orderResult.Message,
                                OrderDate    = orderResult.OrderDate,
                                OrderId      = orderResult.OrderId,
                                Price        = orderResult.Price,
                                Result       = orderResult.Result.ToOrderResult(),
                                TradeId      = orderResult.TradeId,
                            });

                            if (orderResult.Result == ExchangeAPIOrderResult.Canceled || orderResult.Result == ExchangeAPIOrderResult.Error || orderResult.Result == ExchangeAPIOrderResult.Unknown)
                            {
                                throw new Exception("Something went wrong with order " + orderResult.OrderId + ",\r\nResult:" + orderResult.Result + "\r\n" + orderResult.Message);
                            }

                            if (side == OrderSide.Buy)
                            {
                                previousCurrency = pair.AltCurrency;
                            }
                            else
                            {
                                previousCurrency = pair.BaseCurrency;
                            }
                            currentLiquidity = orderResult.AmountFilled;
                        }

                        arbitrageTradeResults.InitialCurrency = result.InitialCurrency;
                        arbitrageTradeResults.EstimatedProfit = result.Profit;
                        arbitrageTradeResults.ActualProfit    = (arbitrageTradeResults.Trades.Last().AmountFilled - result.InitialLiquidity) / result.InitialLiquidity * 100;

                        //Trade 1 gets converted back to the initial currency and added to the dust collected
                        var trade1 = arbitrageTradeResults.Trades.First();
                        if (trade1.OrderSide == OrderSide.Buy)
                        {
                            arbitrageTradeResults.Dust += trade1.AveragePrice * (trade1.Amount - trade1.AmountFilled);
                        }
                        else
                        {
                            arbitrageTradeResults.Dust += (trade1.Amount - trade1.AmountFilled) / trade1.AveragePrice;
                        }

                        //Trade 2 gets converted back to the second currency from the first trade and then to the initial currency
                        var trade2 = arbitrageTradeResults.Trades[1];
                        if (trade2.OrderSide == OrderSide.Buy)
                        {
                            var baseAmount = trade2.AveragePrice * (trade2.Amount - trade2.AmountFilled);
                            if (trade1.OrderSide == OrderSide.Buy)
                            {
                                arbitrageTradeResults.Dust += trade1.AveragePrice * baseAmount;
                            }
                            else
                            {
                                arbitrageTradeResults.Dust += baseAmount / trade1.AveragePrice;
                            }
                        }
                        else
                        {
                            var altAmount = (trade2.Amount - trade2.AmountFilled) / trade2.AveragePrice;
                            if (trade1.OrderSide == OrderSide.Buy)
                            {
                                arbitrageTradeResults.Dust += trade1.AveragePrice * altAmount;
                            }
                            else
                            {
                                arbitrageTradeResults.Dust += altAmount / trade1.AveragePrice;
                            }
                        }

                        //Dust for the final trade is already in the right currency
                        var trade3 = arbitrageTradeResults.Trades.Last();
                        arbitrageTradeResults.Dust += trade3.Amount - trade3.AmountFilled;

                        arbitrageTradeResults.TimeFinished = DateTime.Now;

                        _context.ArbitrageResults.Add(arbitrageTradeResults);
                        _context.SaveChanges();
                    }
                    else
                    {
                        //TODO: Implemented normal arb
                    }
                }
            }
            catch (Exception e)
            {
                _logger.LogCritical("Something went wrong executing arbitrage", e);
            }
        }
Esempio n. 12
0
 public void OnTradeStatus(uint targetid, TradeResults status)
 {
 }
Esempio n. 13
0
        public void SetStatus(TradeResults status)
        {
            byte stat = (byte)status;

            this.PutByte(stat);
        }
Esempio n. 14
0
 public void SendTradeStatusOther(uint targetid, TradeResults status)
 {
     Logger.ShowInfo("Sending trade status other: " + status, null);
     ActorPC target = (ActorPC)map.GetActor(targetid);
     if (target == null) return;
     target.e.OnTradeStatus(this.Char.id, status);
 }
Esempio n. 15
0
 public void OnTradeResult(TradeResults result)
 {
     Packets.Server.TradeResult sendPacket = new SagaMap.Packets.Server.TradeResult();
     sendPacket.SetStatus(result);
     C.netIO.SendPacket(sendPacket, C.SessionID);
 }
        public ActionResult Transactions()
        {
            List <TransactionDetails> transactionsDetails = new List <TransactionDetails>();

            var transactions = dbcontext.GetTrades();

            foreach (var item in transactions)
            {
                TransactionDetails details = new TransactionDetails();
                details.Date = item.Date;

                Double StartLABU;
                Double.TryParse(item.StartingLABUPrice, out StartLABU);
                details.StartingLABUPrice = StartLABU;

                Double StartLABD;
                Double.TryParse(item.StartingLABDPrice, out StartLABD);
                details.StartingLABDPrice = StartLABD;

                details.Strategy     = item.Strategy;
                details.StartingType = item.StartingType;


                string myShares = item.Shares.ToString();
                Int32  NumOfShares;
                Int32.TryParse(myShares, out NumOfShares);
                details.Shares = NumOfShares;

                Double EndLABU;
                Double.TryParse(item.EndingLABUPrice, out EndLABU);
                details.EndingLABUPrice = EndLABU;

                Double EndLABD;
                Double.TryParse(item.EndingLABDPrice, out EndLABD);
                details.EndingLABDPrice = EndLABD;

                details.Type   = item.Type;
                details.Reason = item.Reason;

                transactionsDetails.Add(details);
            }

            List <TradeResults> tradeResults = new List <TradeResults>();
            double total = 0;

            foreach (var item in transactionsDetails)
            {
                TradeResults tradeResult = new TradeResults();
                tradeResult.Date     = item.Date;
                tradeResult.Strategy = item.Strategy;
                tradeResult.Shares   = item.Shares;

                if (item.Strategy.Equals("ShortMorningSpike"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("NineFortyFiveSpike"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("TenAmSpike"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakdown"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakout"))
                {
                    tradeResult.StartingPrice = item.StartingLABUPrice;
                }
                else if (item.Strategy.Equals("GapDownReversal"))
                {
                    tradeResult.StartingPrice = item.StartingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugBreakout"))
                {
                    tradeResult.StartingPrice = item.StartingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugShort"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("GushShortTwoPercent"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }
                else if (item.Strategy.Equals("ShortBreakout"))
                {
                    tradeResult.StartingPrice = item.StartingLABDPrice;
                }


                if (item.Strategy.Equals("ShortMorningSpike"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("NineFortyFiveSpike"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("TenAmSpike"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakdown"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("Breakout"))
                {
                    tradeResult.EndingPrice = item.EndingLABUPrice;
                }
                else if (item.Strategy.Equals("GapDownReversal"))
                {
                    tradeResult.EndingPrice = item.EndingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugBreakout"))
                {
                    tradeResult.EndingPrice = item.EndingLABUPrice;
                }
                else if (item.Strategy.Equals("jnugShort"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("GushShortTwoPercent"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }
                else if (item.Strategy.Equals("ShortBreakout"))
                {
                    tradeResult.EndingPrice = item.EndingLABDPrice;
                }


                double profitLossPerShare = tradeResult.EndingPrice - tradeResult.StartingPrice;

                tradeResult.ProfitLoss = Math.Round((tradeResult.EndingPrice - tradeResult.StartingPrice) * tradeResult.Shares, 2);

                total += tradeResult.ProfitLoss;
                tradeResult.Percentage = Math.Round((profitLossPerShare / tradeResult.StartingPrice) * 100, 2);

                tradeResults.Add(tradeResult);
            }

            ViewBag.Total = total;


            int    k             = 1;
            String jsonChartData = "[0, 0], ";
            double runningTotal  = 0;

            foreach (var item in tradeResults)
            {
                runningTotal   = runningTotal + item.ProfitLoss;
                jsonChartData += "[" + k + ", " + runningTotal + "]";

                if ((k) != tradeResults.Count)
                {
                    jsonChartData += ", ";
                }
                k++;
            }

            ViewBag.JsonChartData = jsonChartData;

            return(View(tradeResults));
        }
Esempio n. 17
0
        public void SetStatus(TradeResults status)
        {
            uint gstnum = (uint)status;

            this.PutUInt(gstnum);
        }
Esempio n. 18
0
        public IActionResult Percentage()
        {
            List <Transactions> transactionsList = _transactionsRepository.GetTransactions().ToList();
            List <TradeResults> tradeResults     = new List <TradeResults>();
            decimal?            total            = 0;
            decimal?            percentageTotal  = 0;

            foreach (var item in transactionsList)
            {
                TradeResults tradeResult = new TradeResults();
                tradeResult.Id         = item.Id;
                tradeResult.StartDate  = item.StartDate;
                tradeResult.StartPrice = item.StartPrice;
                tradeResult.EndPrice   = item.EndPrice;
                tradeResult.EndDate    = item.EndDate;
                tradeResult.Symbol     = item.Symbol;
                tradeResult.Shares     = item.Shares;

                decimal?profitLossPerShare = tradeResult.EndPrice - tradeResult.StartPrice;

                if (!String.IsNullOrWhiteSpace(tradeResult.EndDate))
                {
                    tradeResult.ProfitLoss = Math.Round((decimal)((tradeResult.EndPrice - tradeResult.StartPrice)) * (decimal)tradeResult.Shares, 2);

                    total += tradeResult.ProfitLoss;
                    tradeResult.Percentage = Math.Round((decimal)(profitLossPerShare / tradeResult.StartPrice) * 100, 2);
                    percentageTotal       += tradeResult.Percentage;
                }


                tradeResults.Add(tradeResult);
            }



            ViewBag.Total           = total;
            ViewBag.PercentageTotal = percentageTotal;


            int     k             = 1;
            String  jsonChartData = "[0, 0], ";
            decimal runningTotal  = 0;

            foreach (var item in tradeResults)
            {
                if (!String.IsNullOrWhiteSpace(item.EndDate))
                {
                    runningTotal   = (decimal)(runningTotal + item.Percentage);
                    jsonChartData += "[" + k + ", " + runningTotal + "]";

                    if ((k) != tradeResults.Count)
                    {
                        jsonChartData += ", ";
                    }
                }

                k++;
            }

            ViewBag.JsonChartData = jsonChartData;

            return(View(tradeResults));
        }
Esempio n. 19
0
        public void OnTradeStatus(uint targetid, TradeResults status)
        {
            Packets.Server.Trade sendPacket = new SagaMap.Packets.Server.Trade();
            sendPacket.SetActorID(targetid);
            sendPacket.SetStatus(status);

            C.netIO.SendPacket(sendPacket, C.SessionID);
        }
Esempio n. 20
0
 public void SendTradeStatus(uint targetid, TradeResults status)
 {
     Logger.ShowInfo("Sending trade status: " + status, null);
     /*Packets.Server.Trade sendPacket = new SagaMap.Packets.Server.Trade();
     sendPacket.SetActorID(targetid);
     sendPacket.SetStatus(status);
     this.netIO.SendPacket(sendPacket, this.SessionID);;*/
     this.Char.e.OnTradeStatus(targetid, status);
 }
Esempio n. 21
0
        public ActionResult MonthlyDetails(String Month = "")
        {
            string todaysDate = "";

            if (String.IsNullOrWhiteSpace(Month))
            {
                todaysDate = DateTime.Now.ToString("MM/dd/yyyy");
                Month      = todaysDate.Substring(0, 2);
            }

            string dateSelected     = DateTime.Now.ToString("MM/dd/yyyy");
            string theMonthSelected = dateSelected.Substring(0, 2);
            List <TransactionDetails> transactionsDetails = new List <TransactionDetails>();

            var transactions = dbcontext.ActualTransactions;

            foreach (var item in transactions)
            {
                TransactionDetails details = new TransactionDetails();
                details.Date    = item.Date;
                details.EndDate = item.EndDate;

                Double StartLABU;
                Double.TryParse(item.ActualLABUStartingPrice, out StartLABU);
                details.StartingLABUPrice = StartLABU;

                Double StartLABD;
                Double.TryParse(item.ActualLABDStartingPrice, out StartLABD);
                details.StartingLABDPrice = StartLABD;

                details.Strategy     = item.Strategy;
                details.StartingType = item.StartingType;


                string myShares = item.Shares.ToString();
                Int32  NumOfShares;
                Int32.TryParse(myShares, out NumOfShares);
                details.Shares = NumOfShares;

                Double EndLABU;
                Double.TryParse(item.ActualLABUEndingPrice, out EndLABU);
                details.EndingLABUPrice = EndLABU;

                Double EndLABD;
                Double.TryParse(item.ActualLABDEndingPrice, out EndLABD);
                details.EndingLABDPrice = EndLABD;

                details.Type   = item.Type;
                details.Reason = item.Reason;

                transactionsDetails.Add(details);
            }

            List <TradeResults> tradeResults = new List <TradeResults>();
            double total           = 0;
            double percentageTotal = 0;


            foreach (var item in transactionsDetails)
            {
                if (item.Date.StartsWith(Month))
                {
                    TradeResults tradeResult = new TradeResults();
                    tradeResult.Date     = item.Date;
                    tradeResult.EndDate  = item.EndDate;
                    tradeResult.Strategy = item.Strategy;
                    tradeResult.Shares   = item.Shares;

                    if (item.Strategy.Equals("ShortMorningSpike"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("NineFortyFiveSpike"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("TenAmSpike"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("Breakdown"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("Breakout"))
                    {
                        tradeResult.StartingPrice = item.StartingLABUPrice;
                    }
                    else if (item.Strategy.Equals("ShortBreakout"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("jnugBreakout"))
                    {
                        tradeResult.StartingPrice = item.StartingLABUPrice;
                    }
                    else if (item.Strategy.Equals("GapDownReversal"))
                    {
                        tradeResult.StartingPrice = item.StartingLABUPrice;
                    }
                    else if (item.Strategy.Equals("ShortBreakout"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("GushShortTwoPercent"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }
                    else if (item.Strategy.Equals("jnugShort"))
                    {
                        tradeResult.StartingPrice = item.StartingLABDPrice;
                    }


                    if (item.Strategy.Equals("ShortMorningSpike"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }
                    else if (item.Strategy.Equals("NineFortyFiveSpike"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }
                    else if (item.Strategy.Equals("TenAmSpike"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }
                    else if (item.Strategy.Equals("Breakdown"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }
                    else if (item.Strategy.Equals("Breakout"))
                    {
                        tradeResult.EndingPrice = item.EndingLABUPrice;
                    }
                    else if (item.Strategy.Equals("jnugBreakout"))
                    {
                        tradeResult.EndingPrice = item.EndingLABUPrice;
                    }
                    else if (item.Strategy.Equals("GapDownReversal"))
                    {
                        tradeResult.EndingPrice = item.EndingLABUPrice;
                    }
                    else if (item.Strategy.Equals("ShortBreakout"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }
                    else if (item.Strategy.Equals("GushShortTwoPercent"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }
                    else if (item.Strategy.Equals("jnugShort"))
                    {
                        tradeResult.EndingPrice = item.EndingLABDPrice;
                    }


                    double profitLossPerShare = tradeResult.EndingPrice - tradeResult.StartingPrice;

                    tradeResult.ProfitLoss = Math.Round((tradeResult.EndingPrice - tradeResult.StartingPrice) * tradeResult.Shares, 2);

                    total += tradeResult.ProfitLoss;
                    tradeResult.Percentage = Math.Round((profitLossPerShare / tradeResult.StartingPrice) * 100, 2);
                    percentageTotal       += tradeResult.Percentage;

                    tradeResults.Add(tradeResult);
                }
            }

            List <Month> monthList = new List <Month>();

            Month january = new Month();

            january.MonthValue  = "01";
            january.MonthString = "January";
            monthList.Add(january);

            Month february = new Month();

            february.MonthValue  = "02";
            february.MonthString = "February";
            monthList.Add(february);

            Month march = new Month();

            march.MonthValue  = "03";
            march.MonthString = "March";
            monthList.Add(march);

            Month april = new Month();

            april.MonthValue  = "04";
            april.MonthString = "April";
            monthList.Add(april);

            Month may = new Month();

            may.MonthValue  = "05";
            may.MonthString = "May";
            monthList.Add(may);

            Month june = new Month();

            june.MonthValue  = "06";
            june.MonthString = "June";
            monthList.Add(june);

            Month july = new Month();

            july.MonthValue  = "07";
            july.MonthString = "July";
            monthList.Add(july);

            Month august = new Month();

            august.MonthValue  = "08";
            august.MonthString = "August";
            monthList.Add(august);

            Month september = new Month();

            september.MonthValue  = "09";
            september.MonthString = "September";
            monthList.Add(september);

            Month october = new Month();

            october.MonthValue  = "10";
            october.MonthString = "October";
            monthList.Add(october);

            Month november = new Month();

            november.MonthValue  = "11";
            november.MonthString = "November";
            monthList.Add(november);

            Month december = new Month();

            december.MonthValue  = "12";
            december.MonthString = "December";
            monthList.Add(december);



            ViewBag.Months          = monthList;
            ViewBag.Month           = Month;
            ViewBag.Total           = total;
            ViewBag.PercentageTotal = percentageTotal;


            int    k             = 1;
            String jsonChartData = "[0, 0], ";
            double runningTotal  = 0;

            foreach (var item in tradeResults)
            {
                runningTotal   = runningTotal + item.ProfitLoss;
                jsonChartData += "[" + k + ", " + runningTotal + "]";

                if ((k) != tradeResults.Count)
                {
                    jsonChartData += ", ";
                }
                k++;
            }

            ViewBag.JsonChartData = jsonChartData;

            return(View(tradeResults));
        }