Exemplo n.º 1
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;
        }
Exemplo n.º 2
0
        public bool Init()
        {
            bool bReturn = true;
            try
            {
                mtgoxV0.apiKey = MtGoxConfig.Key;
                mtgoxV0.apiSecret = MtGoxConfig.Secret;
                Currency = MtGoxConfig.Currency;
                userInfo = new UserInfo();
                userInfo.Currency = Currency;

                historyFund = new HistoryInfo();
                historyBtc = new HistoryInfo();
                currentHistory = mtgoxV0.info();
                if (currentHistory == null)
                {
                    bReturn = false;
                    return bReturn;
                }

                this.LoadHistory();
                this.loadUserInfo();
                this.loadOrders();
                tickerTimer = new System.Threading.Timer(GetRealtimeTrade, null, Consts.DefaultRefreshTime * 1000, Consts.DefaultRefreshTime * 1000);
                formTimer = new System.Threading.Timer(BindRealtimeTrade, null, Consts.DefaultRefreshTime * 1000 + System.DateTime.Now.Month * 100 + System.DateTime.Now.Year, Consts.DefaultRefreshTime * 1000);
                this.GetRealtimeTrade(null);
                this.BindUserInfo();
            }
            catch (Exception ex)
            {
                bReturn = false;
                Trace.WriteLine(string.Format("{0} \r\n stack:{1}", Utils.GetDetailedException(ex), Utils.GetStackTrace(ex)));
            }
            return bReturn;
        }