Example #1
0
        /// <summary>
        /// Initializes a new instance of the SoftFX.Extended.Financial.StateInfoEventArgs
        /// </summary>
        /// <param name="info">Represents the current state.</param>
        public StateInfoEventArgs(StateInfo info)
        {
            if (info == null)
                throw new ArgumentNullException("info");

            this.Information = info;
        }
Example #2
0
File: Snapshot.cs Project: ifzz/FDK
        void Update(StateInfo info)
        {
            var accountInfo = this.AccountInfo;
            var positions = new Dictionary<string, Position>();
            var tradeRecords = new List<TradeRecord>();

            if (accountInfo != null)
            {
                var newAccountInfo = new AccountInfo
                {
                    Leverage = accountInfo.Leverage,
                    Currency = accountInfo.Currency,
                    AccountId = accountInfo.AccountId,
                    Type = accountInfo.Type,
                    MarginCallLevel = accountInfo.MarginCallLevel,
                    StopOutLevel = accountInfo.StopOutLevel,

                    Balance = info.Equity,
                    Margin = info.Margin,
                    Equity = info.Equity
                };
                accountInfo = newAccountInfo;


                foreach (var element in info.Positions)
                {
                    positions.Add(element.Symbol, element);

                    var volume = element.BuyAmount - element.SellAmount;
                    if (volume != 0.0)
                    {
                        var record = new TradeRecord
                        {
                            Symbol = element.Symbol,
                            Volume = Math.Abs(volume),
                            OrderId = this.VirtualOrderIdFromSymbol(element.Symbol),
                            Type = TradeRecordType.Position
                        };
                        if (volume >= 0)
                        {
                            record.Side = TradeRecordSide.Buy;
                            record.Price = element.BuyPrice ?? Math.Abs(element.SettlementPrice);
                        }
                        else
                        {
                            record.Side = TradeRecordSide.Sell;
                            record.Price = element.SellPrice ?? Math.Abs(element.SettlementPrice);
                        }
                        
                        record.Price = Math.Abs(element.SettlementPrice);
                        tradeRecords.Add(record);
                    }
                }
                tradeRecords.AddRange(info.TradeRecords);
            }

            lock (this.synchronizer)
            {
                this.AccountInfo = accountInfo;
                this.TradeRecords = tradeRecords;
                this.Positions = positions;

                foreach (var element in info.Prices)
                {
                    Quote quote;
                    if (!info.Quotes.TryGetValue(element.Key, out quote))
                        continue;

                    this.Quotes[element.Key] = new Quote(element.Key, quote.CreatingTime, element.Value.Bid, element.Value.Ask);
                }
            }

            this.syncEvent.Set();
        }