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); }
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); }
public OkexStockDepthData getDepthData(OkexCoinType commodity, OkexCoinType currency) { uint id = genID(commodity, currency); if (!m_depthData.ContainsKey(id)) { return(null); } return(m_depthData[id]); }
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); }
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); }
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(); }
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); }
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); } }
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); }
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); }
// stock public static string getCoinName(OkexCoinType ct) { return(coinName[(int)ct]); }
public StockTradeEntity(OkexCoinType comm, OkexCoinType curr, long queryInterval = 1000) : base(queryInterval) { m_commodity = comm; m_currency = curr; }
public OkexStockDataSubject(OkexCoinType commodity, OkexCoinType currency) { commodityCoin = commodity; currencyCoin = currency; }
public StockDataUpdater(OkexCoinType comm, OkexCoinType curr) { m_commodityCoin = comm; m_currencyCoin = curr; }
public void saveDepthData(OkexCoinType commodity, OkexCoinType currency, OkexStockDepthData depthData) { uint id = genID(commodity, currency); m_depthData[id] = depthData; }
public void saveMarketData(OkexCoinType commodity, OkexCoinType currency, OkexStockMarketData marketData) { uint id = genID(commodity, currency); m_marketData[id] = marketData; }
public static uint genID(OkexCoinType commodityCoin, OkexCoinType currencyCoin) { uint id = 100 * ((uint)commodityCoin + 1) + ((uint)currencyCoin + 1); return(id); }