Exemplo n.º 1
0
        /// <summary>
        /// To calculate commission.
        /// </summary>
        /// <param name="message">The message containing the information about the order or own trade.</param>
        /// <returns>The commission. If the commission can not be calculated then <see langword="null" /> will be returned.</returns>
        protected override decimal?OnProcessExecution(ExecutionMessage message)
        {
            if (message.HasOrderInfo())
            {
                return((decimal)(message.OrderVolume * Value));
            }

            return(null);
        }
Exemplo n.º 2
0
        /// <inheritdoc />
        protected override decimal?OnProcessExecution(ExecutionMessage message)
        {
            if (message.HasOrderInfo())
            {
                return(GetValue(message.OrderPrice));
            }

            return(null);
        }
            public void Process(ExecutionMessage message)
            {
                if (!message.HasOrderInfo())
                {
                    throw new ArgumentException(nameof(message));
                }

                var key = Tuple.Create(message.Side, message.OrderPrice);

                switch (message.OrderState)
                {
                case OrderStates.Done:
                case OrderStates.Failed:
                {
                    var items = _executions.TryGetValue(key);

                    if (items == null)
                    {
                        break;
                    }

                    items.Remove(message.OriginalTransactionId);

                    if (items.Count == 0)
                    {
                        _executions.Remove(key);
                    }

                    break;
                }

                case OrderStates.Active:
                {
                    if (message.Balance != null)
                    {
                        _executions.SafeAdd(key)[message.OriginalTransactionId] = message.Balance.Value;
                    }

                    break;
                }
                }

                if (_executions.ContainsKey(key))
                {
                    _ownVolumes[key] = _executions[key].Sum(o => o.Value);
                }
                else
                {
                    _ownVolumes.Remove(key);
                }
            }
Exemplo n.º 4
0
        /// <summary>
        /// To calculate commission.
        /// </summary>
        /// <param name="message">The message containing the information about the order or own trade.</param>
        /// <returns>The commission. If the commission can not be calculated then <see langword="null" /> will be returned.</returns>
        protected override decimal?OnProcessExecution(ExecutionMessage message)
        {
            if (!message.HasOrderInfo())
            {
                return(null);
            }

            if (++_currentCount < Count)
            {
                return(null);
            }

            _currentCount = 0;
            return((decimal)Value);
        }
		private void ProcessTransactionMessage(Order order, Security security, ExecutionMessage message, long transactionId)
		{
			var processed = false;

			if (message.HasOrderInfo())
			{
				processed = true;
				ProcessOrderMessage(order, security, message, transactionId);
			}

			if (message.HasTradeInfo())
			{
				processed = true;
				ProcessMyTradeMessage(order, security, message, transactionId);
			}

			if (!processed)
				throw new ArgumentOutOfRangeException(LocalizedStrings.Str1695Params.Put(message.ExecutionType));
		}
            public void Process(ExecutionMessage message)
            {
                if (!message.HasOrderInfo())
                {
                    throw new ArgumentException(nameof(message));
                }

                // ignore market orders
                if (message.OrderPrice == 0)
                {
                    return;
                }

                // ignore unknown orders
                if (message.OriginalTransactionId == 0)
                {
                    return;
                }

                var key = Tuple.Create(message.Side, message.OrderPrice);

                switch (message.OrderState)
                {
                case OrderStates.Done:
                case OrderStates.Failed:
                {
                    var pair = _executions.TryGetValue(key);

                    if (pair == null)
                    {
                        break;
                    }

                    var balance = pair.First.TryGetAndRemove(message.OriginalTransactionId);

                    if (pair.First.Count == 0)
                    {
                        _executions.Remove(key);
                    }
                    else
                    {
                        pair.Second -= balance;
                    }

                    break;
                }

                case OrderStates.Active:
                {
                    var balance = message.Balance;

                    if (balance != null)
                    {
                        var pair = _executions.SafeAdd(key, k => RefTuple.Create(new Dictionary <long, decimal>(), 0M));

                        var prev = pair.First.TryGetValue(message.OriginalTransactionId);

                        pair.First[message.OriginalTransactionId] = balance.Value;
                        pair.Second += balance.Value - prev;
                    }

                    break;
                }
                }
            }