示例#1
0
        protected override void Init()
        {
            _symbolGraph = new BarMarketGraph(this)
            {
                Name = "Bar market graph"
            };
            _pathLogic = new PathLogic <CurrencyNode>(1000);
            foreach (var symbol in Symbols)
            {
                if (symbol.IsNull || !symbol.IsTradeAllowed)
                {
                    continue;
                }

                var barSymbol  = new BarSymbol(symbol, this);
                var commission = symbol.CalculateCommission(Account.Type, false);
                if (double.IsNaN(commission))
                {
                    commission = 0;
                }
                _symbolGraph.AddEdge(symbol.BaseCurrency, symbol.CounterCurrency, barSymbol, commission);
                _symbolGraph.AddEdge(symbol.CounterCurrency, symbol.BaseCurrency, barSymbol, commission);
            }

            _currencyId      = _symbolGraph[Currency]?.Id ?? -1;
            _currencyListIds = new List <int>();
            foreach (var currency in CurrencyList.ParseCsvLine())
            {
                var node = _symbolGraph[currency];
                if (node != null)
                {
                    _currencyListIds.Add(node.Id);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Adds edge to market graph finding required currencies
        /// </summary>
        public void AddEdge(string fromCurrency, string toCurrency, BarSymbol symbol, double commission, int pipsDigits)
        {
            if (!_currencyCache.ContainsKey(fromCurrency))
            {
                throw new GraphException($"Node {fromCurrency} not found");
            }
            if (!_currencyCache.ContainsKey(toCurrency))
            {
                throw new GraphException($"Node {toCurrency} not found");
            }

            AddEdge(new BarSymbolEdge(_currencyCache[fromCurrency], _currencyCache[toCurrency], symbol, commission, pipsDigits));
        }
示例#3
0
        public BarSymbolEdge(CurrencyNode from, CurrencyNode to, BarSymbol symbol, double commission, int pipsDigits) : base(from, to)
        {
            if (symbol.BaseCurrency != from.Name && symbol.CounterCurrency != from.Name)
            {
                throw new GraphException($"Node {from} doesn't correspond to symbol {symbol.Name}");
            }
            if (symbol.BaseCurrency != to.Name && symbol.CounterCurrency != to.Name)
            {
                throw new GraphException($"Node {to} doesn't correspond to symbol {symbol.Name}");
            }
            if (from.Name == to.Name)
            {
                throw new GraphException("Symbol edge can't be a loop");
            }

            Symbol     = symbol;
            Side       = symbol.BaseCurrency == from.Name && symbol.CounterCurrency == to.Name ? OrderSide.Sell : OrderSide.Buy;
            Commission = commission;
            PipsDigits = pipsDigits;
        }
示例#4
0
 public BarSymbolEdge(CurrencyNode from, CurrencyNode to, BarSymbol symbol, double commission) : this(from, to, symbol, commission, 0)
 {
 }
示例#5
0
 public BarSymbolEdge(CurrencyNode from, CurrencyNode to, BarSymbol symbol) : this(from, to, symbol, 0)
 {
 }
示例#6
0
 /// <summary>
 /// Adds edge to market graph finding required currencies
 /// </summary>
 public void AddEdge(string fromCurrency, string toCurrency, BarSymbol symbol, double commission)
 {
     AddEdge(fromCurrency, toCurrency, symbol, commission, 2);
 }
示例#7
0
 /// <summary>
 /// Adds edge to market graph finding required currencies
 /// </summary>
 public void AddEdge(string fromCurrency, string toCurrency, BarSymbol symbol)
 {
     AddEdge(fromCurrency, toCurrency, symbol, 0);
 }