Ejemplo n.º 1
0
        private void ForeachExchanges(Instrument instrument, Func <IExchange, IExchange, bool> action)
        {
            foreach (var ex1 in _exchanges.Values)
            {
                lock (ex1)
                {
                    if (!instrument.ContainsOrders(ex1))
                    {
                        continue;
                    }

                    foreach (var ex2 in ex1.Exchanges)
                    {
                        if (!instrument.ContainsOrders(ex2))
                        {
                            continue;
                        }

                        lock (ex2)
                        {
                            if (action(ex1, ex2))
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private bool TryToExchange(IExchange ex1, Instrument ins, out IExchange exBuy, out IExchange exSell)
        {
            var data = InitTransData(ins.GetBalanceStep(), ins);

            exBuy = null; exSell = null;

            foreach (var ex2 in ex1.Exchanges)
            {
                if (!ins.ContainsOrders(ex2))
                {
                    continue;
                }
                lock (ex2)
                {
                    if (ex1.TradingState == TradingState.NoCrypt)
                    {
                        if (ex2.TradingState == TradingState.NoUsd || ex2.TradingState == TradingState.Ok)
                        {
                            _profitRatios[ex2.GetExchangeName()] = _balance.GetProfitRatio(ex1, ex2, ins, data);
                        }
                    }
                    data.AskPrice1 = data.BidPrice2 = 0;
                }
            }
            if (_profitRatios.Count == 0)
            {
                return(false);
            }

            var min = _profitRatios.OrderBy(kvp => kvp.Value).First();
            var max = _profitRatios.OrderBy(kvp => kvp.Value).Last();

            _profitRatios.Clear();
            return(true);
        }
Ejemplo n.º 3
0
        public void HandlingOrder(Action <IExchange> createOrder,
                                  IExchange exchange,
                                  AutoResetEvent evt,
                                  Instrument ins,
                                  ExchangePricesEventArgs args)
        {
            var type = ins.GetOrderType(args);
            var ex   = exchange.GetExchangeName();

            if (SignAsRemoved(ex, type, args))
            {
                Lock(exchange, () =>
                {
                    SaveOrder(ex, type);
                    if (!args.IsOrderDeleted)
                    {
                        SaveOrder(ex, type, args.OrderId);
                        createOrder(exchange);

                        if (ins.ContainsOrders(exchange))
                        {
                            evt.Set();
                        }
                    }
                });
            }
        }