AutoTrader Web API C# library can be used for automated trading on Supports leading Indian Stock Brokers.
Following steps need to be taken in order to use the C# Library.
Download
The library is available on Nuget. So you can easily install it in your C# project.
See instructions on “How to install a package from Nuget?“
Initialize
You need to make an instance of com.dakshata.autotrader.api.AutoTrader class. See the sample code below:
IAutoTrader autoTrader = AutoTrader.CreateInstance(
"<your-api-key>",
AutoTrader.SERVER_URL);
You can find your API Key on AutoTrader Web.
Usage
Using the client is pretty straightforward, you invoke appropriate functions on the autotrader instance. All functions can be learned from API documentation. For example,
using com.dakshata.autotrader.api;
using com.dakshata.constants.trading;
using com.dakshata.data.model.common;
using com.dakshata.trading.model.platform;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace csharp_library_tests
{
class Program
{
static void Main(string[] args)
{
try
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
// IMPORTANT : Add your autotrader api key here & use your Pseudo Account
IAutoTrader autoTrader = AutoTrader.CreateInstance(
"f4xcxa1f-efd7-4587-ad8e-ce4743b25395",
"https://api.stocksdeveloper.in");
//IOperationResponse<ISet<string>> result = autoTrader.FetchLivePseudoAccounts();
//Console.WriteLine("Message: {0}", result.Message);
//Console.WriteLine("Result: {0}", result.Result.Count);
//IOperationResponse<bool?> r2 = autoTrader.CancelOrderByPlatformId("XX1234", "200831101595372");
//Console.WriteLine("Message: {0}", r2.Message);
//Console.WriteLine("Result: {0}", r2.Result);
//IOperationResponse<bool?> r3 = autoTrader.CancelChildOrdersByPlatformId("XX1234", "200831000170161");
//Console.WriteLine("Message: {0}", r3.Message);
//Console.WriteLine("Result: {0}", r3.Result);
// IOperationResponse<bool?> r4 = autoTrader.ModifyOrderByPlatformId("XX1234", "200831101805912",
// null, null, 279.2f, null);
// Console.WriteLine("Message: {0}", r4.Message);
// Console.WriteLine("Result: {0}", r4.Result);
//IOperationResponse<string> r5 = autoTrader.PlaceRegularOrder("XX1234", "NSE", "SBIN", TradeType.BUY,
// OrderType.LIMIT, ProductType.INTRADAY, 2, 214.55f, 0);
//Console.WriteLine("Message: {0}", r5.Message);
//Console.WriteLine("Result: {0}", r5.Result);
//IOperationResponse<string> r6 = autoTrader.PlaceBracketOrder("XX1234", "NSE", "SBIN", TradeType.SELL,
// OrderType.LIMIT, 3, 220f, 0, 2, 3, 0);
//Console.WriteLine("Message: {0}", r6.Message);
//Console.WriteLine("Result: {0}", r6.Result);
//IOperationResponse<string> r7 = autoTrader.PlaceCoverOrder("XX1234", "NSE", "SBIN", TradeType.SELL,
// OrderType.MARKET, 3, 0, 218.4f);
//Console.WriteLine("Message: {0}", r7.Message);
//Console.WriteLine("Result: {0}", r7.Result);
//IOperationResponse<bool?> r8 = autoTrader.SquareOffPosition("XX1234", PositionCategory.DAY,
// PositionType.CO, "NSE", "SBIN");
//Console.WriteLine("Message: {0}", r8.Message);
//Console.WriteLine("Result: {0}", r8.Result);
//IOperationResponse<bool?> r9 = autoTrader.SquareOffPortfolio("XX1234", PositionCategory.DAY);
//Console.WriteLine("Message: {0}", r9.Message);
//Console.WriteLine("Result: {0}", r9.Result);
IOperationResponse<ISet<PlatformMargin>> r10 = autoTrader.ReadPlatformMargins("XX1234");
Console.WriteLine("Message: {0}", r10.Message);
foreach (PlatformMargin p in r10.Result)
Console.WriteLine("{0}", p);
IOperationResponse<ISet<PlatformOrder>> r11 = autoTrader.ReadPlatformOrders("XX1234");
Console.WriteLine("Message: {0}", r11.Message);
foreach (PlatformOrder p in r11.Result)
Console.WriteLine("{0}", p);
IOperationResponse<ISet<PlatformPosition>> r12 = autoTrader.ReadPlatformPositions("XX1234");
Console.WriteLine("Message: {0}", r12.Message);
foreach(PlatformPosition p in r12.Result)
Console.WriteLine("{0}", p);
stopwatch.Stop();
Console.WriteLine("Elapsed Time is {0} ms", stopwatch.ElapsedMilliseconds);
}
catch (Exception e)
{
Console.WriteLine("Exception caught: {0}", e);
}
Console.ReadLine();
}
}
}
API Functions
Note: A detailed explanation is provided for each function along with examples in the API documentation.
GitHub
If you are interested to look at the code of this library, it is available on GitHub.