-
-
Notifications
You must be signed in to change notification settings - Fork 14
Using Trading methods
Place equity and complex option trades including advanced orders.
For all the trading related usages, make sure you include the Trading Model namespace:
using Tradier.Client.Models.Trading;
If you set a default account number in the client, it is not needed to add an account number in the parameters for Trading methods.
Place an order to trade equity security.
IOrder order = await client.Trading.PlaceEquityOrder(accountNumber, "AAPL", "buy", 10, "market", "day");
Place an order to trade a single option.
IOrder order = await client.Trading.PlaceOptionOrder(accountNumber, "SPY", "SPY140118C00195000", "buy_to_open", 10, "market", "day", preview: true);
Place a multileg order with up to 4 legs.
The property legs is a List<(string, string, int)>
, where the items are for:
Item # | Type | Property |
---|---|---|
Item 1 | string | option symbol |
Item 2 | string | side |
Item 3 | int | quantity |
IOrder order =
await client.Trading.PlaceMultilegOrder(accountNumber, "MFA", "credit", "day", new List<(string, string, int)> { ("AAPL", "buy", 10), ("IBM", "buy", 5) }, 1.00);
Place a combo order. This is a specialized type of order consisting of one equity leg and one option leg. It can optionally include a second option leg, for some strategies.
The property legs is a List<(string, string, int)>
, where the items are for:
Item # | Type | Property |
---|---|---|
Item 1 | string | option symbol |
Item 2 | string | side |
Item 3 | int | quantity |
IOrder order =
await client.Trading.PlaceComboOrder(accountNumber, "MFA", "credit", "day", new List<(string, string, int)> { ("AAPL", "buy", 10), ("IBM", "buy", 5) }, 1.00);
Place a one-triggers-other order. This order type is composed of two separate orders sent simultaneously. The property keys of each order are indexed.
The property legs is a List<(string, int, string, string, string, double?, double?)>
, where the items are for:
Item # | Type | Property | Required |
---|---|---|---|
Item 1 | string | symbol | required |
Item 2 | int | quantity | required |
Item 3 | string | type | required |
Item 4 | string | option symbol | required |
Item 5 | string | side | required |
Item 6 | double | price | optional |
Item 7 | double | stop | optional |
IOrder order =
await client.Trading.PlaceOtoOrder(accountNumber, "day", new List<(string, int, string, string, string, double?, double?)> { ("SPY", 10, "limit", "SPY190605C00282000", "buy_to_open", 1.00, 1.00) });
Place a one-cancels-other order. This order type is composed of two separate orders sent simultaneously. The property keys of each order are indexed.
The property legs is a List<(string, int, string, string, string, double?, double?)>
, where the items are for:
Item # | Type | Property | Required |
---|---|---|---|
Item 1 | string | symbol | required |
Item 2 | int | quantity | required |
Item 3 | string | type | required |
Item 4 | string | option symbol | required |
Item 5 | string | side | required |
Item 6 | double | price | optional |
Item 7 | double | stop | optional |
IOrder order =
await client.Trading.PlaceOcoOrder(accountNumber, "day", new List<(string, int, string, string, string, double?, double?)> { ("SPY", 10, "limit", "SPY190605C00282000", "buy_to_open", 1.00, 1.00) });
Place a one-triggers-one-cancels-other order. This order type is composed of three separate orders sent simultaneously. The property keys of each order are indexed.
The property legs is a List<(string, int, string, string, string, double?, double?)>
, where the items are for:
Item # | Type | Property | Required |
---|---|---|---|
Item 1 | string | symbol | required |
Item 2 | int | quantity | required |
Item 3 | string | type | required |
Item 4 | string | option symbol | required |
Item 5 | string | side | required |
Item 6 | double | price | optional |
Item 7 | double | stop | optional |
IOrder order =
await client.Trading.PlaceOtocoOrder(accountNumber, "day", new List<(string, int, string, string, string, double?, double?)> { ("SPY", 10, "limit", "SPY190605C00282000", "buy_to_open", 1.00, 1.00) });
Modify an order. You may change some or all of these parameters. You may not change the session of a pre/post-market session order. Send only the parameters you would like to adjust.
IOrder order =
await client.Trading.ModifyOrder(accountNumber, orderId, "limit", "day", 1.00, 1.00);
Cancel an order.
IOrder order = await client.Trading.CancelOrder(accountNumber, orderId);
using System.Collections.Generic;
using System.Threading.Tasks;
using Tradier.Client;
using Tradier.Client.Models.Trading;
namespace MyConsoleApp
{
class Program
{
static async Task Main(string[] args)
{
TradierClient client = new TradierClient("<TOKEN>");
string accountNumber = "<ACCOUNT_NUMBER>";
string orderId = "<ORDER_ID>";
IOrder order = await client.Trading.PlaceEquityOrder(accountNumber, "AAPL", "buy", 10, "market", "day");
IOrder order1 = await client.Trading.PlaceOptionOrder(accountNumber, "SPY", "SPY140118C00195000", "buy_to_open", 10, "market", "day", preview: true);
IOrder order2 = await client.Trading.PlaceMultilegOrder(accountNumber, "MFA", "credit", "day", new List<(string, string, int)> { ("AAPL", "buy", 10), ("IBM", "buy", 5) }, 1.00);
IOrder order3 = await client.Trading.PlaceComboOrder(accountNumber, "MFA", "credit", "day", new List<(string, string, int)> { ("AAPL", "buy", 10), ("IBM", "buy", 5) }, 1.00);
IOrder order4 = await client.Trading.PlaceOtoOrder(accountNumber, "day", new List<(string, int, string, string, string, double?, double?)> { ("SPY", 10, "limit", "SPY190605C00282000", "buy_to_open", 1.00, 1.00) });
IOrder order5 = await client.Trading.PlaceOcoOrder(accountNumber, "day", new List<(string, int, string, string, string, double?, double?)> { ("SPY", 10, "limit", "SPY190605C00282000", "buy_to_open", 1.00, 1.00) });
IOrder order6 = await client.Trading.PlaceOtocoOrder(accountNumber, "day", new List<(string, int, string, string, string, double?, double?)> { ("SPY", 10, "limit", "SPY190605C00282000", "buy_to_open", 1.00, 1.00) });
IOrder order7 = await client.Trading.ModifyOrder(accountNumber, orderId, "limit", "day", "1.00", "1.00");
IOrder order8 = await client.Trading.CancelOrder(accountNumber, orderId);
}
}
}
Created by Henrique Tedeschi and Vitali Karmanov. See our Disclaimer. Check the API documentation on Tradier API.