public KrakenOrder(KrakenGetOrderRecord record) { Pair = record.Descr.Pair; Type = record.Descr.Type; OrderType = record.Descr.Ordertype; Price = Convert.ToDecimal(record.Descr.Price); Volume = Convert.ToDecimal(record.Vol); Opened = UnixTime.ConvertToDateTime((UInt32)(record.Opentm)); Status = record.Status; }
public static KrakenTime ReadFromJObject(JObject o) { if (o == null) { return(null); } return(new KrakenTime { Time = UnixTime.ConvertToDateTime(o.Value <UInt32>("unixtime")), Rfc1123 = o.Value <string>("rfc1123") }); }
public static TradeInfoV3 ReadFromJObject(JObject o) { if (o == null) { return(null); } return(new TradeInfoV3() { Amount = o.Value <decimal>("amount"), Price = o.Value <decimal>("price"), Timestamp = UnixTime.ConvertToDateTime(o.Value <UInt32>("timestamp")), Tid = o.Value <UInt32>("tid"), Type = TradeInfoTypeHelper.FromString(o.Value <string>("type")) }); }
public static TradeInfo ReadFromJObject(JObject o) { if (o == null) { return(null); } return(new TradeInfo() { Amount = o.Value <decimal>("amount"), Price = o.Value <decimal>("price"), Date = UnixTime.ConvertToDateTime(o.Value <UInt32>("date")), Item = BtceCurrencyHelper.FromString(o.Value <string>("item")), PriceCurrency = BtceCurrencyHelper.FromString(o.Value <string>("price_currency")), Tid = o.Value <UInt32>("tid"), Type = TradeInfoTypeHelper.FromString(o.Value <string>("trade_type")) }); }
public override DateTime GetHuobiTime() { Ticker ticker = BtceApi.GetTicker(BtcePair.btc_usd); return(UnixTime.ConvertToDateTime(ticker.ServerTime)); }
/// <summary> /// /// </summary> /// <param name="o"></param> /// <returns></returns> protected bool CancelOrder(HuobiOrder o) { bool traded = false; try { HuobiSimpleResult cancelResult = m_huobi.CancelOrder(m_market, o.id); } catch (HuobiException e) { // ignore order which have been filled, or cancelled if (e.m_error.code != 41 && e.m_error.code != 42) { throw; } else { if (e.m_error.code == 41) { // not found, so filled m_renderer.AddMarker(o.type == HuobiOrderType.buy, true, o.order_price, UnixTime.ConvertToDateTime(o.order_time)); traded = true; } m_lastOpenOrders.RemoveAll(loo => loo.id == o.id); } } return(traded); }
static void Main() { // attach graph renderer Rendering renderer = new Rendering(800, 400); long lastTradeId = -1; var marketAccesses = JsonConvert.DeserializeObject <List <MarketAccess> >(File.ReadAllText("accessKeys.txt")); var huobiAccess = marketAccesses.First(e => e.Name == "Huobi"); var btceAccess = marketAccesses.First(e => e.Name == "BTCE"); IMarket huobi = new Huobi(huobiAccess.AccessKey, huobiAccess.SecretKey); //huobi = new BTCeMarket(btceAccess.AccessKey, btceAccess.SecretKey); AlgoBase alogo = new NaiveMarketMaker(huobi, HuobiMarket.btc, renderer); BcwTrade lastTrade = null; TimeSpan timeOffset = new TimeSpan(); DateTime lastTime = new DateTime(); while (true) { try { List <BcwTrade> newTrades = huobi.GetPublicTrades(BcwMarket.huobibtccny, lastTradeId); newTrades.Reverse(); HuobiMarketSummary depth = huobi.GetMarketSummary(HuobiMarket.btc); BcwTicker ticker = huobi.GetTicker(BcwMarket.huobibtccny); DateTime now = UnixTime.ConvertToDateTime(ticker.date) + timeOffset; if (newTrades.Count > 0) { if (timeOffset.TotalSeconds == 0) { DateTime firstTradeDate = UnixTime.ConvertToDateTime(newTrades[0].date); if (firstTradeDate < lastTime) { timeOffset = firstTradeDate - lastTime; } } foreach (BcwTrade t in newTrades) { if (t.trade_type == BcwOrderType.ask) { // this condition means that a BUY ORDER was filled } else { // this condition means that a SELL ORDER was filled } renderer.AddDataPoint(depth.GetBidPrice(0), depth.GetAskPrice(0), t.price, UnixTime.ConvertToDateTime(t.date)); } lastTrade = newTrades.Last(); lastTradeId = newTrades.Last().tid; now = UnixTime.ConvertToDateTime(lastTrade.date); } else { renderer.AddDataPoint(depth.GetBidPrice(0), depth.GetAskPrice(0), lastTrade.price, now); } // // update the algorithm // alogo.Update(now); } catch (HuobiApi.RetryCountExceededException) { } catch (Newtonsoft.Json.JsonReaderException e) { Console.WriteLine(e.ToString()); } Thread.Sleep(5000); } }