Exemplo 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;
        }
Exemplo n.º 2
0
 /// <summary>
 /// 0/ticker
 /// </summary>
 public MtGoxTickerItem ticker()
 {
     try
     {
         string url         = (this.baseURL) + "0/ticker.php";
         string postData    = "";
         string responseStr = (new MtGoxNetTools()).DoAuthenticatedAPIPost(url, apiKey, apiSecret, postData);
         return(MtGoxTickerItem.getObjects(responseStr));
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
        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);
        }
Exemplo n.º 4
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List <MtGoxTrade> tradeListInOneMin, List <MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     return(ticker.last < condition);
 }
Exemplo n.º 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);
 }
Exemplo n.º 6
0
 public bool ShouldExecute(MtGoxDepthInfo depth, List <MtGoxTrade> tradeListInOneMin, List <MtGoxTrade> tradeListInFiveMin, MtGoxTickerItem ticker, double condition)
 {
     if (tradeListInOneMin != null)
     {
         foreach (MtGoxTrade trade in tradeListInOneMin)
         {
             if (trade.amount > condition)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Exemplo n.º 7
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);
 }