Exemplo n.º 1
0
        // 账户信息
        public bool getUserInfo(out Dictionary <OkexFutureInstrumentType, OkexAccountInfo> info)
        {
            string  str    = postRequest.future_userinfo_4fix();
            JObject jo     = (JObject)JsonConvert.DeserializeObject(str);
            bool    result = (bool)jo["result"];

            info = new Dictionary <OkexFutureInstrumentType, OkexAccountInfo>();

            if (result == true)
            {
                for (int i = 0; i <= (int)OkexFutureInstrumentType.FI_BCH; i++)
                {
                    OkexFutureInstrumentType fi    = (OkexFutureInstrumentType)i;
                    string          instrumentName = OkexDefValueConvert.getCoinName(fi);
                    OkexAccountInfo ai             = new OkexAccountInfo();
                    ai.balance = (double)jo["info"][instrumentName]["balance"];
                    ai.rights  = (double)jo["info"][instrumentName]["rights"];
                    JArray arr = JArray.Parse(jo["info"][instrumentName]["contracts"].ToString());
                    foreach (var item in arr)
                    {
                        OkexContractInfo ci = (OkexContractInfo)JsonConvert.DeserializeObject(item.ToString(), typeof(OkexContractInfo));
                        ai.contractsInfo.Add(ci);
                    }
                    info.Add(fi, ai);
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        public void cancelAysnc(OkexCoinType commodity, OkexCoinType currency,
                                string orderID,
                                HttpAsyncReq.ResponseCallback callback)
        {
            string c0     = OkexDefValueConvert.getCoinName(commodity);
            string c1     = OkexDefValueConvert.getCoinName(currency);
            string symbol = c0 + "_" + c1;

            postRequest.cancelOrderAsync(symbol, orderID, callback);
        }
Exemplo n.º 3
0
        public void tradeAsync(OkexCoinType commodity, OkexCoinType currency,
                               OkexStockTradeType tradeType, double price, double amount,
                               HttpAsyncReq.ResponseCallback callback)
        {
            string c0      = OkexDefValueConvert.getCoinName(commodity);
            string c1      = OkexDefValueConvert.getCoinName(currency);
            string symbol  = c0 + "_" + c1;
            string strType = OkexDefValueConvert.getStockTradeTypeStr(tradeType);

            postRequest.tradeAsync(symbol, strType, price.ToString(), amount.ToString(), callback);
        }
Exemplo n.º 4
0
        public OkexStockMarketData getStockMarketData(OkexCoinType commodityCoin, OkexCoinType currencyCoin)
        {
            string              c0  = OkexDefValueConvert.getCoinName(commodityCoin);
            string              c1  = OkexDefValueConvert.getCoinName(currencyCoin);
            string              str = getRequest.ticker(c0 + "_" + c1);
            JObject             jo  = (JObject)JsonConvert.DeserializeObject(str);
            OkexStockMarketData md  = JsonConvert.DeserializeObject <OkexStockMarketData>(jo["ticker"].ToString());

            md.timestamp        = long.Parse((string)jo["date"]);
            md.receiveTimestamp = DateUtil.getCurTimestamp();
            return(md);
        }
Exemplo n.º 5
0
        public bool getOrderInfoByID(OkexCoinType commodity, OkexCoinType currency, long orderID, out OkexStockOrderBriefInfo info)
        {
            string  c0     = OkexDefValueConvert.getCoinName(commodity);
            string  c1     = OkexDefValueConvert.getCoinName(currency);
            string  symbol = c0 + "_" + c1;
            string  str    = postRequest.order_info(symbol, orderID.ToString());
            JObject jo     = (JObject)JsonConvert.DeserializeObject(str);
            bool    ret    = (bool)jo["result"];

            info = new OkexStockOrderBriefInfo();
            if (ret)
            {
                JArray arr = JArray.Parse(jo["orders"].ToString());
                foreach (var item in arr)
                {
                    info.amount       = (double)item["amount"];
                    info.price        = (double)item["price"];
                    info.createDate   = (string)item["create_date"];
                    info.avgDealPrice = (double)item["avg_price"];
                    info.dealAmount   = (double)item["deal_amount"];
                    string strType = (string)item["type"];
                    info.tradeType = OkexDefValueConvert.parseStockTradeType(strType);

                    int nStatus = int.Parse((string)item["status"]);
                    if (nStatus == 3)
                    {
                        nStatus = 4;
                    }
                    info.status  = (OkexOrderStatusType)nStatus;
                    info.orderID = (long)item["order_id"];

                    info.commodity = commodity;
                    info.currency  = currency;

                    break;
                }
            }
            return(ret);
        }
Exemplo n.º 6
0
        public OkexStockDepthData getStockDepthData(OkexCoinType commodityCoin, OkexCoinType currencyCoin, uint size = 10)
        {
            string             c0 = OkexDefValueConvert.getCoinName(commodityCoin);
            string             c1 = OkexDefValueConvert.getCoinName(currencyCoin);
            OkexStockDepthData dd = new OkexStockDepthData();

            dd.sendTimestamp = DateUtil.getCurTimestamp();
            string str = getRequest.depth(c0 + "_" + c1, size.ToString());

            JObject jo     = (JObject)JsonConvert.DeserializeObject(str);
            JArray  bidArr = JArray.Parse(jo["bids"].ToString());
            JArray  askArr = JArray.Parse(jo["asks"].ToString());
            int     count  = Math.Min(bidArr.Count, 10);

            for (int i = 0; i < count; i++)
            {
                JArray ordArr = JArray.Parse(bidArr[i].ToString());
                double p      = (double)ordArr[0];
                double v      = (double)ordArr[1];
                dd.bids[i].price  = p;
                dd.bids[i].volume = v;
            }

            count = Math.Min(askArr.Count, 10);
            int last = askArr.Count - 1;

            for (int i = 0; i < count; i++)
            {
                JArray ordArr = JArray.Parse(askArr[last - i].ToString());
                double p      = (double)ordArr[0];
                double v      = (long)ordArr[1];
                dd.asks[i].price  = p;
                dd.asks[i].volume = v;
            }
            return(dd);
        }