Пример #1
0
        /// <summary>
        /// 获取我的24小时内成交记录
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public static async Task <List <MyTradeHistory> > MyTradeHistoryAsync(MyTradeHistoryReq req)
        {
            try
            {
                var requestUrl = TRADE_URL + MY_TRADE_HISTORY_URL;

                var form = new Dictionary <string, string>();
                form.Add("currencyPair", req.CurrencyPair);
                form.Add("orderNumber", req.OrderNo);

                var json = await PostReqAsync(requestUrl, form);


                var parse = JToken.Parse(json) as dynamic;
                if (parse.result == "true")
                {
                    return(parse.trades.ToObject <List <MyTradeHistory> >());
                }
                else
                {
                    var code    = parse.code.ToString();
                    var message = parse.message.ToString();

                    throw new BotException(code, message);
                }
            }
            catch (JsonSerializationException)
            {
                throw new BotException("1002");
            }
            catch (Exception ex)
            {
                throw new BotException("1000", ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// 匹配数据库
        /// </summary>
        private async void PiPei()
        {
            var blance = await gateio.api.API.GetBalancesAsync();

            blance.Available.Remove("USDT");                                        //去除usdt
            var blancelist = blance.Available.Where(S => S.Value > 0.01m).ToList(); //去除小余0.01的币种

            foreach (var item in blancelist)
            {
                MyTradeHistoryReq req = new MyTradeHistoryReq();
                req.CurrencyPair = item.Key + "_USDT";

                var order = await gateio.api.API.MyTradeHistoryAsync(req);

                order = order.Where(S => S.Type == "buy").ToList();         //只看买的

                order = order.Where(S => S.Rate * item.Value > 1).ToList(); // 去除金额小于1usdt的币种

                if (order.Count == 0)
                {
                    continue;
                }

                OrderReq model = new OrderReq();

                //如果只有一条直接插入
                if (order.Count == 1)
                {
                    model.Amount = order[0].Amount;
                    model.Rate   = order[0].Rate;

                    if (model.Amount != item.Value)
                    {
                        model.Amount = item.Value;
                    }
                    model.CurrencyPair = req.CurrencyPair;
                    InsertDataBase(model, string.Empty);

                    continue;
                }



                decimal count = order.Sum(S => S.Amount);

                decimal total = order.Sum(S => S.Rate * S.Amount);


                model.Amount = count;
                if (model.Amount != item.Value)
                {
                    model.Amount = item.Value;
                }
                model.Rate         = total / count;
                model.CurrencyPair = req.CurrencyPair;

                InsertDataBase(model, string.Empty);
            }


            this.dataGridView1.DataSource = CheckOrder();
        }