Ejemplo n.º 1
0
 /// <summary>
 /// Either gets data or displays the exception in a popup
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="callResult"></param>
 /// <returns></returns>
 public static T GetOrDisplayError <T>(this CryptoExchange.Net.CallResult <T> callResult)
 {
     try
     {
         return(callResult.GetOrThrow());
     }
     catch (BinanceAPIException ex)
     {
         InfoPopup("Error", ex.Message, MessageBoxImage.Error);
         return(default(T));
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Either throws an exception if the request was faulty or returns the data
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="callResult"></param>
 /// <returns></returns>
 public static T GetOrThrow <T>(this CryptoExchange.Net.CallResult <T> callResult)
 {
     if (callResult.Success == false)
     {
         var errorObj = Trading.BinanceErrorJSON.FromJson(callResult.Error.Message.Replace("Server error: ", ""));
         throw new BinanceAPIException($"Could not get result: \"{errorObj.Msg} ({errorObj.Code})\"", errorObj.Code);
     }
     else
     {
         return(callResult.Data);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Attach Bittrex AllMarketDeltaStream websocket stream to tickers processor.
        /// This is a delta stream, sending only the changes since the last tick.
        /// </summary>
        /// <param name="callback">The callback.</param>
        /// <param name="streamId">The stream identifier which can be used to dispose this stream without killing all other socket subscriptions.</param>
        /// <returns>
        /// The BittrexSocketClient
        /// Note that this socketclient handles all subscriptions.
        /// To unsubscribe a single subscription, use UnsubscribeFromStream(int streamId)
        /// </returns>
        public BittrexSocketClient GetTickersWebSocket(Action <IReadOnlyCollection <KeyValuePair <string, ExchangeTicker> > > callback, out int streamId)
        {
            streamId = -1;

            if (callback == null)
            {
                return(null);
            }

            CryptoExchange.Net.CallResult <int> result = this.SocketClient.SubscribeToAllMarketDeltaStream
                                                         (
                summaries =>
            {
                // Convert Bittrex.Net tickers objects into ExchangeSharp ExchangeTickers
                var freshTickers = new Dictionary <string, ExchangeTicker>(StringComparer.OrdinalIgnoreCase);
                foreach (BittrexMarketSummary market in summaries)
                {
                    decimal quantityAmount = market.Volume.ConvertInvariant <decimal>();
                    decimal last           = market.Last.ConvertInvariant <decimal>();
                    var ticker             = new ExchangeTicker
                    {
                        Ask    = market.Ask,
                        Bid    = market.Bid,
                        Last   = last,
                        Volume = new ExchangeVolume
                        {
                            QuantityAmount = quantityAmount,
                            QuantitySymbol = market.MarketName,
                            PriceAmount    = market.BaseVolume.ConvertInvariant <decimal>(quantityAmount * last),
                            PriceSymbol    = market.MarketName,
                            Timestamp      = market.TimeStamp
                        }
                    };
                    freshTickers[market.MarketName] = ticker;
                }
                callback(freshTickers);
            }
                                                         );
            if (result.Success)
            {
                streamId = result.Data;
            }

            return(this.SocketClient);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns whether a request succeded
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="callResult"></param>
 /// <returns></returns>
 public static bool Fails <T>(this CryptoExchange.Net.CallResult <T> callResult)
 {
     return(!callResult.Success);
 }