Example #1
0
        public void CreateFromString_CreatesValidObject()
        {
            var trade = TradeObject.CreateFromJObject(tradeId, tradeJObject);

            Assert.NotNull((trade));
            Assert.Equal(1600M, trade.Fee);
            Assert.Equal(1000000M, trade.Cost);
        }
Example #2
0
        public List <TradeObject> GetTradeObjects()
        {
            List <TradeObject> result = new List <TradeObject>();
            var tradeObjectsNode      = XmlParser.GetXmlNode(this.XmlRoot, XmlTags.TradeObjects);
            var tradeObjectNodes      = XmlParser.GetXmlNodes(tradeObjectsNode, XmlTags.TradeObject);

            foreach (XmlNode tradeObjectNode in tradeObjectNodes)
            {
                TradeObject tradeObject = null;
                string      name        = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.Name);
                string      gln         = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.GLN);
                string      clientCode  = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.ClientCode);

                if (name == string.Empty || gln == string.Empty || clientCode == string.Empty)
                {
                    this.Logger.WriteLog("Error parsing trade object: field Name, GLN or ClientCode incorrect", LogTypes.WARNING);
                    continue;
                }

                Client client = null;
                client = ClientRepository.GetAllEntities().Where(c => c.ExCode == clientCode).FirstOrDefault();

                tradeObject = new TradeObject
                {
                    Name        = name,
                    GLN         = gln,
                    FtpLogin    = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.FtpLogin),
                    FtpPassword = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.FtpPassword),
                    LocalFolder = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.LocalFolder),
                    Address     = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.Address),
                    ExCode      = XmlParser.GetTagValue((XmlElement)tradeObjectNode, XmlTags.Code),
                };

                try
                {
                    tradeObject.ClientID = client.ID;
                }
                catch (NullReferenceException)
                {
                    this.Logger.WriteLog(string.Format("Client with ExCode: {0} not found. Trade object: {1} not loaded.", clientCode, name), LogTypes.WARNING);
                    continue;
                }

                result.Add(tradeObject);
            }

            return(result);
        }
Example #3
0
        private AlsiUtils.Trade.BuySell GetBS(TradeObject t, out int Vol)
        {
            int x = 1;

            Trade.BuySell bs = Trade.BuySell.None;

            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenLong && t.Exit_Reason == TradeObject.ExitReason.ReverseSignal)
            {
                x   = 2;
                bs  = Trade.BuySell.Buy;
                Vol = WebSettings.General.VOL * x;
                return(bs);
            }

            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenLong && t.Exit_Reason == TradeObject.ExitReason.ReverseSignal)
            {
                x   = 2;
                bs  = Trade.BuySell.Sell;
                Vol = WebSettings.General.VOL * x;
                return(bs);
            }


            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenLong)
            {
                bs = Trade.BuySell.Buy;
            }
            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenShort)
            {
                bs = Trade.BuySell.Sell;
            }

            if (t.TradeTrigger_Close == TradeObject.TriggerClose.CloseLong)
            {
                bs = Trade.BuySell.Sell;
            }
            if (t.TradeTrigger_Close == TradeObject.TriggerClose.CloseShort)
            {
                bs = Trade.BuySell.Buy;
            }



            Vol = WebSettings.General.VOL * x;

            return(bs);
        }
Example #4
0
        private static void Client_OwnTradesReceived(object sender, Events.KrakenPrivateEventArgs<OwnTradesMessage> e)
        {

            List<TradeObject> trades = e.PrivateMessage.Trades;

            for (int i = 0; i < trades.Count; i++)
            {
                TradeObject t = trades[i];

                OsEngine.Entity.MyTrade trade = new OsEngine.Entity.MyTrade();
                trade.NumberOrderParent = t.OrderTxId;
                trade.Price = t.Price;
                trade.NumberTrade = t.TradeId;
                string pair = t.Pair.ToString();

                Sec security = Securities.Find(sec => sec.NameInSocket == pair);

                if (security == null)
                {
                    return;
                }

                trade.SecurityNameCode = security.NameInRest;
                trade.Volume = t.Volume;
                DateTime time = new DateTime(1970, 1, 1).AddSeconds(Convert.ToDouble(t.Time));
                trade.Time = time;

                if (t.Type == "sell")
                {
                    trade.Side = OsEngine.Entity.Side.Sell;
                }
                else
                {
                    trade.Side = OsEngine.Entity.Side.Sell;
                }

                if (MyTradeUpdateEvent != null)
                {
                    MyTradeUpdateEvent(trade);
                }
            }


            //
            // = (sender, e) => Console.WriteLine($"OwnTrades received");
        }
Example #5
0
        public void DownloadFiles(TradeObject tradeObject)
        {
            NetworkCredential   networkCredential = new NetworkCredential(tradeObject.FtpLogin, tradeObject.FtpPassword);
            FtpClientParameters parametres        = new FtpClientParameters();

            parametres.ConnectTimeout   = new TimeSpan(0, 0, timeoutSec);
            parametres.ReadWriteTimeout = new TimeSpan(0, 0, timeoutSec);
            parametres.Passive          = this.isPassive;

            using (var ftpClient = new FtpClient(this.FTPUri, networkCredential, parametres))
            {
                var files = ftpClient.ListEntries(FtpPath).Where(en => en.Type == FtpEntryType.File);
                this.logger.WriteLog("Document files count in directory: " + ftpClient.ListEntries(FtpPath).Count().ToString());
                foreach (var item in files)
                {
                    using (var stream = ftpClient.Retr(item.Path))
                    {
                        List <byte> byteList = new List <byte>();
                        int         curByte;

                        while ((curByte = stream.ReadByte()) != -1)
                        {
                            byteList.Add((byte)curByte);
                        }

                        try
                        {
                            this.logger.WriteLog(string.Format("{0} {1}", "Parsing waybill file", item.Name));
                            XMLConverter converter = new XMLConverter(byteList, this.logger);
                            if (!this.wBService.AddRecord(converter.GetWaybill()))
                            {
                                this.logger.WriteLog(string.Format("{0}: {1}", "Waybill or register writing error. File", item.Name), LogTypes.ERROR);
                            }
                        }
                        catch (XmlException ex)
                        {
                            this.logger.WriteLog(string.Format("{0}. File: {1}. {2}: {3}. {4}", "Waybill file parsing error", item.Name, ex.Source, ex.Message, ex.StackTrace), LogTypes.ERROR);
                        }
                        catch (Exception ex)
                        {
                            this.logger.WriteLog(string.Format("{0}. File: {1}. {2}: {3}. {4}", "Error adding waybill to db", item.Name, ex.Source, ex.Message, ex.StackTrace), LogTypes.ERROR);
                        }
                        try
                        {
                            File.WriteAllBytes(tradeObject.LocalFolder + "\\" + item.Name, byteList.ToArray());
                        }
                        catch (IOException ex)
                        {
                            this.logger.WriteLog(string.Format("{0}: {1}: {2}. {3}", "Error to save waybill file " + item.Name, ex.Source, ex.Message, ex.StackTrace), LogTypes.ERROR);
                        }
                        if (ftpClient.Dele(item.Path))
                        {
                            this.logger.WriteLog("File " + item.Path + " was deleted from FTP", LogTypes.INFO);
                        }
                        else
                        {
                            this.logger.WriteLog("File " + item.Path + " not deleted from FTP", LogTypes.WARNING);
                        }
                        this.logger.WriteLog("Saved waybill file " + item.Name, LogTypes.INFO);
                    }
                }
            }
        }
        private AlsiUtils.Trade.BuySell GetBS(TradeObject t, out int Vol)
        {
            int x = 1;
            Trade.BuySell bs = Trade.BuySell.None;

            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenLong && t.Exit_Reason == TradeObject.ExitReason.ReverseSignal)
            {
                x = 2;
                bs = Trade.BuySell.Buy;
                Vol = WebSettings.General.VOL * x;
                return bs;
            }

            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenLong && t.Exit_Reason == TradeObject.ExitReason.ReverseSignal)
            {
                x = 2;
                bs = Trade.BuySell.Sell;
                Vol = WebSettings.General.VOL * x;
                return bs;
            }


            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenLong) bs = Trade.BuySell.Buy;
            if (t.TradeTrigger_Open == TradeObject.TriggerOpen.OpenShort) bs = Trade.BuySell.Sell;

            if (t.TradeTrigger_Close == TradeObject.TriggerClose.CloseLong) bs = Trade.BuySell.Sell;
            if (t.TradeTrigger_Close == TradeObject.TriggerClose.CloseShort) bs = Trade.BuySell.Buy;

          


            Vol = WebSettings.General.VOL * x;

            return bs;
        }
Example #7
0
 public void CreateFromString_JObjectdNull_ThrowsArgumentNullException()
 {
     Assert.Equal("jObject", Assert.Throws <ArgumentNullException>(() => TradeObject.CreateFromJObject(tradeId, null)).ParamName);
 }
Example #8
0
 public void CreateFromString_TradeIdNull_ThrowsArgumentNullException()
 {
     Assert.Equal("tradeId", Assert.Throws <ArgumentNullException>(() => TradeObject.CreateFromJObject(null, tradeJObject)).ParamName);
 }