Example #1
0
        public JsonResult SendResetPosition([FromBody] Params param)
        {
            _tcpClient = new TcpClient(param.ApiHost, param.ApiPort);;
            _apiSocket = new SslStream(_tcpClient.GetStream(), false, new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
            _apiSocket.AuthenticateAsClient(param.ApiHost);
            SendAuthorizationRequest(param);
            List <string> data       = new List <string>();
            var           msgFactory = new OpenApiMessagesFactory();

            if (param.SelectedType == "double")
            {
                foreach (var p in param.SelectedPositions)
                {
                    ProtoTradeSide tradeType = new ProtoTradeSide();
                    if (p.TradeSide.ToUpper() == "BUY")
                    {
                        tradeType = ProtoTradeSide.BUY;
                    }
                    if (p.TradeSide.ToUpper() == "SELL")
                    {
                        tradeType = ProtoTradeSide.SELL;
                    }
                    var msg = msgFactory.CreateMarketOrderRequest(param.AccountId, param.AccessToken, p.SymbolName, tradeType, p.Volume, null, null, null, p.PositionId);
                    Transmit(msg);
                }
            }

            if (param.SelectedType == "reverse")
            {
                foreach (var p in param.SelectedPositions)
                {
                    ProtoTradeSide tradeType = new ProtoTradeSide();
                    if (p.TradeSide.ToUpper() == "BUY")
                    {
                        tradeType = ProtoTradeSide.SELL;
                    }
                    if (p.TradeSide.ToUpper() == "SELL")
                    {
                        tradeType = ProtoTradeSide.BUY;
                    }
                    var msg = msgFactory.CreateMarketOrderRequest(param.AccountId, param.AccessToken, p.SymbolName, tradeType, p.Volume * 2, null, null, null, p.PositionId);
                    Transmit(msg);
                }
            }

            byte[] _message     = Listen(_apiSocket);
            var    protoMessage = msgFactory.GetMessage(_message);

            data.Add(OpenApiMessagesPresentation.ToString(protoMessage));

            Thread.Sleep(1000);
            _message     = Listen(_apiSocket);
            protoMessage = msgFactory.GetMessage(_message);
            data.Add(OpenApiMessagesPresentation.ToString(protoMessage));
            return(Json(new { data }));
        }
Example #2
0
        private void btnSendMarketOrder_Click(object sender, EventArgs e)
        {
            var msgFactory = new OpenApiMessagesFactory();
            var msg        = msgFactory.CreateMarketOrderRequest(Convert.ToInt32(_accountID), _token, 1, ProtoOATradeSide.BUY, Convert.ToInt64(100000));

            Transmit(msg);
        }
Example #3
0
        void SendMarketOrderRequest(OpenApiMessagesFactory msgFactory, Queue writeQueue)
        {
            var _msg = msgFactory.CreateMarketOrderRequest(AccountId, AccessToken, "EURUSD", OpenApiLib.ProtoTradeSide.BUY, testVolume, clientMsgId);

            if (isDebugIsOn)
            {
                Console.WriteLine("SendMarketOrderRequest() Message to be sent:\n{0}", OpenApiMessagesPresentation.ToString(_msg));
            }
            writeQueue.Enqueue(_msg.ToByteArray());
        }
        public void SendMarketOrderRequest(long testAccountId, string symbol, ProtoTradeSide tradeSide, long volume)
        {
            var _msg = outgoingMsgFactory.CreateMarketOrderRequest(testAccountId, authToken, symbol, tradeSide, volume, clientMsgId);

            if (isDebugIsOn)
            {
                Console.WriteLine("SendMarketOrderRequest() Message to be send:\n{0}", OpenApiMessagesPresentation.ToString(_msg));
            }
            writeQueue.Enqueue(Utils.Serialize(_msg));
        }
Example #5
0
        protected void btnSendMarketOrderRequest_Click(object sender, EventArgs e)
        {
            SendAuthorizationRequest();
            var accountID  = ddlTradingAccounts.SelectedValue;
            var token      = Session["Token"].ToString();
            var msgFactory = new OpenApiMessagesFactory();
            var msg        = msgFactory.CreateMarketOrderRequest(Convert.ToInt32(accountID), token, "EURUSD", OpenApiLib.ProtoTradeSide.BUY, 100000);

            Transmit(msg);
            byte[] _message     = Listen(_apiSocket);
            var    protoMessage = msgFactory.GetMessage(_message);

            lblResponse.Text = OpenApiMessagesPresentation.ToString(protoMessage);
        }