public void SendRequestToCancelAllOrders(IWebSocketClientConnection connection)
        {
            JObject order_cancel_request = new JObject();

            order_cancel_request["MsgType"]     = "F";
            order_cancel_request["FingerPrint"] = connection.Device.FingerPrint;
            order_cancel_request["STUNTIP"]     = connection.Device.Stuntip;
            connection.SendMessage(order_cancel_request.ToString());
        }
        //

        public string SendOrder(IWebSocketClientConnection connection,
                                string symbol,
                                ulong qty,
                                ulong price,
                                char side,
                                int broker_id,
                                string client_order_id,
                                char order_type = '2',
                                char execInst   = default(char))
        {
            // add pending new order to the OMS
            MiniOMS.Order orderToSend = new MiniOMS.Order();
            orderToSend.Symbol    = symbol;
            orderToSend.OrderQty  = qty;
            orderToSend.Price     = price;
            orderToSend.Side      = side;
            orderToSend.ClOrdID   = client_order_id;
            orderToSend.OrdType   = order_type;
            orderToSend.OrdStatus = 'A'; // PENDING_NEW according to FIX std
            try
            {
                _miniOMS.AddOrder(orderToSend);
            }
            catch (Exception ex)
            {
                LogStatus(LogStatusType.ERROR,
                          "The MiniOMS Rejected the Order : " +
                          orderToSend.ClOrdID + ";" +
                          orderToSend.OrderQty + ";" +
                          orderToSend.Price.ToString() + ";\n"
                          + ex.Message.ToString() + "\n"
                          + ex.StackTrace
                          );
                return(null);
            }

            // send the order to the broker
            JObject new_order_single = new JObject();

            new_order_single["MsgType"]  = "D";
            new_order_single["ClOrdID"]  = orderToSend.ClOrdID;
            new_order_single["Symbol"]   = orderToSend.Symbol;
            new_order_single["Side"]     = orderToSend.Side.ToString();
            new_order_single["OrdType"]  = orderToSend.OrdType.ToString();
            new_order_single["Price"]    = orderToSend.Price;
            new_order_single["OrderQty"] = orderToSend.OrderQty;
            new_order_single["BrokerID"] = broker_id;
            if (execInst != default(char))
            {
                new_order_single["ExecInst"] = execInst.ToString();
            }
            new_order_single["FingerPrint"] = connection.Device.FingerPrint;
            new_order_single["STUNTIP"]     = connection.Device.Stuntip;
            connection.SendMessage(new_order_single.ToString());
            return(orderToSend.ClOrdID);
        }
        private void SendRequestForOpenOrders(IWebSocketClientConnection connection, int page = 0)
        {
            JObject orders_list_request = new JObject();

            orders_list_request["MsgType"]     = "U4";
            orders_list_request["OrdersReqID"] = connection.NextOutgoingSeqNum();
            orders_list_request["Page"]        = page;
            orders_list_request["PageSize"]    = 20;
            orders_list_request["Filter"]      = new JArray("has_leaves_qty eq 1" /*"has_cum_qty eq 1"*/);
            connection.SendMessage(orders_list_request.ToString());
        }
Пример #4
0
        public void SendTestRequest(IWebSocketClientConnection connection)
        {
            JObject test_request = new JObject();

            test_request["MsgType"]     = "1";
            test_request["FingerPrint"] = connection.Device.FingerPrint;
            test_request["STUNTIP"]     = connection.Device.Stuntip;
            test_request["TestReqID"]   = connection.NextOutgoingSeqNum().ToString();
            test_request["SendTime"]    = Util.ConvertToUnixTimestamp(DateTime.Now).ToString();
            string test_request_msg = test_request.ToString();

            connection.SendMessage(test_request_msg);
        }
 public bool CancelOrderByClOrdID(IWebSocketClientConnection connection, string clOrdID)
 {
     MiniOMS.Order orderToCancel = _miniOMS.GetOrderByClOrdID(clOrdID);
     if (orderToCancel != null)
     {
         if (orderToCancel.OrdStatus == OrdStatus.NEW || orderToCancel.OrdStatus == OrdStatus.PARTIALLY_FILLED)
         {
             orderToCancel.OrdStatus = OrdStatus.PENDING_CANCEL;
             JObject order_cancel_request = new JObject();
             order_cancel_request["MsgType"]     = "F";
             order_cancel_request["ClOrdID"]     = clOrdID;
             order_cancel_request["FingerPrint"] = connection.Device.FingerPrint;
             order_cancel_request["STUNTIP"]     = connection.Device.Stuntip;
             connection.SendMessage(order_cancel_request.ToString());
             return(true);
         }
     }
     return(false);
 }
Пример #6
0
        public void OnOpen(IWebSocketClientConnection connection)
        {
            Debug.Assert(connection.IsConnected);
            Debug.Assert(!connection.IsLoggedOn);

            OnLogEvent(LogStatusType.INFO, "Connection Succeeded");

            _connections.Add(connection);

            // dispatch the connection opened
            DispatchEvent(SystemEventType.OPENED, connection);

            // build the json Login Request Message
            JObject login_request = new JObject();

            login_request["MsgType"]            = "BE";
            login_request["UserReqID"]          = connection.NextOutgoingSeqNum();
            login_request["UserReqTyp"]         = "1";
            login_request["Username"]           = connection.UserAccount.Username;
            login_request["Password"]           = connection.UserAccount.Password;
            login_request["BrokerID"]           = connection.UserAccount.BrokerId;
            login_request["CancelOnDisconnect"] = "1";             // enabled so that all session orders are automatically cancelled upon a disconnection (should work in next backend version)
            if (connection.UserAccount.SecondFactor != null && connection.UserAccount.SecondFactor != string.Empty)
            {
                login_request["SecondFactor"] = connection.UserAccount.SecondFactor;
            }
            login_request["UserAgent"]               = "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.76 Mobile Safari/537.36";
            login_request["UserAgentLanguage"]       = "en-US";
            login_request["UserAgentTimezoneOffset"] = ":180,";
            login_request["UserAgentPlatform"]       = "Linux x86_64";
            login_request["FingerPrint"]             = connection.Device.FingerPrint;
            login_request["STUNTIP"] = connection.Device.Stuntip;

            // send the login request Message on wire
            connection.SendMessage(login_request.ToString());
        }
        private void StartInitialRequestsAfterLogon(IWebSocketClientConnection connection)
        {
            // 1. cancel all user orders
            SendRequestToCancelAllOrders(connection); // not necessary if cancel on disconnect is active

            // 2. send the balance request
            JObject balance_request = new JObject();

            balance_request["MsgType"]      = "U2";
            balance_request["BalanceReqID"] = connection.NextOutgoingSeqNum();
            balance_request["FingerPrint"]  = connection.Device.FingerPrint;
            balance_request["STUNTIP"]      = connection.Device.Stuntip;
            connection.SendMessage(balance_request.ToString());

            // 3. send market data request
            JObject marketdata_request = new JObject();

            marketdata_request["MsgType"] = "V";
            marketdata_request["MDReqID"] = connection.NextOutgoingSeqNum();
            marketdata_request["SubscriptionRequestType"] = "1";
            marketdata_request["MarketDepth"]             = 0;
            marketdata_request["MDUpdateType"]            = "1";
            marketdata_request["MDEntryTypes"]            = new JArray("0", "1", "2"); // bid, offer, trade
            marketdata_request["Instruments"]             = new JArray(_tradingSymbol);
            marketdata_request["FingerPrint"]             = connection.Device.FingerPrint;
            marketdata_request["STUNTIP"] = connection.Device.Stuntip;
            connection.SendMessage(marketdata_request.ToString());

            // 4. send security status request
            JObject securitystatus_request = new JObject();

            securitystatus_request["MsgType"]                 = "e";
            securitystatus_request["SecurityStatusReqID"]     = connection.NextOutgoingSeqNum();
            securitystatus_request["SubscriptionRequestType"] = "1";
            JArray instruments = new JArray();

            instruments.Add("BLINK:BTCBRL");
            instruments.Add("BLINK:BTCUSD");
            instruments.Add("BLINK:BTCVND");
            instruments.Add("BLINK:BTCVEF");
            instruments.Add("BLINK:BTCPKR");
            instruments.Add("BLINK:BTCCLP");
            instruments.Add("BITSTAMP:BTCUSD");
            instruments.Add("ITBIT:BTCUSD");
            instruments.Add("BITFINEX:BTCUSD");
            instruments.Add("BTRADE:BTCUSD");
            instruments.Add("MBT:BTCBRL");
            instruments.Add("KRAKEN:BTCEUR");
            instruments.Add("COINFLOOR:BTCGBP");
            instruments.Add("UOL:USDBRL");
            instruments.Add("UOL:USDBRT");
            instruments.Add("OKCOIN:BTCCNY");
            securitystatus_request["Instruments"] = instruments;
            securitystatus_request["FingerPrint"] = connection.Device.FingerPrint;
            securitystatus_request["STUNTIP"]     = connection.Device.Stuntip;
            connection.SendMessage(securitystatus_request.ToString());

            // 5. send the trade history request
            JObject trades_request = new JObject();

            trades_request["MsgType"]           = "U32";
            trades_request["TradeHistoryReqID"] = connection.NextOutgoingSeqNum();
            //trades_request["Filter"] = new JArray("Symbol eq 'BTCBRL'"); // not working
            //trades_request["SymbolList"] = new JArray("BTCBRL"); // not working
            trades_request["FingerPrint"] = connection.Device.FingerPrint;
            trades_request["STUNTIP"]     = connection.Device.Stuntip;
            connection.SendMessage(trades_request.ToString());

            // 6. send request for all "open" orders
            SendRequestForOpenOrders(connection);
        }