Пример #1
0
        public override async Task InitializeExchangePriceProcessingAsync()
        {
            // Bitflyer uses pubnub. This is a cloud based service which works with subscriptions.
            pubnub = new Pubnub(null, this.Exchange.GetSetting("PubNubKey"));

            // Just in case you have problem, just remove these comments.
            //m.SetPubnubLog(new PubNubConsole());
            //m.SetInternalLogLevel(LoggingMethod.Level.Verbose);

            subsribedProducts = this.tradingPairs.ToDictionary(x => "lightning_ticker_" + x.Value.TradePair.FromCurrency.Code + "_" + x.Value.TradePair.ToCurrency.Code, y => y.Value);


            // Loop through each product and subscribe it.
            foreach (var product  in subsribedProducts)
            {
                pubnub.Subscribe <string>(product.Key, (data) =>
                {
                    try
                    {
                        // Get JSON array and extract product, time and last trade price.
                        dynamic dynObj        = Newtonsoft.Json.Linq.JArray.Parse(data);
                        string productName    = dynObj[0].product_code.Value;
                        DateTime utcTime      = dynObj[0].timestamp.Value;
                        double lasttradeprice = dynObj[0].ltp.Value;

                        Task.Run(() => this.NotifyObserverOfPriceChange(product.Value, (decimal)lasttradeprice, utcTime));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }

                    //System.Console.WriteLine($"product: {product} / ltp: {lasttradeprice} / time : {utcTime} ");
                }, (data) => { }, (err) => System.Console.WriteLine(err.Description));
            }

            // We're not doing async. We just want the warning to be gone.
            await Task.Run(() => { });
        }
Пример #2
0
        static public void Main()
        {
            PubnubProxy proxy = null;

            Console.WriteLine("HINT: TO TEST RE-CONNECT AND CATCH-UP,");
            Console.WriteLine("      DISCONNECT YOUR MACHINE FROM NETWORK/INTERNET AND ");
            Console.WriteLine("      RE-CONNECT YOUR MACHINE AFTER SOMETIME.");
            Console.WriteLine();
            Console.WriteLine("      IF NO NETWORK BEFORE MAX RE-TRY CONNECT,");
            Console.WriteLine("      NETWORK ERROR MESSAGE WILL BE SENT");
            Console.WriteLine();

            Console.WriteLine("ENTER Channel Name");
            channel = Console.ReadLine();

            Console.WriteLine(string.Format("Channel = {0}", channel));
            Console.WriteLine();

            Console.WriteLine("Enable SSL? ENTER Y for Yes, else N");
            string enableSSL = Console.ReadLine();

            if (enableSSL.Trim().ToLower() == "y")
            {
                Console.WriteLine("SSL Enabled");
            }
            else
            {
                Console.WriteLine("SSL NOT Enabled");
            }
            Console.WriteLine();

            Console.WriteLine("ENTER cipher key for encryption feature.");
            Console.WriteLine("If you don't want to avail at this time, press ENTER.");
            string cipheryKey = Console.ReadLine();

            if (cipheryKey.Trim().Length > 0)
            {
                Console.WriteLine("Cipher key provided.");
            }
            else
            {
                Console.WriteLine("No Cipher key provided");
            }
            Console.WriteLine();

            pubnub = new Pubnub("demo", "demo", "", cipheryKey,
                                (enableSSL.Trim().ToLower() == "y") ? true : false);

            Console.WriteLine("Use Custom Session UUID? ENTER Y for Yes, else N");
            string enableCustomUUID = Console.ReadLine();

            if (enableCustomUUID.Trim().ToLower() == "y")
            {
                Console.WriteLine("ENTER Session UUID.");
                string sessionUUID = Console.ReadLine();
                pubnub.SessionUUID = sessionUUID;
                Console.WriteLine("Accepted Custom Session UUID.");
            }
            else
            {
                Console.WriteLine("Default Session UUID opted.");
            }
            Console.WriteLine();

            Console.WriteLine("Proxy Server exists? ENTER Y for Yes, else N");
            string enableProxy = Console.ReadLine();

            if (enableProxy.Trim().ToLower() == "y")
            {
                bool proxyAccepted = false;
                while (!proxyAccepted)
                {
                    Console.WriteLine("ENTER proxy server name or IP.");
                    string proxyServer = Console.ReadLine();
                    Console.WriteLine("ENTER port number of proxy server.");
                    string proxyPort = Console.ReadLine();
                    int    port;
                    Int32.TryParse(proxyPort, out port);
                    Console.WriteLine("ENTER user name for proxy server authentication.");
                    string proxyUsername = Console.ReadLine();
                    Console.WriteLine("ENTER password for proxy server authentication.");
                    string proxyPassword = Console.ReadLine();

                    proxy               = new PubnubProxy();
                    proxy.ProxyServer   = proxyServer;
                    proxy.ProxyPort     = port;
                    proxy.ProxyUserName = proxyUsername;
                    proxy.ProxyPassword = proxyPassword;
                    try
                    {
                        pubnub.Proxy  = proxy;
                        proxyAccepted = true;
                        Console.WriteLine("Proxy details accepted");
                    }
                    catch (MissingFieldException mse)
                    {
                        Console.WriteLine(mse.Message);
                        Console.WriteLine("Please RE-ENTER Proxy Server details.");
                    }
                }
            }
            else
            {
                Console.WriteLine("No Proxy");
            }
            Console.WriteLine();

            Console.WriteLine("ENTER 1 FOR Subscribe (not implementing connectCallback)");
            Console.WriteLine("ENTER 2 FOR Subscribe (implementing connectCallback)");
            Console.WriteLine("ENTER 3 FOR Publish");
            Console.WriteLine("ENTER 4 FOR Presence");
            Console.WriteLine("ENTER 5 FOR Detailed History");
            Console.WriteLine("ENTER 6 FOR Here_Now");
            Console.WriteLine("ENTER 7 FOR Unsubscribe");
            Console.WriteLine("ENTER 8 FOR Presence-Unsubscribe");
            Console.WriteLine("ENTER 9 FOR Time");
            Console.WriteLine("ENTER 0 FOR EXIT OR QUIT");

            bool exitFlag = false;

            Console.WriteLine("");
            while (!exitFlag)
            {
                string userinput = Console.ReadLine();
                switch (userinput)
                {
                case "0":
                    exitFlag = true;
                    pubnub.EndPendingRequests();
                    break;

                case "1":
                    Console.WriteLine("Running subscribe() (not implementing connectCallback)");
                    pubnub.Subscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "2":
                    Console.WriteLine("Running subscribe() (implementing connectCallback)");
                    pubnub.Subscribe <string>(channel, DisplayReturnMessage, DisplayConnectStatusMessage);
                    break;

                case "3":
                    Console.WriteLine("Running publish()");
                    Console.WriteLine("Enter the message for publish. To exit loop, enter QUIT");
                    string publishMsg = Console.ReadLine();
                    double doubleData;
                    int    intData;
                    if (int.TryParse(publishMsg, out intData))                     //capture numeric data
                    {
                        pubnub.Publish <string>(channel, intData, DisplayReturnMessage);
                    }
                    else if (double.TryParse(publishMsg, out doubleData))                     //capture numeric data
                    {
                        pubnub.Publish <string>(channel, doubleData, DisplayReturnMessage);
                    }
                    else
                    {
                        //check whether any numeric is sent in double quotes
                        if (publishMsg.IndexOf("\"") == 0 && publishMsg.LastIndexOf("\"") == publishMsg.Length - 1)
                        {
                            string strMsg = publishMsg.Substring(1, publishMsg.Length - 2);
                            if (int.TryParse(strMsg, out intData))
                            {
                                pubnub.Publish <string>(channel, strMsg, DisplayReturnMessage);
                            }
                            else if (double.TryParse(strMsg, out doubleData))
                            {
                                pubnub.Publish <string>(channel, strMsg, DisplayReturnMessage);
                            }
                            else
                            {
                                pubnub.Publish <string>(channel, publishMsg, DisplayReturnMessage);
                            }
                        }
                        else
                        {
                            pubnub.Publish <string>(channel, publishMsg, DisplayReturnMessage);
                        }
                    }
                    break;

                case "4":
                    Console.WriteLine("Running presence()");
                    pubnub.Presence <string>(channel, DisplayReturnMessage);
                    break;

                case "5":
                    Console.WriteLine("Running detailed history()");
                    pubnub.DetailedHistory <string>(channel, 100, DisplayReturnMessage);
                    break;

                case "6":
                    Console.WriteLine("Running Here_Now()");
                    pubnub.HereNow <string>(channel, DisplayReturnMessage);
                    break;

                case "7":
                    Console.WriteLine("Running unsubscribe()");
                    pubnub.Unsubscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "8":
                    Console.WriteLine("Running presence-unsubscribe()");
                    pubnub.PresenceUnsubscribe <string>(channel, DisplayReturnMessage);
                    break;

                case "9":
                    Console.WriteLine("Running time()");
                    pubnub.Time <string>(DisplayReturnMessage);
                    break;

                default:
                    Console.WriteLine("INVALID CHOICE.");
                    break;
                }
            }

            Console.WriteLine("\nPress any key to exit.\n\n");
            Console.ReadLine();
        }
Пример #3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            /*if (ApplicationContext.Resources.Configuration.ScreenLayout = Android.Content.Res.ScreenLayout.SizeLarge) {
             *      SetContentView (Resource.Layout.Mainlarge);
             * } else {*/

            //}
            //Build.VERSION.Sdk

            SetContentView(Resource.Layout.Main);

            string channelName = Intent.GetStringExtra("Channel");

            channel = channelName;

            bool   enableSSL = Convert.ToBoolean((Intent.GetStringExtra("SslOn")));
            string cipher    = (Intent.GetStringExtra("Cipher"));

            string ssl = "";

            if (enableSSL)
            {
                ssl = ", SSL";
            }

            if (!String.IsNullOrWhiteSpace(cipher))
            {
                cipher = ", Cipher";
            }

            string head = String.Format("Channel: {0}{1}{2}", channelName, ssl, cipher);

            pubnub = LaunchScreen.pubnub;
            //pubnub = new Pubnub ("demo", "demo", "", cipher, enableSSL);

            Title = head;

            Button btnSubscribe = FindViewById <Button> (Resource.Id.btnSubscribe);

            btnSubscribe.Click += delegate { Subscribe(); };

            Button btnCancel = FindViewById <Button> (Resource.Id.btnCancel);

            btnCancel.Click += delegate { pubnub.EndPendingRequests(); Finish(); };

            Button btnPresence = FindViewById <Button> (Resource.Id.btnPresence);

            btnPresence.Click += delegate { Presence(); };

            Button btnPublish = FindViewById <Button> (Resource.Id.btnPublish);

            btnPublish.Click += delegate { Publish(); };

            Button btnHereNow = FindViewById <Button> (Resource.Id.btnHereNow);

            btnHereNow.Click += delegate { HereNow(); };

            Button btnDetailedHis = FindViewById <Button> (Resource.Id.btnDetailedHis);

            btnDetailedHis.Click += delegate { DetailedHistory(); };

            Button btnTime = FindViewById <Button> (Resource.Id.btnTime);

            btnTime.Click += delegate { GetTime(); };

            Button btnUnsub = FindViewById <Button> (Resource.Id.btnUnsub);

            btnUnsub.Click += delegate { Unsub(); };

            Button btnUnsubPres = FindViewById <Button> (Resource.Id.btnUnsubPres);

            btnUnsubPres.Click += delegate { UnsubPresence(); };
        }