Esempio n. 1
0
        private void HandleTradesCallBack(string result)
        {
            var webResult = JObject.Parse(result);

            foreach (var pair in configuration.Pairs)
            {
                if (!PairTrades.ContainsKey(pair))
                {
                    PairTrades.Add(pair, new List <IMarketTrade>());
                }

                foreach (var trade in webResult[BtcePairHelper.ToString(pair)])
                {
                    var newTrade = new MarketTrade
                    {
                        Pair      = pair,
                        TradeId   = trade["tid"].Value <int>(),
                        Amount    = trade["amount"].Value <decimal>(),
                        Rate      = trade["price"].Value <decimal>(),
                        Timestamp = UnixTimeHelper.UnixTimeToDateTime(trade["timestamp"].Value <UInt32>())
                    };

                    if (PairTrades[pair].Find(a => a.TradeId == newTrade.TradeId) == null)
                    {
                        PairTrades[pair].Add(newTrade);
                    }
                }
            }

            /*
             * foreach (var tradeItem in webResult["return"].Value<JObject>())
             *  {
             *      var newTrade = new MarketTrade
             *          {
             *              Pair =  BtcePairHelper.FromString(tradeItem.Value["pair"].Value<string>()),
             *              TradeType = TradeTypeHelper.FromString(tradeItem.Value["type"].Value<string>()),
             *              Amount = tradeItem.Value["amount"].Value<decimal>(),
             *              Rate = tradeItem.Value["rate"].Value<decimal>(),
             *              OrderId = tradeItem.Value["order_id"].Value<int>(),
             *              YourOrder = tradeItem.Value["is_your_order"].Value<string>(),
             *              TimeStamp = UnixTimeHelper.UnixTimeToDateTime(tradeItem.Value["timestamp"].Value<UInt32>())
             *          };
             *
             *      if (!PairTrades.ContainsKey(newTrade.Pair))
             *          PairTrades.Add(newTrade.Pair, new List<IMarketTrade>());
             *
             *      if (PairTrades[newTrade.Pair].Find(a => a.OrderId == newTrade.OrderId) == null)
             *          PairTrades[newTrade.Pair].Add(newTrade);
             *  }*/


            OnPropertyChanged("PairTrades");

            if (MarketTradesUpdated != null)
            {
                MarketTradesUpdated(this, null);
            }

            LogApiMessage("Api message processed", "Market trades updated");
        }
Esempio n. 2
0
        static void TestGetMarketTrade()
        {
            MarketTrade marketTrade = Api.GetMarketTrade("ethbtc", 20);

            if (marketTrade == null)
            {
                Console.WriteLine("GetMarketTrade Failed!");
                return;
            }

            Console.WriteLine("GetMarketTrade Succeed:");
            Console.WriteLine("  symbol = {0}", marketTrade.symbol);
            for (int i = 0; i < marketTrade.trade_data.Count; i++)
            {
                MarketTrade.Item item = marketTrade.trade_data[i];
                Console.WriteLine("  {0}.\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}",
                                  i + 1,
                                  item.id,
                                  item.side,
                                  item.price,
                                  item.vol,
                                  item.amount,
                                  item.ts,
                                  item.ds);
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Constructor for UserViewModel
 /// </summary>
 public UserViewModel()
 {
     _DefaultUser        = new User();
     _DefaultMarket      = new MarketTrade();
     UpdateCommand       = new UserUpdateCommand(this);
     AuthenticateCommand = new AuthenticateCommand(this);
     LimitBuyCommand     = new LimitBuyCommand(this);
     LimitSellCommand    = new LimitSellCommand(this);
 }
Esempio n. 4
0
        public IncomingMessage Visit(Mantle.Fix44.MarketDataResponse msg)
        {
            var res = new IncomingMessage();

            res.SendingTime = msg.StandardHeader.SendingTime.Value;
            if (msg.OrigTime.HasValue)
            {
                res.MarketData.Value.ServerTime = msg.OrigTime.Value;
            }
            else if (msg.StandardHeader.SendingTime.HasValue)
            {
                res.MarketData.Value.ServerTime = msg.StandardHeader.SendingTime.Value;
            }
            else
            {
                _log.Warn("MarketDataResponse is missing OrigTime and SendingTime fields: {0}", msg);
                return(null);
            }
            if (!msg.Instrument.Symbol.HasValue)
            {
                _log.Warn("MarketDataResponse is missing Symbol field: {0}", msg);
                return(null);
            }
            res.MarketData.Value.Symbol = msg.Instrument.Symbol.Value;
            foreach (Mantle.Fix44.MDEntry entry in msg.MDEntries)
            {
                string      error;
                MarketOrder order = MakeOrder(entry, out error);
                if (order != null)
                {
                    if (res.MarketData.Value.Snapshot == null)
                    {
                        res.MarketData.Value.Snapshot = new List <MarketOrder>();
                    }
                    res.MarketData.Value.Snapshot.Add(order);
                    continue;
                }
                if (error != null)
                {
                    _log.Warn("{0}: {1}", error, msg);
                    continue;
                }
                // ServerTime was already set above.
                MarketTrade trade = MakeTrade(res.MarketData.Value.ServerTime, entry, out error);
                if (trade != null)
                {
                    if (res.MarketData.Value.Trades == null)
                    {
                        res.MarketData.Value.Trades = new List <MarketTrade>();
                    }
                    res.MarketData.Value.Trades.Add(trade);
                    continue;
                }
                _log.Warn("Ignoring MDEntry of unkonwn format: {0}", msg);
            }
            return(res);
        }
Esempio n. 5
0
        // Three possible outcomes:
        // - Result is not null. That's success. In this case error is guaranteed to be null.
        // - Result is null, error is null. It means the entry isn't a trade. Not an error.
        // - Result is null, error is not null. That's an error.
        static MarketTrade MakeTrade(DateTime msgTime, Mantle.Fix44.MDEntry entry, out string error)
        {
            var res = new MarketTrade();

            error = null;

            if (!entry.MDEntryType.HasValue)
            {
                error = "Missing MDEntryType field";
                return(null);
            }

            if (entry.MDEntryType.Value != '2')
            {
                return(null);                                 // No error.
            }
            if (!entry.MDEntryPx.HasValue)
            {
                error = "Missing MDEntryPx field";
                return(null);
            }
            res.Price = entry.MDEntryPx.Value;
            if (!entry.MDEntrySize.HasValue)
            {
                error = "Missing MDEntrySize field";
                return(null);
            }
            res.Quantity = entry.MDEntrySize.Value;

            if (entry.Side.HasValue)
            {
                if (entry.Side.Value == '1')
                {
                    res.Side = Side.Buy;
                }
                else if (entry.Side.Value == '2')
                {
                    res.Side = Side.Sell;
                }
                else
                {
                    _log.Warn("Unknown value of Side field: {0}", entry.Side.Value);
                }
            }

            if (entry.MDEntryTime.HasValue)
            {
                // Huobi sends MDEntryTime with every trade report but this field contains only
                // time without the date. We combine it with OrigTime or SendingTime (whichever is present)
                // to get a full timestamp.
                res.Timestamp = Combine(msgTime, entry.MDEntryTime.Value);
            }

            return(res);
        }
        /// <summary>
        /// It Maps the Market Trades and binds the object of Market Trades with Recently Traded Values
        /// </summary>
        /// <param name="BuyeruserID">Unique Buyer's ID e.g. ABC</param>
        /// <param name="SellerID">Unique Seller's ID e.g. 123</param>
        /// <param name="symbol">Symbol e.g Symbol A</param>
        /// <param name="Quantity">Quantity of the Given Symbol e.g. 10</param>
        /// <param name="price">Price of the Given Symbol e,g. 20.00</param>
        internal void ProcessMarketTrade(string BuyeruserID, string SellerID, string symbol, int Quantity, double price)
        {
            MarketTrade marketTrade = new MarketTrade()
            {
                BuyUserID      = BuyeruserID,
                SellerUserID   = SellerID,
                symbol         = symbol,
                TradedQuantity = Quantity,
                TradedPrice    = price
            };

            marketTradesList.Add(marketTrade);
        }
Esempio n. 7
0
        private void _listener_OnTrade(object sender, MarketTrade e)
        {
            _publisher.SendTrade(e);

            Console.WriteLine(e.ToString());
        }
Esempio n. 8
0
 public void SendTrade(MarketTrade trade)
 {
     _trades.PublishAsync(ObjectToByteArray(trade));
 }
Esempio n. 9
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (TradeId.Length != 0)
            {
                hash ^= TradeId.GetHashCode();
            }
            if (ExchangeOrderId.Length != 0)
            {
                hash ^= ExchangeOrderId.GetHashCode();
            }
            if (System.Length != 0)
            {
                hash ^= System.GetHashCode();
            }
            if (Counterparty.Length != 0)
            {
                hash ^= Counterparty.GetHashCode();
            }
            if (PortfolioId.Length != 0)
            {
                hash ^= PortfolioId.GetHashCode();
            }
            if (Volume != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Volume);
            }
            if (InstrumentId.Length != 0)
            {
                hash ^= InstrumentId.GetHashCode();
            }
            if (Price != 0D)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseDoubleEqualityComparer.GetHashCode(Price);
            }
            if (Currency.Length != 0)
            {
                hash ^= Currency.GetHashCode();
            }
            if (timestamp_ != null)
            {
                hash ^= Timestamp.GetHashCode();
            }
            hash ^= AdditionalData.GetHashCode();
            if (SystemTradeId.Length != 0)
            {
                hash ^= SystemTradeId.GetHashCode();
            }
            if (UniqueTradeId.Length != 0)
            {
                hash ^= UniqueTradeId.GetHashCode();
            }
            if (Desk.Length != 0)
            {
                hash ^= Desk.GetHashCode();
            }
            if (ExchangeTradeId.Length != 0)
            {
                hash ^= ExchangeTradeId.GetHashCode();
            }
            if (MarketTrade != false)
            {
                hash ^= MarketTrade.GetHashCode();
            }
            if (AlgoId.Length != 0)
            {
                hash ^= AlgoId.GetHashCode();
            }
            if (Strategy.Length != 0)
            {
                hash ^= Strategy.GetHashCode();
            }
            if (Owner.Length != 0)
            {
                hash ^= Owner.GetHashCode();
            }
            if (ClearerAccount.Length != 0)
            {
                hash ^= ClearerAccount.GetHashCode();
            }
            if (Depot.Length != 0)
            {
                hash ^= Depot.GetHashCode();
            }
            if (Safekeeping.Length != 0)
            {
                hash ^= Safekeeping.GetHashCode();
            }
            if (Deleted != false)
            {
                hash ^= Deleted.GetHashCode();
            }
            if (FundingCurrency.Length != 0)
            {
                hash ^= FundingCurrency.GetHashCode();
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }