-
-
Notifications
You must be signed in to change notification settings - Fork 14
Using Watchlist methods
Henrique Tedeschi edited this page May 29, 2020
·
2 revisions
Create and update custom watchlists.
For all the watchlist related usages, make sure you include the Watchlist Model namespace:
using Tradier.Client.Models.Watchlist;
Retrieve all of a users watchlists.
Watchlists watchlists = await client.Watchlist.GetWatchlists();
Retrieve a specific watchlist by id.
Watchlists dafaultWatchlist = await client.Watchlist.GetWatchlist("<WATCHLIST_ID>");
Create a new watchlist. The new watchlist created will use the specified name and optional symbols upon creation.
Watchlists newWatchlist = await client.Watchlist.CreateWatchlist("My Watchlist", "AAPL,IBM");
Update an existing watchlist. This request will override the existing watchlist information with the parameters sent in the body.
Watchlists updatedWatchlist = await client.Watchlist.UpdateWatchlist("my-watchlist", "My First Watchlist", "SPY");
Add symbols to an existing watchlist. If the symbol exists, it will be over-written.
await client.Watchlist.AddSymbolsToWatchlist("my-watchlist", "NFLX");
Remove a symbol from a specific watchlist.
await client.Watchlist.RemoveSymbolFromWatchlist("my-watchlist", "AAPL");
Delete a specific watchlist.
Watchlists deleteWatclist = await client.Watchlist.DeleteWatchlist("my-watchlist");
using System;
using System.Linq;
using System.Threading.Tasks;
using Tradier.Client;
using Tradier.Client.Models.Watchlist;
namespace MyConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
TradierClient client = new TradierClient("<TOKEN>");
Watchlists watchlists = await client.Watchlist.GetWatchlists();
Console.WriteLine($"Watchlists: {watchlists.Watchlist.Count}");
Watchlists defaultWatchlist = await client.Watchlist.GetWatchlist("public-2dgqr81s7u");
Console.WriteLine($"List name: {String.Join(",", defaultWatchlist.Watchlist.Select(x => x.Name))}");
Watchlists newWatchlist = await client.Watchlist.CreateWatchlist("My Watchlist", "AAPL,IBM");
Console.WriteLine($"New Watchlist ID: {newWatchlist.Watchlist.Select(x => x.Id)}");
await client.Watchlist.UpdateWatchlist("my-watchlist", "My First Watchlist", "SPY");
await client.Watchlist.AddSymbolsToWatchlist("my-watchlist", "NFLX");
await client.Watchlist.RemoveSymbolFromWatchlist("my-watchlist", "AAPL");
defaultWatchlist = await client.Watchlist.GetWatchlist("my-watchlist");
Console.WriteLine($"Symbols: {String.Join(",", defaultWatchlist.Watchlist.Select(x => x.Items.Item.Select(y => y.Symbol)))}");
await client.Watchlist.DeleteWatchlist("my-watchlist");
}
}
}
Created by Henrique Tedeschi and Vitali Karmanov. See our Disclaimer. Check the API documentation on Tradier API.