示例#1
0
 /// <summary>
 /// 委托执行回报,订单的任何执行回报都会触发本事件,通过rpt可访问回报信息。
 /// </summary>
 /// <param name="rpt"></param>
 public override void OnExecRpt(ExecRpt rpt)
 {
     Console.WriteLine(
         "rpt: cl_ord_id={0} price={1} amount={2} exec_type={3}",
         rpt.cl_ord_id,
         rpt.price,
         rpt.amount,
         rpt.exec_type);
 }
示例#2
0
 /// <summary>
 /// 撤单请求被拒绝时,触发本事件
 /// </summary>
 /// <param name="rpt"></param>
 public override void OnOrderCancelRejected(ExecRpt rpt)
 {
     Console.WriteLine("order cancel failed: {0}", rpt.cl_ord_id);
 }
示例#3
0
 public static void on_execrpt(ExecRpt e)
 {
     System.Console.WriteLine("execution: {0}", e.cl_ord_id);
 }
示例#4
0
 /// <summary>
 /// 撤单请求被拒绝时,触发本事件
 /// </summary>
 /// <param name="rpt"></param>
 public override void OnOrderCancelRejected(ExecRpt rpt)
 {
 }
示例#5
0
 /// <summary>
 /// 委托执行回报,订单的任何执行回报都会触发本事件,通过rpt可访问回报信息。
 /// </summary>
 /// <param name="rpt"></param>
 public override void OnExecRpt(ExecRpt rpt)
 {
 }
示例#6
0
文件: Ally.cs 项目: ryanclouser/Ally
        public async Task <ExecRpt> CreateOrder(string account, string symbol, double quantity, double price, bool gtc = false)
        {
            var xml  = new XmlDocument();
            var root = xml.CreateElement("FIXML", "http://www.fixprotocol.org/FIXML-5-0-SP2");

            xml.AppendChild(root);

            var order = xml.CreateElement("Order", xml.DocumentElement.NamespaceURI);

            var attr = xml.CreateAttribute("Side");

            attr.Value = quantity > 0 ? "1" : "2";   // buy/sell
            order.Attributes.Append(attr);

            attr       = xml.CreateAttribute("Acct");
            attr.Value = account;
            order.Attributes.Append(attr);

            attr       = xml.CreateAttribute("Typ");
            attr.Value = price > 0 ? "2" : "1"; // order type
            order.Attributes.Append(attr);

            if (price > 0)
            {
                attr       = xml.CreateAttribute("Px");
                attr.Value = Convert.ToString(price);
                order.Attributes.Append(attr);
            }

            attr       = xml.CreateAttribute("TmInForce");
            attr.Value = gtc ? "1" : "0";
            order.Attributes.Append(attr);

            var instrmt = xml.CreateElement("Instrmt", xml.DocumentElement.NamespaceURI);

            attr       = xml.CreateAttribute("SecTyp");
            attr.Value = "CS";
            instrmt.Attributes.Append(attr);

            attr       = xml.CreateAttribute("Sym");
            attr.Value = symbol.ToUpper();
            instrmt.Attributes.Append(attr);

            var OrdQty = xml.CreateElement("OrdQty", xml.DocumentElement.NamespaceURI);

            attr       = xml.CreateAttribute("Qty");
            attr.Value = Convert.ToString(Math.Abs(quantity));
            OrdQty.Attributes.Append(attr);

            order.AppendChild(instrmt);
            order.AppendChild(OrdQty);
            root.AppendChild(order);

            var request = new RestRequest("/accounts/{id}/orders.json", Method.POST);

            request.AddHeader("TKI_OVERRIDE", "true");
            request.AddUrlSegment("id", account);
            request.AddParameter("application/xml", XmlToString(xml), ParameterType.RequestBody);
            var response = await client.ExecuteAsync(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                JObject o = JObject.Parse(response.Content);

                if ((string)o["response"]["error"] == "Success")
                {
                    string order_id = (string)o["response"]["clientorderid"];

                    var exec = new ExecRpt();
                    exec.TrdDt = DateTime.Now;
                    exec.OrdID = order_id;
                    exec.ID    = order_id;
                    exec.Stat  = (int)OrderState.Pending;
                    exec.Side  = quantity > 0 ? 1 : 2;  // buy / sell
                    exec.Typ   = price > 0 ? 1 : 2;     // limit
                    if (price > 0)
                    {
                        exec.Px = price;                // limit price
                    }
                    exec.TmInForce = gtc ? "1" : "0";   // duration
                    exec.Acct      = account;

                    exec.Instrmt        = new Instrmt();
                    exec.Instrmt.Sym    = symbol;
                    exec.Instrmt.SecTyp = "CS";

                    exec.OrdQty     = new OrdQty();
                    exec.OrdQty.Qty = Math.Abs(quantity);

                    return(exec);
                }
            }

            return(null);
        }
示例#7
0
文件: Ally.cs 项目: ryanclouser/Ally
        public async Task <bool> CreateOrder(ExecRpt exec)
        {
            var xml  = new XmlDocument();
            var root = xml.CreateElement("FIXML", "http://www.fixprotocol.org/FIXML-5-0-SP2");

            xml.AppendChild(root);

            var order = xml.CreateElement("Order", xml.DocumentElement.NamespaceURI);

            var attr = xml.CreateAttribute("Side");

            attr.Value = Convert.ToString(exec.Side);   // buy/sell
            order.Attributes.Append(attr);

            attr       = xml.CreateAttribute("Acct");
            attr.Value = exec.Acct;
            order.Attributes.Append(attr);

            attr       = xml.CreateAttribute("Typ");
            attr.Value = Convert.ToString(exec.Typ); // order type
            order.Attributes.Append(attr);

            if (exec.Typ == 2)    // limit
            {
                attr       = xml.CreateAttribute("Px");
                attr.Value = Convert.ToString(exec.Px);
                order.Attributes.Append(attr);
            }

            attr       = xml.CreateAttribute("TmInForce");
            attr.Value = exec.TmInForce;
            order.Attributes.Append(attr);

            var instrmt = xml.CreateElement("Instrmt", xml.DocumentElement.NamespaceURI);

            attr       = xml.CreateAttribute("SecTyp");
            attr.Value = exec.Instrmt.SecTyp;
            instrmt.Attributes.Append(attr);

            attr       = xml.CreateAttribute("Sym");
            attr.Value = exec.Instrmt.Sym;
            instrmt.Attributes.Append(attr);

            var OrdQty = xml.CreateElement("OrdQty", xml.DocumentElement.NamespaceURI);

            attr       = xml.CreateAttribute("Qty");
            attr.Value = Convert.ToString(exec.OrdQty.Qty);
            OrdQty.Attributes.Append(attr);

            order.AppendChild(instrmt);
            order.AppendChild(OrdQty);
            root.AppendChild(order);

            var request = new RestRequest("/accounts/{id}/orders.json", Method.POST);

            request.AddHeader("TKI_OVERRIDE", "true");
            request.AddUrlSegment("id", exec.Acct);
            request.AddParameter("application/xml", XmlToString(xml), ParameterType.RequestBody);
            var response = await client.ExecuteAsync(request);

            if (response.StatusCode == HttpStatusCode.OK)
            {
                JObject o = JObject.Parse(response.Content);

                if ((string)o["response"]["error"] == "Success")
                {
                    return(true);
                }
            }

            return(false);
        }