Beispiel #1
0
        public static UserInfo ReadFromJObject(JObject o)
        {
            var r = new UserInfo
                {
                    Funds = Funds.ReadFromJObject(o["funds"] as JObject),
                    Rights = Rights.ReadFromJObject(o["rights"] as JObject),
                    TransactionCount = o.Value<int>("transaction_count"),
                    OpenOrders = o.Value<int>("open_orders"),
                    ServerTime = o.Value<int>("server_time")
                };

            return r;
        }
Beispiel #2
0
        private void Update(bool enabled, double period)
        {
            lock (this)
            {
                // Fetch live data from internet
                if (enabled)
                {
                    if (realtimeCandles.Count == 0)
                    {
                        UpdateStatus("Loading last 24 hours candles");
                        try
                        {
                            IList<OHLC> candles = GetCandlesFromBitcoincharts(DateTime.Now.Subtract(new TimeSpan(24, 0, 0)), period);
                            if (candles.Count == 0)
                                candles = ReadCandlesFromCSV(string.Format("realtime{0}.csv", pair.ToString()), DateTime.Now.Subtract(new TimeSpan(24, 0, 0)));

                            foreach (var candle in candles)
                                realtimeCandles.Add(candle);
                        }
                        catch (Exception)
                        {
                            UpdateStatus("Failed to get last 24 hours candles from Bitcoincharts");
                            Thread.Sleep(1000);
                        }
                    }

                    // First load history
                    if (realtimeCandles.Count > 0)
                    {
                        UpdateStatus("Fetching new data from BTC-e");
                        GetCandlesFromBtce(period);
                        SaveCandlesToCSV(realtimeCandles, string.Format("realtime{0}.csv", pair.ToString()));
                    }
                }

                try
                {
                    if (pair != BtcePair.Unknown)
                    {
                        //UpdateStatus("Updating BTC-e ticker and fees");
                        if (fee == 0m) fee = BtceApi.GetFee(pair);
                        ticker = BtceApi.GetTicker(pair);
                    }

                    if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(secret))
                    {
                        //UpdateStatus("Updating account informations");
                        BtceApi btceApi = new BtceApi(key, secret);
                        info = btceApi.GetInfo();
                    }
                    UpdateStatus("Ready...");
                }
                catch (Exception ex)
                {
                    UpdateStatus(string.Format("Error during Update: {0}", ex.Message));
                }

                //Depth btcusdDepth = BtceApi.GetDepth(BtcePair.btc_eur);
                //var transHistory = btceApi.GetTransHistory();
                //var tradeHistory = btceApi.GetTradeHistory(count: 20);
                //var orderList = btceApi.GetOrderList();
                //var tradeAnswer = btceApi.Trade(BtcePair.btc_eur, TradeType.Sell, 20, 0.1m);
                //var cancelAnswer = btceApi.CancelOrder(tradeAnswer.OrderId);
            }
        }