コード例 #1
0
 internal void AddQueryStock(SecurityInfo si)
 {
     foreach (var st in RunningST)
     {
         BaseTradeAPI bta = ((BaseTradeAPI)st.Value);
         if (bta.market == si.Market)
         {
             if (bta.isOpened)
             {
                 if (CurrentTicker.getCurrentTickerPrice(si.Market + si.Code) == 0)
                 {
                     CurrentTicker.Insert(si.Market + si.Code);
                 }
                 if (!bta.DicSi.ContainsKey(si.Code))
                 {
                     bta.DicSi.Add(si.Code, si);
                 }
                 bta.Subscribe(si.Code, "marketDepth", si.Type);
                 bta.Subscribe(si.Code, "trade", si.Type);
                 if (showTradeView)
                 {
                     bta.Subscribe(si.Code, "order", si.Type);
                     bta.Subscribe(si.Code, "account", si.Type);
                     if (si.Type != "spot")
                     {
                         bta.Subscribe(si.Code, "position", si.Type);
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
 public override void QueryQuote5(JObject jomsg)
 {
     #region 全量
     TickData     t           = new TickData();
     JObject      jtick_depth = jomsg;
     string[]     s           = jtick_depth["ch"].ToString().Split(new char[] { '.' });
     SecurityInfo si          = DicSi[s[1]];
     t.SecInfo = si;
     System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
     t.Time   = startTime.AddMilliseconds(System.Convert.ToDouble(jtick_depth["ts"].ToString()));
     t.Name   = si.Name;
     t.Code   = si.Code;
     t.IsReal = true;
     t.Bid    = System.Convert.ToDouble(jtick_depth["tick"]["bids"][0][0].ToString());
     t.Ask    = System.Convert.ToDouble(jtick_depth["tick"]["asks"][0][0].ToString());
     double last = CurrentTicker.getCurrentTickerPrice(market + s[1]);
     t.Last = last == 0 ? (t.Bid + t.Ask) / 2 : last;
     for (int i = 0; i < 10; i++)
     {
         t.Bids[i]     = System.Convert.ToDouble(jtick_depth["tick"]["bids"][i][0].ToString());
         t.Bidsizes[i] = System.Convert.ToDouble(jtick_depth["tick"]["bids"][i][1].ToString());
         t.Asks[i]     = System.Convert.ToDouble(jtick_depth["tick"]["asks"][i][0].ToString());
         t.Asksizes[i] = System.Convert.ToDouble(jtick_depth["tick"]["asks"][i][1].ToString());
     }
     RaiseQueryData(t);
     if (si.Code == this._querySi.Code && si.Market == market)
     {
         RaiseTradeQueryData(t);
     }
     #endregion
 }
コード例 #3
0
        public override JObject PostOrders(string symbol, string tsoc, string price, string orderQty, string tsopt, string symbolType, string clOrdID = "", bool maker = false, string leverage = "10")
        {
            string res = "";

            switch (symbolType)
            {
            case "swap":
                break;

            case "futures":
                break;

            case "spot":
            {
                var param = new Dictionary <string, string>();
                param["amount"] = orderQty;
                if (tsopt != "Market")
                {
                    param["price"] = price;
                    param["type"]  = "limit";
                }
                else
                {
                    param["type"]   = "market";
                    param["amount"] = Math.Round(System.Convert.ToDouble(orderQty) * CurrentTicker.getCurrentTickerPrice(market + symbol), 2).ToString();
                }
                //if (maker)
                //{
                //    param["order_type"] = "1";
                //}
                param["symbol"] = symbol;
                if (tsoc == "5")
                {
                    param["side"] = "buy";
                }
                else
                {
                    param["side"] = "sell";
                }
                //param["exchange"] = "main";

                //if (clOrdID != "")
                //{
                //    param["client_oid"] = clOrdID;
                //}
                res = Query("POST", "/orders", param, true);
            }
            break;

            default:
                break;
            }
            JObject resultJo = new JObject();

            resultJo["data"]   = "网络错误";
            resultJo["status"] = false;
            if (res.Length > 0)
            {
                if (res[0].ToString() != "<")
                {
                    JObject jo = (JObject)JsonConvert.DeserializeObject(res);
                    switch (symbolType)
                    {
                    case "swap":
                        break;

                    case "futures":
                        break;

                    case "spot":
                    {
                        if (jo["status"].ToString() == "0")
                        {
                            resultJo["data"]   = jo["data"].ToString();
                            resultJo["status"] = true;
                        }
                        else
                        {
                            resultJo["data"]   = jo["msg"].ToString();
                            resultJo["status"] = false;
                        }
                    }
                    break;

                    default:
                        resultJo["data"]   = "类型错误";
                        resultJo["status"] = false;
                        break;
                    }
                    return(resultJo);
                }
            }
            return(resultJo);
        }