Exemple #1
0
        public async Task Init()
        {
            // Please sign in first, following services uses the client file
            var cache = new TDUnprotectedCache();

            client = new TDAmeritradeClient(cache);
            await client.PostRefreshToken();

            Assert.IsTrue(client.IsSignedIn);
        }
Exemple #2
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Starting Client");
            Console.WriteLine("...");

            //var serviceCollection = new ServiceCollection();
            //serviceCollection.AddDataProtection();
            //var services = serviceCollection.BuildServiceProvider();
            //var protection = services.GetService<IDataProtectionProvider>();
            //var cache = new TDProtectedCache(protection);
            //var client = new TDAmeritradeClient(cache);

            var cache  = new TDUnprotectedCache();
            var client = new TDAmeritradeClient(cache);

            Console.WriteLine("1 to sign in fresh, 2 to refresh signin, 3 streaming");
            var option = Console.ReadKey();

            switch (option.Key)
            {
            case ConsoleKey.D1:
                Console.WriteLine("Paste consumer key :");
                var key = Console.ReadLine();
                Console.WriteLine("Opening Browser. Please sign in.");
                client.RequestAccessToken(key);

                Console.WriteLine("Paste the code. This is in the browser url bar 'code={code}'.");
                var code = Console.ReadLine();
                await client.PostAccessToken(key, code);

                Console.WriteLine($"Authenticated {client.IsSignedIn}.");
                Console.ReadLine();
                break;

            case ConsoleKey.D2:
                await client.PostRefreshToken();

                Console.WriteLine($"Authenticated {client.IsSignedIn}.");
                Console.ReadLine();
                break;

            case ConsoleKey.D3:
                await client.PostRefreshToken();

                Console.WriteLine($"Authenticated {client.IsSignedIn}.");
                var socket = new TDAmeritradeStreamClient(client);
                socket.OnMessage += (m) =>
                {
                    Console.WriteLine(m);
                };
                await socket.Connect();

                await socket.Subscribe_Chart("MSFT");

                Console.ReadLine();
                break;

            default:
                return;
            }
        }
 public Program()
 {
     cache  = new TDUnprotectedCache();
     client = new TDAmeritradeClient(cache);
 }
Exemple #4
0
 public TDProtectedCache(IDataProtectionProvider provider)
 {
     _cache    = new TDUnprotectedCache();
     _provider = provider;
 }