Ejemplo n.º 1
0
        public void Initialize()
        {
            depth = new MtGoxDepthInfo();
            tradeListInFiveMin = new List<MtGoxTrade>();
            tradeListInOneMin = new List<MtGoxTrade>();
            ticker = new MtGoxTickerItem();

            for (int i = 0; i < 100; i++)
            {
                MtGoxAsk a = new MtGoxAsk();
                a.amount = i + 1;
                a.price = i + 1;
                depth.asks.Add(a);
                MtGoxBid b = new MtGoxBid();
                b.amount = i + 1;
                b.price = i + 1;
                depth.bids.Add(b);
                MtGoxTrade t = new MtGoxTrade();
                t.amount = i + 1;
                t.price = i + 1;
                tradeListInFiveMin.Add(t);
                tradeListInOneMin.Add(t);
            }
            ticker.last = 5;
        }
Ejemplo n.º 2
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List<MtGoxTrade> tradeListInOneMin, List<MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     if (tradeListInFiveMin != null)
     {
         double amount = 0;
         foreach (MtGoxTrade trade in tradeListInFiveMin)
         {
             amount += trade.amount;
         }
         return amount > condition;
     }
     return false;
 }
Ejemplo n.º 3
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List<MtGoxTrade> tradeListInOneMin, List<MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     if (depth != null && depth.bids.Count > 10)
     {
         double dAmount = 0;
         int index = 0;
         foreach (MtGoxBid bid in depth.bids)
         {
             if (++index > 10)
                 break;
             dAmount += bid.amount;
         }
         return dAmount > condition;
     }
     return false;
 }
        public static MtGoxTickerItem getObjects(string jsonDataStr)
        {
            string json       = jsonDataStr;
            var    serializer = new JavaScriptSerializer();

            serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
            dynamic         obj  = serializer.Deserialize(json, typeof(object));
            MtGoxTickerItem item = new MtGoxTickerItem();

            item.avg        = double.Parse(obj.ticker.avg.ToString());
            item.buy        = double.Parse(obj.ticker.buy.ToString());
            item.high       = double.Parse(obj.ticker.high.ToString());
            item.last       = double.Parse(obj.ticker.last.ToString());
            item.low        = double.Parse(obj.ticker.low.ToString());
            item.sell       = double.Parse(obj.ticker.sell.ToString());
            item.vol        = double.Parse(obj.ticker.vol.ToString());
            item.vwap       = double.Parse(obj.ticker.vwap.ToString());
            item.last_all   = double.Parse(obj.ticker.last_all.ToString());
            item.last_local = double.Parse(obj.ticker.last_local.ToString());
            return(item);
        }
Ejemplo n.º 5
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List<MtGoxTrade> tradeListInOneMin, List<MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     if (tradeListInFiveMin != null && tradeListInFiveMin.Count >= 2)
     {
         return (tradeListInFiveMin[0].price - ticker.last) * 100 / tradeListInFiveMin[0].price > condition;
     }
     return false;
 }
Ejemplo n.º 6
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List<MtGoxTrade> tradeListInOneMin, List<MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     return ticker.last < condition;
 }
Ejemplo n.º 7
0
        public bool ComputeNewOrders(MtGoxDepthInfo depth, List<MtGoxTrade> tradeListInOneMin, List<MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, UserInfo user, MtGoxAPIV0 api, List<AutoTradeSettings> autoTradeSettingsList)
        {
            try
            {
                double buyPrice = depth.asks[0].price + OrderTol;
                double sellPrice = depth.bids[0].price - OrderTol;
                int index = 0;
                foreach (AutoTradeSettings autoTrade in autoTradeSettingsList)
                {
                    index++;
                    if (autoTrade.Status == AutoTradeSettings.OrderStatus.Executed)
                        continue;
                    bool execute = false;

                    foreach (RuleSettings rule in autoTrade.Rules)
                    {
                        IAutoTradeRule tradeRule = AutoTradeRuleFactory.CreateAutoTradeRule(rule.RuleIndex);
                        if (tradeRule != null)
                        {
                            execute = tradeRule.ShouldExecute(depth, tradeListInOneMin, tradeListInFiveMin, ticker, rule.RuleCondition);
                            if (!execute)
                            {
                                break;
                            }
                        }
                    }
                    if (execute)
                    {
                        if (autoTrade.Warn)
                        {
                            try
                            {
                                SoundPlayer player = new SoundPlayer(Path.Combine(SoundFolder, autoTrade.Sound));
                                player.Play();
                            }
                            catch
                            {
                            }
                        }
                        if (autoTrade.Trade)
                        {
                            if (autoTrade.TradeType == AutoTradeSettings.OrderType.Sell)
                            {
                                List<MtGoxOrder> order = api.sellBTC(autoTrade.TradeAmount, user.Currency, sellPrice);
                            }
                            else
                            {
                                List<MtGoxOrder> order = api.buyBTC(autoTrade.TradeAmount, user.Currency, buyPrice);
                            }
                            autoTradeSettingsList[index - 1].ExecuteTime = System.DateTime.Now;
                            autoTradeSettingsList[index - 1].Status = AutoTradeSettings.OrderStatus.Executed;
                        }
                    }
                }

            }
            catch(Exception e)
            {
                throw;
            }
            return true;
        }
Ejemplo n.º 8
0
 public static MtGoxTickerItem getObjects(string jsonDataStr)
 {
     string json = jsonDataStr;
     var serializer = new JavaScriptSerializer();
     serializer.RegisterConverters(new[] { new DynamicJsonConverter() });
     dynamic obj = serializer.Deserialize(json, typeof(object));
     MtGoxTickerItem item = new MtGoxTickerItem();
     item.avg = double.Parse(obj.ticker.avg.ToString());
     item.buy = double.Parse(obj.ticker.buy.ToString());
     item.high = double.Parse(obj.ticker.high.ToString());
     item.last = double.Parse(obj.ticker.last.ToString());
     item.low = double.Parse(obj.ticker.low.ToString());
     item.sell = double.Parse(obj.ticker.sell.ToString());
     item.vol = double.Parse(obj.ticker.vol.ToString());
     item.vwap = double.Parse(obj.ticker.vwap.ToString());
     item.last_all = double.Parse(obj.ticker.last_all.ToString());
     item.last_local = double.Parse(obj.ticker.last_local.ToString());
     return item;
 }
Ejemplo n.º 9
0
 private void GetRealtimeTrade(object state)
 {
     try
     {
         tickerTimer.Change(int.MaxValue, int.MaxValue);
         currentInfo = mtgoxV0.getDepth(Currency);
         currentTicker = mtgoxV0.ticker();
         DateTime fiveMinuteAgo = System.DateTime.Now - TimeSpan.FromMinutes(5);
         string tidFive = getJasonDate(fiveMinuteAgo) + "000000";
         currenttradeListInFiveMin = mtgoxV0.getTrades(tidFive);
         DateTime oneMinuteAgo = System.DateTime.Now - TimeSpan.FromMinutes(1);
         string tidOne = getJasonDate(oneMinuteAgo) + "000000";
         currenttradeListInOneMin = mtgoxV0.getTrades(tidOne);
         executeAutoTrade();
     }
     catch(Exception ex)
     {
         Trace.WriteLine(string.Format("{0} \r\n stack:{1}", Utils.GetDetailedException(ex), Utils.GetStackTrace(ex)));
     }
     finally
     {
         tickerTimer.Change(lastRefreshTime * 1000, lastRefreshTime * 1000);
         formEvent.Set();
     }
 }
Ejemplo n.º 10
0
        private void btnSell_Click(object sender, EventArgs e)
        {
            double price = 0;
            double amount = 0;
            try
            {
                amount = Double.Parse(this.txtSellCount.Text.Trim());
                price = Double.Parse(this.txtSellPrice.Text.Trim());
                if (this.comboSellType.SelectedIndex == 0)
                {

                }
                else
                {
                    if (this.comboSellType.SelectedIndex == 1)
                    {
                        currentTicker = mtgoxV0.ticker();
                        price = currentTicker.buy - Consts.MarketTol;
                    }
                    else if (this.comboSellType.SelectedIndex == 2)
                    {
                        StopOrder stopOrder = new StopOrder();
                        stopOrder.Amount = amount;
                        stopOrder.Currency = Currency;
                        stopOrder.OrderTime = System.DateTime.Now;
                        stopOrder.Price = price;
                        stopOrder.Status = StopOrder.OrderStatus.Pending;
                        stopOrder.Type = StopOrder.OrderType.SellStop;
                        this.stopOrderList.Add(stopOrder);
                        Utils.SaveToFile(this.stopOrderList, this.stopOrderFullPath);
                        return;
                    }
                }

            }
            catch
            {
                MessageBox.Show(ResourceFactory.GetString("InputError"), ResourceFactory.GetString("InputError"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            List<MtGoxOrder> order = mtgoxV0.sellBTC(amount, Currency, price);
            if (order != null)
            {
                MessageBox.Show(ResourceFactory.GetString("OrderSucceed"), ResourceFactory.GetString("OrderSucceed"), MessageBoxButtons.OK);
            }
        }
Ejemplo n.º 11
0
        private void btnBuy_Click(object sender, EventArgs e)
        {
            double price = 0;
            double amount = 0;

            try
            {
                if (this.comboBuyType.SelectedIndex == 0)
                {
                    price = Double.Parse(this.txtBuyPrice.Text.Trim());
                }
                else
                {
                    currentTicker = mtgoxV0.ticker();
                    price = currentTicker.sell + Consts.MarketTol;
                }
                amount = Double.Parse(this.txtBuyCount.Text.Trim());
            }
            catch(Exception ex)
            {
                MessageBox.Show(ResourceFactory.GetString("InputError"), ResourceFactory.GetString("InputError"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            List<MtGoxOrder> order = mtgoxV0.buyBTC(amount, Currency, price);
            if (order != null)
            {
                MessageBox.Show(ResourceFactory.GetString("OrderSucceed"), ResourceFactory.GetString("OrderSucceed"), MessageBoxButtons.OK);
            }
        }