示例#1
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);
        }
示例#2
0
        public void trade(OkexCoinType comm, OkexCoinType curr,
                          double price, double volume, OkexStockTradeType type,
                          StockTradeEntity.StockTradeEventHandler callback = null, long queryInterval = 1000)
        {
            StockTradeEntity entity = new StockTradeEntity(comm, curr, queryInterval);

            entity.setTradeEventHandler(callback);
            OkexStockTrader.Instance.tradeAsync(comm, curr, type, price, volume, entity.onAsyncCallback);
            m_stockEntityList.Add(entity);
        }
示例#3
0
        public OkexStockDepthData getDepthData(OkexCoinType commodity, OkexCoinType currency)
        {
            uint id = genID(commodity, currency);

            if (!m_depthData.ContainsKey(id))
            {
                return(null);
            }

            return(m_depthData[id]);
        }
示例#4
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);
        }
示例#5
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);
        }
示例#6
0
        public void subscribeInstrument(OkexCoinType commodity, OkexCoinType currency)
        {
            uint id = genID(commodity, currency);

            if (m_stockDataSubjects.ContainsKey(id))
            {
                return;
            }

            m_stockDataSubjects[id] = new OkexStockDataSubject(commodity, currency);

            StockDataUpdater sdu = new StockDataUpdater(commodity, currency);

            m_dataUpdaters.TryAdd(id, sdu);
            sdu.start();
        }
示例#7
0
        public OkexStockMarketData getMarketDataWithTimeLimit(OkexCoinType commodity, OkexCoinType currency, long limitMillisec)
        {
            OkexStockMarketData md = getMarketData(commodity, currency);

            if (md == null)
            {
                return(null);
            }

            long curTimestamp = DateUtil.getCurTimestamp();

            if (curTimestamp - md.receiveTimestamp - GlobalSetting.marketDataBias > limitMillisec)
            {
                return(null);
            }

            return(md);
        }
示例#8
0
        public void unsubscribeInstrument(OkexCoinType commodity, OkexCoinType currency)
        {
            uint id = genID(commodity, currency);

            if (!m_stockDataSubjects.ContainsKey(id))
            {
                return;
            }

            OkexStockDataSubject sbj;

            m_stockDataSubjects.TryRemove(id, out sbj);
            if (m_dataUpdaters.ContainsKey(id))
            {
                StockDataUpdater sdu = m_dataUpdaters[id];
                sdu.stop();
                m_dataUpdaters.TryRemove(id, out sdu);
            }
        }
示例#9
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);
        }
示例#10
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);
        }
示例#11
0
 // stock
 public static string getCoinName(OkexCoinType ct)
 {
     return(coinName[(int)ct]);
 }
示例#12
0
 public StockTradeEntity(OkexCoinType comm, OkexCoinType curr, long queryInterval = 1000) : base(queryInterval)
 {
     m_commodity = comm;
     m_currency  = curr;
 }
示例#13
0
 public OkexStockDataSubject(OkexCoinType commodity, OkexCoinType currency)
 {
     commodityCoin = commodity;
     currencyCoin  = currency;
 }
示例#14
0
 public StockDataUpdater(OkexCoinType comm, OkexCoinType curr)
 {
     m_commodityCoin = comm;
     m_currencyCoin  = curr;
 }
示例#15
0
        public void saveDepthData(OkexCoinType commodity, OkexCoinType currency, OkexStockDepthData depthData)
        {
            uint id = genID(commodity, currency);

            m_depthData[id] = depthData;
        }
示例#16
0
        public void saveMarketData(OkexCoinType commodity, OkexCoinType currency, OkexStockMarketData marketData)
        {
            uint id = genID(commodity, currency);

            m_marketData[id] = marketData;
        }
示例#17
0
        public static uint genID(OkexCoinType commodityCoin, OkexCoinType currencyCoin)
        {
            uint id = 100 * ((uint)commodityCoin + 1) + ((uint)currencyCoin + 1);

            return(id);
        }