Exemplo n.º 1
0
        private async void btnSubscribe(object sender, RoutedEventArgs e)
        {
            string channel = "", instType = "";
            Button btn      = (Button)sender;
            string btn_type = btn.Content.ToString();

            switch (btn_type)
            {
            case "订阅(public)":
                channel = cleanTag(this.channel_public.Text);
                if (channel == "instruments")
                {
                    instType = this.instType_public.Text;
                    if (string.IsNullOrWhiteSpace(instType))
                    {
                        return;
                    }
                }
                break;

            case "订阅(futures)":

                break;

            default:
                break;
            }
            await websocketor.Subscribe(new List <Dictionary <string, string> >() { new Dictionary <string, string>()
                                                                                    {
                                                                                    } });
        }
Exemplo n.º 2
0
        async void Start()
        {
            List <KLine> history_data = new List <KLine>();

            OKExV5APi api = CommonData.Ins.V5pApi;


            //AccountAPIKey api = new AccountAPIKey(keys);
            //web.WebSocketPush += Result;

            //await web.ConnectAsync();

            //await web.LoginAsync(api.V_ApiKey, api.V_SecretKey, api.V_Passphrase);



            //SpotApi api = new SpotApi("", "", "");
            DateTime t_start = DateTime.Now.AddMinutes(-100);


            DateTime t_end = DateTime.Now;

            TimeSpan timeSpan = t_end - new DateTime(1970, 1, 1);

            Console.WriteLine(timeSpan.TotalSeconds);

            timeSpan = TimeZoneInfo.ConvertTimeToUtc(t_end) - new DateTime(1970, 1, 1);

            Console.WriteLine(timeSpan.TotalSeconds);

            //return;

            int length = 1;

            while (t_start.AddMinutes(length * 100) < t_end)
            {
                JContainer con = await api.getCandlesDataAsyncV5("BTC-USDT", t_start, t_start.AddMinutes(length * 100), length);

                List <KLine> d = KLine.GetListFormJContainer(con);

                t_start = t_start.AddMinutes(length * 100);
            }

            //SwapApi api = new SwapApi("", "", "");
            //DateTime t_start = DateTime.Now.AddMinutes(-5 * 181);
            //JContainer con = await api.getCandlesDataAsync("BTC-USD-SWAP", t_start, DateTime.Now, 300);

            //data = KLine.GetListFormJContainer(con);

            //float f_10 = EMA.GetEMA(10, data);
            //float f_30 = EMA.GetEMA(30, data);
            //float f_180 = EMA.GetEMA(180, data);
            //float f_120 = EMA.GetEMA(120, data);
            //float f_60 = EMA.GetEMA(60, data);

            //Console.WriteLine(data.Count);

            //Console.WriteLine(con.First);
            //Console.WriteLine("next");
            //WriteNext(con.First);

            //Console.WriteLine("last");
            //WriteLast(con);



            //KLine k = new KLine("111", "1", "2", "3", "4","5");

            //Console.WriteLine(JToken.FromObject(k).ToString());

            //List<KLine> list = KLine.GetListFormJContainer(con);

            //foreach (var item in list)
            //{
            //    Console.WriteLine(item.closePrice);
            //}

            //KLineCache cache = new KLineCache();
            //cache.SetData(con);

            //MA ma = new MA();
            //ma.SetCache(cache);

            //Console.WriteLine(ma.GetMAValue(5) + "  " + ma.GetMAValue(10) + "  " + ma.GetMAValue(15) + "  " + ma.GetMAValue(30));

            //Console.WriteLine(con.ToString());

            //curentIndex = 0;

            //KLineCache cache = new KLineCache();
            //cache.RefreshData(data);

            //MATaticsHelper helper = new MATaticsHelper();
            //helper.Init(AppSetting.Ins.GetValue("MA_ETH"));
            //await helper.RunHistory();

            //MATaticsHelper2 helper = new MATaticsHelper2();
            //helper.Init(AppSetting.Ins.GetValue("MA_BTC"));
            //await helper.RunHistory();

            ////TurtleTaticsHelper helper3 = new TurtleTaticsHelper();
            ////helper3.Init(AppSetting.Ins.GetValue("Turtle_ETH"));



            //EMATaticsHelper helper2 = new EMATaticsHelper();
            //helper2.Init(AppSetting.Ins.GetValue("EMA_BTC"));

            //await helper2.RunHistory();

            //EMATaticsHelper2 helper3 = new EMATaticsHelper2();
            //helper3.Init(AppSetting.Ins.GetValue("EMA_BTC"));

            //await helper3.RunHistory();

            //await helper3.RunHistory();

            //int winCount = 0;
            //float allMoney = 0;

            //Dictionary<int, int> lossCountDic = new Dictionary<int, int>();

            //Dictionary<int, List<int>> lossWinDic = new Dictionary<int, List<int>>();

            //Dictionary<int, int> winDic = new Dictionary<int, int>();

            //Dictionary<int, Dictionary<int, float>> all_ResultDic = new Dictionary<int, Dictionary<int, float>>();

            //float t = await CommonData.Ins.V_InformationApi.F_GetLongShortRatio("BTC", DateTime.Now, 5);

            //var result = await CommonData.Ins.V_SpotApi.getInstrumentsAsync();

            int runHelper = AppSetting.Ins.GetInt("RunHelper");

            string[] coins = AppSetting.Ins.GetValue("Run").Split(';');
            Console.WriteLine(AppSetting.Ins.GetValue("Run"));
            for (int i = 0; i < coins.Length; i++)
            {
                string item = coins[i];
                if (runHelper == 1)
                {
                    MATaticsHelper m_helper = new MATaticsHelper();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("MA_{0}", item)));

                    await m_helper.RunHistory();
                }
                else if (runHelper == 2)
                {
                    MATaticsHelper2 m_helper = new MATaticsHelper2();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("MA_{0}", item)));

                    await m_helper.RunHistory();
                }
                else if (runHelper == 3)
                {
                    EMATaticsHelper m_helper = new EMATaticsHelper();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("EMA_{0}", item)));

                    await m_helper.RunHistory();
                }
                else if (runHelper == 4)
                {
                    EMATaticsHelper2 m_helper = new EMATaticsHelper2();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("EMA2_{0}", item)));

                    await m_helper.RunHistory();
                }
                else if (runHelper == 5)
                {
                    EMAHelper3 m_helper = new EMAHelper3();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("EMA3_{0}", item)));

                    await m_helper.RunHistory();
                }
                else if (runHelper == 6)
                {
                    FourPriceHelper m_helper = new FourPriceHelper();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("FOUR_{0}", item)));

                    await m_helper.RunHistory();
                }
                else if (runHelper == 7)
                {
                    TurtleTaticsHelper m_helper = new TurtleTaticsHelper();
                    m_helper.Init(AppSetting.Ins.GetValue(string.Format("Turtle_{0}", item)));
                }
            }

            void WriteNext(JToken con)
            {
                if (con != null)
                {
                    Console.WriteLine(con);
                    WriteNext(con.Next);
                }
            }

            void WriteLast(JToken con)
            {
                if (con != null)
                {
                    Console.WriteLine(con);
                    WriteNext(con.Last);
                }
            }

            async void Result(string msg)
            {
                if (msg.Contains("success"))
                {
                    List <string> list = new List <string>();
                    list.Add("swap/account:BTC-USD-SWAP");
                    await web.Subscribe(list);
                }

                Console.WriteLine(msg);
            }
        }
Exemplo n.º 3
0
        private async void btnSubscribe(object sender, RoutedEventArgs e)
        {
            string channel_public = cleanTag(this.channel_public.Text), instType = cleanTag(this.instType_public.Text), instId = cleanTag(this.instId_public.Text), candlesSize = cleanTag(this.candle_public.Text),
                   uly = cleanTag(this.uly_public.Text), books_public = cleanTag(this.books_public.Text).Replace("books", ""), private_ccy = cleanTag(this.ccy_private.Text), private_instType = cleanTag(this.instType_private.Text),
                   private_uly = cleanTag(this.uly_private.Text), private_instId = cleanTag(this.instId_private.Text), channel_private = cleanTag(this.channel_private.Text), channel_order = cleanTag(this.channel_order.Text),
                   id_order = cleanTag(this.id_order.Text), instId_order = cleanTag(this.instId_order.Text), clOrdId_order = cleanTag(this.clOrdId_order.Text), tdMode_order = cleanTag(this.tdMode_order.Text),
                   ccy_order = cleanTag(this.ccy_order.Text), side_order = cleanTag(this.side_order.Text), ordType_order = cleanTag(this.ordType_order.Text), sz_order = cleanTag(this.sz_order.Text), posSide_order = cleanTag(this.posSide_order.Text),
                   tag_order = cleanTag(this.tag_order.Text), px_order = cleanTag(this.px_order.Text), reduceOnly_order = cleanTag(this.reduceOnly_order.Text), id_cancel = cleanTag(this.id_cancel.Text),
                   instId_cancel = cleanTag(this.instId_cancel.Text), ordId_cancel = cleanTag(this.ordId_cancel.Text), clOrdId_cancel = cleanTag(this.clOrdId_cancel.Text), instId_amend = cleanTag(this.instId_amend.Text),
                   ordId_amend = cleanTag(this.ordId_amend.Text), clOrdId_amend = cleanTag(this.clOrdId_amend.Text), cxlOnFail_amend = cleanTag(this.cxlOnFail_amend.Text), reqId_amend = cleanTag(this.reqId_amend.Text), newSz_amend = cleanTag(this.newSz_amend.Text),
                   newPx_amend = cleanTag(this.newPx_amend.Text), id_amend = cleanTag(this.id_amend.Text);
            Button btn      = (Button)sender;
            string btn_type = btn.Content.ToString();

            switch (btn_type)
            {
            case "订阅(public)":
                if (channel_public.Contains("books"))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_public + books_public);
                    Params.Add("instId", instId);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                else if (channel_public.Contains("candle"))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_public + candlesSize);
                    Params.Add("instId", instId);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                else if (list_instType.Contains(channel_public))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_public);
                    Params.Add("instType", instType);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                else if (list_instId.Contains(channel_public))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_public);
                    Params.Add("instId", instId);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                else if (list_instType_uly.Contains(channel_public))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_public);
                    Params.Add("instType", instType);
                    Params.Add("uly", uly);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                else if (list_uly.Contains(channel_public))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_public);
                    Params.Add("uly", uly);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                break;

            case "订阅(私有频道)":
                if (channel_private.Contains("account"))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_private);
                    Params.Add("ccy", private_ccy);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                else if (channel_private.Contains("positions") || channel_private.Contains("orders") || channel_private.Contains("orders-algo"))
                {
                    Dictionary <string, string> Params = new Dictionary <string, string>();
                    Params.Add("channel", channel_private);
                    Params.Add("instId", private_instId);
                    Params.Add("instType", private_instType);
                    Params.Add("uly", private_uly);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, string> >();
                    list_params.Add(context);
                    await websocketor.Subscribe(list_params);
                }
                break;

            case "订阅(交易)":
                if (channel_order == "order")
                {
                    Dictionary <string, object> Params = new Dictionary <string, object>();
                    Params.Add("instId", instId_order);
                    Params.Add("tdMode", tdMode_order);
                    Params.Add("ccy", ccy_order);
                    Params.Add("clOrdId", clOrdId_order);
                    Params.Add("tag", tag_order);
                    Params.Add("side", side_order);
                    Params.Add("posSide", posSide_order);
                    Params.Add("ordType", ordType_order);
                    Params.Add("sz", sz_order);
                    Params.Add("px", px_order);
                    Params.Add("reduceOnly", reduceOnly_order);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, object> >();
                    list_params.Add(context);
                    await websocketor.Subscribe_order(id_order, channel_order, list_params);
                }
                else if (channel_order == "batch-orders")
                {
                    var list_params = new List <Dictionary <string, object> >();
                    var _instIds    = instId_order.Split(',');
                    var _tdMode     = tdMode_order.Split(',');
                    var _ccy        = ccy_order.Split(',');
                    var _clOrdId    = clOrdId_order.Split(',');
                    var _tag        = tag_order.Split(',');
                    var _side       = side_order.Split(',');
                    var _posSide    = posSide_order.Split(',');
                    var _ordType    = ordType_order.Split(',');
                    var _sz         = sz_order.Split(',');
                    var _px         = px_order.Split(',');
                    var _reduceOnly = reduceOnly_order.Split(',');
                    for (int index = 0; index < _instIds.Length; index++)
                    {
                        Dictionary <string, object> Params = new Dictionary <string, object>();
                        Params.Add("instId", _instIds[index]);
                        Params.Add("tdMode", _tdMode.Length == _instIds.Length?_tdMode[index]:"");
                        Params.Add("ccy", _ccy.Length == _instIds.Length ? _ccy[index] : "");
                        Params.Add("clOrdId", _clOrdId.Length == _instIds.Length ? _clOrdId[index] : "");
                        Params.Add("tag", _tag.Length == _instIds.Length ? _tag[index] : "");
                        Params.Add("side", _side.Length == _instIds.Length ? _side[index] : "");
                        Params.Add("posSide", _posSide.Length == _instIds.Length ? _posSide[index] : "");
                        Params.Add("ordType", _ordType.Length == _instIds.Length ? _ordType[index] : "");
                        Params.Add("sz", _sz.Length == _instIds.Length ? _sz[index] : "");
                        Params.Add("px", _px.Length == _instIds.Length ? _px[index] : "");
                        Params.Add("reduceOnly", _reduceOnly.Length == _instIds.Length ? _reduceOnly[index] : "");
                        var context = cleanNullKey(Params);
                        list_params.Add(context);
                    }
                    await websocketor.Subscribe_order(id_order, channel_order, list_params);
                }
                else if (channel_order == "cancel-order")
                {
                    Dictionary <string, object> Params = new Dictionary <string, object>();
                    Params.Add("instId", instId_cancel);
                    Params.Add("ordId", ordId_cancel);
                    Params.Add("clOrdId", clOrdId_cancel);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, object> >();
                    list_params.Add(context);
                    await websocketor.Subscribe_order(id_cancel, channel_order, list_params);
                }
                else if (channel_order == "batch-cancel-orders")
                {
                    var list_params = new List <Dictionary <string, object> >();
                    var _instIds    = instId_cancel.Split(',');
                    var _clOrdId    = clOrdId_cancel.Split(',');
                    var _ordId      = ordId_cancel.Split(',');
                    for (int index = 0; index < _instIds.Length; index++)
                    {
                        Dictionary <string, object> Params = new Dictionary <string, object>();
                        Params.Add("instId", _instIds[index]);
                        Params.Add("ordId", _ordId.Length == _instIds.Length ? _ordId[index] : "");
                        Params.Add("clOrdId", _clOrdId.Length == _instIds.Length ? _clOrdId[index] : "");
                        var context = cleanNullKey(Params);
                        list_params.Add(context);
                    }
                    await websocketor.Subscribe_order(id_cancel, channel_order, list_params);
                }
                else if (channel_order == "amend-order")
                {
                    Dictionary <string, object> Params = new Dictionary <string, object>();
                    Params.Add("instId", instId_amend);
                    Params.Add("cxlOnFail", cxlOnFail_amend);
                    Params.Add("ordId", ordId_amend);
                    Params.Add("clOrdId", clOrdId_amend);
                    Params.Add("reqId", reqId_amend);
                    Params.Add("newSz", newSz_amend);
                    Params.Add("newPx", newPx_amend);
                    var context     = cleanNullKey(Params);
                    var list_params = new List <Dictionary <string, object> >();
                    list_params.Add(context);
                    await websocketor.Subscribe_order(id_amend, channel_order, list_params);
                }
                else if (channel_order == "batch-amend-orders")
                {
                    var list_params = new List <Dictionary <string, object> >();
                    var _instIds    = instId_amend.Split(',');
                    var _cxlOnFail  = cxlOnFail_amend.Split(',');
                    var _ordId      = ordId_amend.Split(',');
                    var _clOrdId    = clOrdId_amend.Split(',');
                    var _reqId      = reqId_amend.Split(',');
                    var _newSz      = newSz_amend.Split(',');
                    var _newPx      = newPx_amend.Split(',');
                    for (int index = 0; index < _instIds.Length; index++)
                    {
                        Dictionary <string, object> Params = new Dictionary <string, object>();
                        Params.Add("instId", _instIds[index]);
                        Params.Add("cxlOnFail", _cxlOnFail.Length == _instIds.Length ? _cxlOnFail[index] : "");
                        Params.Add("clOrdId", _clOrdId.Length == _instIds.Length ? _clOrdId[index] : "");
                        Params.Add("ordId", _ordId.Length == _instIds.Length ? _ordId[index] : "");
                        Params.Add("reqId", _reqId.Length == _instIds.Length ? _reqId[index] : "");
                        Params.Add("newSz", _newSz.Length == _instIds.Length ? _newSz[index] : "");
                        Params.Add("newPx", _newPx.Length == _instIds.Length ? _newPx[index] : "");
                        var context = cleanNullKey(Params);
                        list_params.Add(context);
                    }
                    await websocketor.Subscribe_order(id_amend, channel_order, list_params);
                }
                break;

            default:
                break;
            }
        }