示例#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;
        }
示例#2
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List <MtGoxTrade> tradeListInOneMin, List <MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     if (tradeListInOneMin != null && tradeListInOneMin.Count >= 2)
     {
         return((tradeListInOneMin[0].price - ticker.last) * 100 / tradeListInOneMin[0].price > condition);
     }
     return(false);
 }
示例#3
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List <MtGoxTrade> tradeListInOneMin, List <MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     if (tradeListInOneMin != null)
     {
         double amount = 0;
         foreach (MtGoxTrade trade in tradeListInOneMin)
         {
             amount += trade.amount;
         }
         return(amount > condition);
     }
     return(false);
 }
示例#4
0
        /// <summary>
        /// 0/data/getDepth.php
        /// </summary>
        public MtGoxDepthInfo getDepth(MtGoxCurrencySymbol currency)
        {
            try
            {
                string url         = (this.baseURL) + "0/data/getDepth.php?currency=" + currency.ToString();
                string postData    = "";
                string responseStr = (new MtGoxNetTools()).DoAuthenticatedAPIPost(url, apiKey, apiSecret, postData);

                MtGoxDepthInfo returnValue = MtGoxDepthInfo.getObjects(responseStr);

                return(returnValue);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
示例#5
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 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);
        }
示例#7
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List <MtGoxTrade> tradeListInOneMin, List <MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     return(ticker.last < condition);
 }