TDAmeritrade.DotNetCore
TDAmeritrade for C# and DotNetCore
Install / Use
/learn @NVentimiglia/TDAmeritrade.DotNetCoreREADME
TD Ameritrade Client Library for .NET
Free, open-source .NET Client for the TD Ameritrade Trading Platform. Helps developers integrate TD Ameritrade API into custom trading solutions.
Features
- Authentication Flow
- Principal
- Quotes
- Historical Charts
- Option Chain
- Streaming QOS
- Streaming Charts
- Streaming Level 1 Quotes
- Streaming Level 2 Quotes
- Streaming Time & Sales
Sample
// Credentials are saved, please use the protected cache
var cache = TDProtectedCache();
var client = new TDAmeritradeClient(cache);
// Sign in first time
var url = client.GetSignInUrl("consumerkey");
client.SignIn("consumerkey", "codefromloginurl");
Assert.IsTrue(client.IsSignedIn);
// Sign in second time
client.SignIn();
Assert.IsTrue(client.IsSignedIn);
//Use!
var data = await client.GetQuote_Equity("SPY");
var data = await client.GetQuote_Future("/NQ");
var data = await client.GetQuote_Option("SPY_231215C500");
var data = await client.GetPriceHistory(new TDPriceHistoryRequest
{
symbol = "SPY",
frequencyType = TDPriceHistoryRequest.FrequencyType.minute,
frequency = 5,
periodType = TDPriceHistoryRequest.PeriodTypes.day,
period = 2,
});
var data = await client.GetOptionsChain(new TDOptionChainRequest
{
symbol = "SPY",
});
var data = await client.GetPrincipals(TDPrincipalsFields.preferences);
using (var socket = new TDAmeritradeStreamClient(client))
{
socket.OnHeartbeatSignal += o => { };
socket.OnQuoteSignal += o => { };
socket.OnTimeSaleSignal += o => { };
socket.OnChartSignal += o => { };
socket.OnBookSignal += o => { };
await socket.Connect();
await socket.SubscribeQuote("QQQ");
await socket.SubscribeChart("QQQ", TDChartSubs.CHART_EQUITY);
await socket.SubscribeTimeSale("QQQ", TDTimeSaleServices.TIMESALE_EQUITY);
await socket.SubscribeBook("QQQ", TDBookOptions.NASDAQ_BOOK);
}
Console/UnitTest Initialization
Setup is multi-step process. To use this SDK, you must run the console app and set up your security file.
- Run the console app, this will prompt you for a consumer key.
- Consumer key is located under MyApps
- Sign in using the opened web browser.
- Copy the code (?code={code}) from the returned website upon completion.
- Input the code into the console app.
- This will write a security file (TDAmeritradeKey). Place it in the runtime root when needed.
- Copy this key to the test bin/debug folder next to the exe and dll
AspNetCore Initialization
I have included a AspNetCore example with Dataprotection implemented using a web page.
- Run the web application
- Start authentication by submitting your consumer key.
- Sign in using the opened web browser.
- Copy the code (?code={code}) from the returned website upon completion.
- Input the code into the 'PostAccessToken' field
- This will write a security file (TDAmeritradeKey).
- Enjoy
Credits
Copyright (c) 2021 Nicholas Ventimiglia
Logo image is a trademark of TD Ameritrade, Inc.
Related Skills
node-connect
352.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.3kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
