Пример #1
0
      private  void CheckMultitrades(CpTrade trade,List <Ctrade> boTrades){
       //  var Sequence= new Array();
         if (trade !=null){
             var possibletrades = boTrades.Where(item => (item.symbol_id==trade.BOSymbol && item.price==trade.Price) ); ;
              if (trade.Qty > 0)
             {
               possibletrades = possibletrades.Where(item => item.qty > 0);
               possibletrades = possibletrades.OrderByDescending(o => o.qty);
             }
             else{
               possibletrades = possibletrades.Where(item => item.qty < 0);
               possibletrades = possibletrades.OrderBy(o => o.qty);
              }
              var Sequence= new List<long>();
              if (possibletrades.Count()>0){
              if (trade.Qty==possibletrades.ElementAt(0).qty){
                if(possibletrades.ElementAt(0).tradeNumber!=null)Sequence.Add((long) possibletrades.ElementAt(0).tradeNumber);

              }
              else {
                var i=0;
                double qty=0;
                while ((i<possibletrades.Count())&&(qty!=trade.Qty)){
                  if(Math.Abs((double) possibletrades.ElementAt(i).qty)<Math.Abs((double) trade.Qty)){
                    qty = (double) possibletrades.ElementAt(i).qty;
                    if (Sequence.Count == 0) Sequence.Add((long)possibletrades.ElementAt(i).tradeNumber);
                    else Sequence[0] = (long)possibletrades.ElementAt(i).tradeNumber;
               //     qty=calculateQty(trade.Qty,qty,i+1,possibletrades,Sequence,1);
                  }
                  else i++;
                }
                //for (i = 0;i<Sequence.Count;i++)Sequence[i]=possibletrades.ElementAt(Sequence[i]);
              }
              }
              }
            //  return Sequence;
}/*
Пример #2
0
 private FTjson FeeJsonfromCpTrade(CpTrade cptrade)
 {
     var p = new FTjson();
     p.operationType = "COMMISSION";
     p.symbolId = cptrade.BOSymbol;
     p.asset = cptrade.ExchFeeCcy;
     p.accountId = cptrade.account;
     double amount = 0;
     if (cptrade.ExchangeFees != null)
     {
         amount = -Math.Abs((double) cptrade.ExchangeFees);
     }
     if (cptrade.Fee != null)
     {
         amount = amount - Math.Abs((double) cptrade.Fee);
     }
     p.amount = amount.ToString();
     p.timestamp = ((DateTime) cptrade.TradeDate).ToString("yyyy-MM-dd HH:mm:ss");
     p.comment = cptrade.exchangeOrderId;
     p.internalComment = cptrade.Symbol;
     return p;
 }
Пример #3
0
        private BOjson JsonfromCpTrade(CpTrade cptrade, string account, string accountclientid)
        {
            var p = new BOjson();
            p.tradeType = "TRADE";
            p.symbolId = cptrade.BOSymbol;
            p.quantity = Math.Abs((double) cptrade.Qty).ToString();
            p.price = cptrade.Price.ToString();
            p.gwTime = ((DateTime) cptrade.TradeDate).ToString("yyyy-MM-dd HH:mm:ss");
            if (((DateTime) cptrade.ValueDate).ToString("yyyy-MM-dd") == "2011-01-01")
            {
                p.valueDate = ((DateTime) cptrade.TradeDate).ToString("yyyy-MM-dd");
            }
            else
            {
                p.valueDate = ((DateTime) cptrade.ValueDate).ToString("yyyy-MM-dd");
            }
            p.side = cptrade.Qty > 0 ? "buy" : "sell";
            p.userId = "az";
            p.counterparty = cptrade.BOcp;
            //    p.counterparty = cptrade.Comment;
            //   p.settlementCounterparty = "LEK";

            p.settlementBrokerAccountId = account;
            //            p.settlementBrokerAccountId = "IUM1307.001";
            //  p.settlementCounterparty = cptrade.BOcp;
            p.settlementCounterparty = cptrade.Comment;
            //  p.brokerAccountId = accountclientid;
            //  p.comment = cptrade.BOTradeNumber;
            p.internalComment = cptrade.exchangeOrderId;
            //p.commission = (-cptrade.ExchangeFees).ToString();
            // p.commissionCurrency = "USD";
            p.takeCommission = true;
            //   p.takeCommission = false;//убрать
            //    p.comment = "Correct reversal of trade dd " + ((DateTime)cptrade.TradeDate).ToString("dd.MM.yyyy");//убрать
            p.redemption = false;
            p.isManual = true;
            return p;
        }
Пример #4
0
        private List<Ctrade> CheckMultitrades(CpTrade trade, List<Ctrade> boTrades)
        {
            List<long> sequence = null;
            List<Ctrade> listBoTrades = null;
            if (trade != null)
            {
                string symbol = trade.BOSymbol;
                double? price = trade.Price;
                //   bool positiveqtyflag = !(trade.Qty < 0);
                double? initialQty = trade.Qty;
                //      if ((boTrades[i].symbol_id == symbol && boTrades[i].price == price) && (boTrades[i].qty > 0 && positiveqtyflag && (Math.Abs((double)boTrades[i].qty) < qtyflag))) possibletrades.Add(boTrades[i]);
                //      var accounts = boTrades.GroupBy(x => x.account_id).Select(g => g.First().account_id).ToList();
                IEnumerable<Ctrade> possibletrades =
                    boTrades.Where(item => (item.symbol_id == symbol && item.price == price));
                List<string> accounts =
                    possibletrades.GroupBy(x => x.account_id).Select(g => g.First().account_id).ToList();

                /****/
                if (trade.Qty > 0)
                {
                    possibletrades =
                        possibletrades.Where(
                            item => (item.qty > 0 && Math.Abs((double) item.qty) < Math.Abs((double) initialQty)));
                    possibletrades = possibletrades.OrderByDescending(o => o.qty);
                }
                else
                {
                    possibletrades =
                        possibletrades.Where(
                            item => (item.qty < 0 && Math.Abs((double) item.qty) < Math.Abs((double) initialQty)));
                    possibletrades = possibletrades.OrderBy(o => o.qty);
                }

                sequence = new List<long>();
                if (possibletrades.Count() > 0)
                {
                    if (trade.Qty == possibletrades.ElementAt(0).qty)
                    {
                        if (possibletrades.ElementAt(0).tradeNumber != null)
                        {
                            sequence.Add(possibletrades.ElementAt(0).fullid);
                            listBoTrades.Add(possibletrades.ElementAt(0));
                        }
                    }
                    else
                    {
                        int i = 0;
                        double qty = 0;
                        while ((i < possibletrades.Count()) && (qty != initialQty))
                        {
                            qty = (double) possibletrades.ElementAt(i).qty;
                            if (sequence.Count == 0) sequence.Add(i);
                            else sequence[0] = i;
                            qty = calculateQty(trade.Qty, qty, i + 1, possibletrades.ToList(), sequence, 1);
                            if (qty != trade.Qty) i++;
                        }
                        if (((qty == trade.Qty)) && (sequence.Count > 0))
                        {
                            listBoTrades = new List<Ctrade> {possibletrades.ElementAt((int) sequence[0])};
                            for (i = 1; i < sequence.Count; i++)
                            {
                                listBoTrades.Add(possibletrades.ElementAt((int) sequence[i]));
                            }
                        }
                    }
                }

                /****/
            }
            return listBoTrades;
        }
Пример #5
0
 private int BoReconPostTrade(CpTrade cpTrade, BOaccount acc, string conStr, string token, int tradesqty)
 {
     string accountnumber = null;
     if (cpTrade.BOTradeNumber != null)
     {
         int? tradenumber = Convert.ToInt32(cpTrade.BOTradeNumber.Split(';')[0]);
         accountnumber = GetAccountIdFromTradeNumber(tradenumber);
     }
     BOjson json = JsonfromCpTrade(cpTrade, accountnumber, acc.accountNameCP);
     string requestPayload = JsonConvert.SerializeObject(json);
     //      if (SendJson(requestPayload, conStr + acc.BOaccountId + "/trade", token))
     if (SendJson(requestPayload, conStr + cpTrade.account + "/trade", token))
     {
         cpTrade.ReconAccount = cpTrade.account;
         tradesqty++;
     }
     else
     {
         LogTextBox.AppendText("\r\n Error in sending to BO for fullid: " + cpTrade.FullId);
     }
     return tradesqty;
 }
Пример #6
0
 private void BoReconPostFee(CpTrade cpTrade, string conStr, BOaccount acc, string token)
 {
     FTjson bjson = null;
     bjson = FeeJsonfromCpTrade(cpTrade);
     string requestFTload = JsonConvert.SerializeObject(bjson);
     if (!SendJson(requestFTload, conStr + acc.BOaccountId + "/transaction", token))
     {
         LogTextBox.AppendText("\r\n Error in sending to fee to BO for fullid: " + cpTrade.FullId);
     }
 }
Пример #7
0
        private static void UpdateRecTrades(CpTrade cpTrade, List<Ctrade> ctrade, EXANTE_Entities db,
                                            List<Reconcilation> recon)
        {
            long? botradenumber = ctrade[0].tradeNumber;
            if (cpTrade.BOTradeNumber == null)
            {
                cpTrade.BOTradeNumber = botradenumber.ToString();
            }
            else
            {
                cpTrade.BOTradeNumber = cpTrade.BOTradeNumber + ";" + botradenumber.ToString();
            }
            cpTrade.BOcp = ctrade[0].cp_id;
            cpTrade.BOSymbol = ctrade[0].symbol_id;
            cpTrade.Comment = ctrade[0].BOtradeTimestamp.Value.ToShortDateString();
            ctrade[0].RecStatus = true;
            db.CpTrades.Attach(cpTrade);
            db.Entry(cpTrade).State = (EntityState)System.Data.Entity.EntityState.Modified;
            db.Ctrades.Attach(ctrade[0]);
            db.Entry(ctrade[0]).State = (EntityState)System.Data.Entity.EntityState.Modified;

            recon.Add(new Reconcilation
                {
                    CpFull_id = cpTrade.FullId,
                    BOTradenumber = botradenumber,
                    Timestamp = DateTime.UtcNow,
                    username = "******",
                    valid = 1
                });

            SaveDBChanges(ref db);
        }
Пример #8
0
        private static void UpdateRecTrades(CpTrade cpTrade, List<Ctrade> ctrade, EXANTE_Entities db, Dictionary<string, List<Ctrade>> boTradeslist,
                                            List<Reconcilation> recon)
        {
            var botradenumber = ctrade[0].tradeNumber;
            if (cpTrade.BOTradeNumber == null)
            {
                cpTrade.BOTradeNumber = botradenumber.ToString();
            }
            else
            {

                cpTrade.BOTradeNumber = cpTrade.BOTradeNumber + ";" + botradenumber.ToString();
            }
            cpTrade.BOcp = ctrade[0].cp_id;
            cpTrade.BOSymbol = ctrade[0].symbol_id;
            cpTrade.Comment = ctrade[0].BOtradeTimestamp.Value.ToShortDateString();
            ctrade[0].RecStatus = true;
            db.CpTrades.Attach(cpTrade);
            db.Entry(cpTrade).State = EntityState.Modified;
            db.Ctrades.Attach(ctrade[0]);
            db.Entry(ctrade[0]).State = EntityState.Modified;

            recon.Add(new Reconcilation
                {
                    CpTrade_id = cpTrade.FullId,
                    Ctrade_id = botradenumber,
                    Timestamp = DateTime.UtcNow,
                    username = "******",
                    valid = 1
                });
        }