Exemplo n.º 1
0
        public string sendTransaction(
            Transaction t
            )
        {
            Request requestSell = service.CreateRequest("CreateOrderAndRouteEx");
            requestSell.Set("EMSX_AMOUNT", t.amount);
            requestSell.Set("EMSX_BROKER", "API");
            requestSell.Set("EMSX_HAND_INSTRUCTION", "ANY");
            requestSell.Set("EMSX_ORDER_TYPE", "MKT");
            requestSell.Set("EMSX_SIDE", "SELL");
            requestSell.Set("EMSX_TICKER", t.securitySell);
            requestSell.Set("EMSX_TIF", "DAY");

            Request requestBuy = service.CreateRequest("CreateOrderAndRouteEx");
            requestSell.Set("EMSX_AMOUNT", t.amount);
            requestSell.Set("EMSX_BROKER", "API");
            requestSell.Set("EMSX_HAND_INSTRUCTION", "ANY");
            requestSell.Set("EMSX_ORDER_TYPE", "MKT");
            requestSell.Set("EMSX_SIDE", "BUY");
            requestSell.Set("EMSX_TICKER", t.securityBuy);
            requestSell.Set("EMSX_TIF", "DAY");

            session.SendRequest(requestSell, new CorrelationID(-2222));
            session.SendRequest(requestBuy, new CorrelationID(-1111));

            return "\nSUCCESFULLY SENT: " + t.toString();
        }
Exemplo n.º 2
0
        private void sendSellTransaction(
            Transaction t
            )
        {
            double sellVal = (t.amountSell * t.priceSell);

            Request requestSell = service.CreateRequest("CreateOrderAndRouteEx");
            //Request requestSell = service.CreateRequest("CreateOrder");
            requestSell.Set("EMSX_LIMIT_PRICE", (t.priceSell).ToString());
            //requestSell.Set("EMSX_LIMIT_PRICE", 1.0);
            //requestSell.Set("EMSX_AMOUNT", t.amountSell);
            requestSell.Set("EMSX_AMOUNT", 1);
            requestSell.Set("EMSX_BROKER", "NORS"); // BMTB
            requestSell.Set("EMSX_HAND_INSTRUCTION", "DMA");
            requestSell.Set("EMSX_ORDER_TYPE", "LMT");
            requestSell.Set("EMSX_SIDE", "SELL");
            requestSell.Set("EMSX_TICKER", t.securitySell);
            requestSell.Set("EMSX_TIF", "DAY");
            requestSell.Set("EMSX_ACCOUNT", "LAGOTRAD");

            int sellStamp = GetTimestamp(DateTime.Now);
            requestSell.Set("EMSX_SEQUENCE", sellStamp);
            this.unfilledOrders[sellStamp] = requestSell;
            this.unfilledTransactions[sellStamp] = t;

            CorrelationID requestID = new CorrelationID("-2222");
            session.SendRequest(requestSell, requestID);

            Lgr.WriteTrade(sellVal, " ..... SELL: " + t.securitySell +
                " ..... amount " + t.amountSell + " price " + t.priceSell + " EUR" +
                " curr rate " + t.currencyRateSell.ToString());
        }
Exemplo n.º 3
0
        public string sendBuyTransaction(
            Transaction t
            )
        {
            double tradeValToday = Lgr.GetTradeValToday();
            double maxEurPerDay = Convert.ToDouble(ConfigurationManager.AppSettings["maxEurPerDay"]);
            double maxEurPerTrade = Convert.ToDouble(ConfigurationManager.AppSettings["maxEurPerTrade"]);
            double buyVal = (t.amountBuy * t.priceBuy);
            double sellVal = (t.amountSell * t.priceSell);

            if (tradeValToday + (t.amountBuy * t.priceBuy) + (t.amountSell * t.priceSell) > maxEurPerDay)
            {
                Lgr.Log("INFO", "Trades value today " + tradeValToday.ToString() +
                    " + Sell value " + sellVal.ToString() +
                    " + Buy value " + buyVal.ToString() +
                    " > maxEurPerDay " + maxEurPerDay.ToString() +
                    " NOT SENDING TRANSACTION");
                return "";
            }
            if ((t.amountBuy * t.priceBuy) + (t.amountSell * t.priceSell) > maxEurPerTrade)
            {
                Lgr.Log("INFO", "Sell value " + sellVal.ToString() +
                    " + Buy value " + buyVal.ToString() +
                    " > maxEurPerTrade " + maxEurPerTrade.ToString() +
                    " NOT SENDING TRANSACTION");
                return "";
            }

            string retstr = "";

            //Request requestBuy = service.CreateRequest("CreateOrderAndRouteEx");
            Request requestBuy = service.CreateRequest("CreateOrder");
            requestBuy.Set("EMSX_AMOUNT", t.amountBuy);
            //double price = t.priceBuy * t.currencyRateBuy;
            requestBuy.Set("EMSX_LIMIT_PRICE", (t.priceBuy).ToString());
            //requestBuy.Set("EMSX_LIMIT_PRICE", 1.0);
            //requestBuy.Set("EMSX_AMOUNT", 1);
            requestBuy.Set("EMSX_BROKER", "NORS"); // BMTB
            requestBuy.Set("EMSX_HAND_INSTRUCTION", "DMA");
            requestBuy.Set("EMSX_ORDER_TYPE", "LMT");
            requestBuy.Set("EMSX_SIDE", "BUY");
            requestBuy.Set("EMSX_TICKER", t.securityBuy);
            requestBuy.Set("EMSX_TIF", "DAY");
            requestBuy.Set("EMSX_ACCOUNT", "LAGOTRAD");

            int buyStamp = GetTimestamp(DateTime.Now);
            requestBuy.Set("EMSX_SEQUENCE", buyStamp);
            this.unfilledOrders[buyStamp] = requestBuy;

            CorrelationID requestID = new CorrelationID("-1111");
            session.SendRequest(requestBuy, requestID);

            //Request requestInfo = service.CreateRequest("OrderInfo");
            //requestInfo.Set("EMSX_SEQUENCE", requestBuy.EMSX_SEQUENCE);
            //CorrelationID infoID = new CorrelationID("-3333");
            //session.SendRequest(requestInfo, infoID);
            //use this to get buy order info and if order status == FILLED -> sell

            int timeoutInMilliSeconds = 5000;

            Event evt = session.NextEvent(timeoutInMilliSeconds);
            do
            {
                retstr += "Received Event: " + evt.Type + "\n";
                foreach (Message msg in evt)
                {
                    retstr += "MESSAGE: " + msg.ToString() + "\n";
                    retstr += "CORRELATION ID: " + msg.CorrelationID + "\n";
                    if (evt.Type == Event.EventType.RESPONSE && msg.CorrelationID == requestID)
                    {
                    }
                }
                evt = session.NextEvent(timeoutInMilliSeconds);
            } while (evt.Type != Event.EventType.TIMEOUT);
            Lgr.Log("DEBUG", retstr);

            Lgr.WriteTrade(buyVal, " ..... BUY: " + t.securityBuy +
                " ..... amount " + t.amountBuy + " price " + t.priceBuy + " EUR" +
                " curr rate " + t.currencyRateBuy.ToString());

            return "\nSUCCESFULLY SENT: " + t.toString() + "\n" + retstr;
        }
Exemplo n.º 4
0
        private void sendTransaction(Transaction t)
        {
            string retval = ts.startSession();
            Invoke(new Action(() =>
                          richTextBox1.AppendText(retval)));

            retval = ts.sendTransaction(t);
            Invoke(new Action(() =>
              richTextBox1.AppendText(retval)));

            retval = ts.stopSession();
            Invoke(new Action(() =>
                          richTextBox1.AppendText(retval)));
        }
Exemplo n.º 5
0
        private void sendTransaction(Transaction t)
        {
            Result result = ts.startSession();
            bool succ = result.success;
            string retval = result.retval;
            if (!succ)
            {
                Lgr.Log("ERROR", retval);
                return;
            }

            Invoke(new Action(() =>
                          richTextBox1.AppendText(retval)));

            retval = ts.sendBuyTransaction(t);
            Invoke(new Action(() =>
              richTextBox1.AppendText(retval)));

            retval = ts.stopSession();
            Invoke(new Action(() =>
                          richTextBox1.AppendText(retval)));
        }
Exemplo n.º 6
0
 private void handleTransaction(Transaction transaction, string elmFields)
 {
     Lgr.Log("INFO", "Got element fields " + elmFields + " from API.");
     if (sendTransactions)
     {
         Invoke(new Action(() =>
           richTextBox1.AppendText("\nsendTransactions=true\n")));
         if (transaction.isFeasible())
         {
             Lgr.Log("INFO", "SEND TRANSACTIONS = TRUE, FEASIBLE TRANSACTION!!!");
             Lgr.Log("INFO", transaction.toString());
             Invoke(new Action(() =>
                 richTextBox1.AppendText("\nFEASIBLE TRANSACTION!\n")));
             sendTransaction(transaction);
         }
         else
         {
             Invoke(new Action(() =>
                 richTextBox1.AppendText("\nno feasible transaction\n")));
         }
     }
     else
     {
         if (transaction.isFeasible())
         {
             Lgr.Log("INFO", "SEND TRANSACTIONS = FALSE, FEASIBLE TRANSACTION");
             Lgr.Log("INFO", transaction.toString());
         }
         Invoke(new Action(() =>
             richTextBox1.AppendText("\nsendTransactions=false\n")));
     }
 }