### Initialize and Connect to QUIK Terminal with C# Source: https://context7.com/finsight/quiksharp/llms.txt Initializes the connection to the QUIK trading terminal using the Quik class. Supports default or custom ports and hosts. Includes checking connection status and retrieving the QUIK working folder path. Remember to stop the service when done. ```csharp using QuikSharp; using QuikSharp.DataStructures; using QuikSharp.DataStructures.Transaction; // Initialize connection to QUIK terminal (default port: 34130, localhost) var quik = new Quik(); // Or specify custom port and remote host var quik = new Quik(port: 34130, storage: new InMemoryStorage(), host: "192.168.1.100"); // Check if terminal is connected to the trading server bool isConnected = await quik.Service.IsConnected(); Console.WriteLine($"Connected to server: {isConnected}"); // Get working folder path string workingFolder = await quik.Service.GetWorkingFolder(); Console.WriteLine($"QUIK path: {workingFolder}"); // Stop the service when done quik.StopService(); ``` -------------------------------- ### Send and Manage Transactions in C# Source: https://context7.com/finsight/quiksharp/llms.txt Demonstrates creating and sending various transaction types like new orders and cancellations using the QuikSharp library. It also shows how to subscribe to transaction replies, order events, and trade events for real-time feedback. Error handling for failed transactions is included. ```csharp // Create transaction for new order Transaction transaction = new Transaction { ACTION = TransactionAction.NEW_ORDER, CLASSCODE = "TQBR", SECCODE = "SBER", ACCOUNT = "L01+00000F00", CLIENT_CODE = "CLIENT001", OPERATION = TransactionOperation.B, // Buy PRICE = 250.00m, QUANTITY = 10, TYPE = TransactionType.L, // Limit order EXECUTION_CONDITION = ExecutionCondition.PUT_IN_QUEUE }; long transId = await quik.Trading.SendTransaction(transaction); if (transId > 0) { Console.WriteLine($"Transaction sent: {transId}"); } else { Console.WriteLine($"Transaction failed: {transaction.ErrorMessage}"); } // Cancel order transaction Transaction killTransaction = new Transaction { ACTION = TransactionAction.KILL_ORDER, CLASSCODE = "TQBR", SECCODE = "SBER", ORDER_KEY = "123456789" // Order number to cancel }; await quik.Trading.SendTransaction(killTransaction); // Subscribe to transaction replies quik.Events.OnTransReply += (TransactionReply reply) => { Console.WriteLine($"Trans {reply.TransID}: Status={reply.Status}, ErrorCode={reply.ErrorCode}"); if (!string.IsNullOrEmpty(reply.ResultMsg)) { Console.WriteLine($"Message: {reply.ResultMsg}"); } }; // Transaction with event handlers transaction.OnTransReply += (TransactionReply reply) => { Console.WriteLine($"My transaction reply: {reply.Status}"); }; transaction.OnOrder += (Order order) => { Console.WriteLine($"Order created: {order.OrderNum}"); }; transaction.OnTrade += (Trade trade) => { Console.WriteLine($"Trade from transaction: {trade.TradeNum}"); }; ``` -------------------------------- ### Manage Trading Parameters and Market Data in C# Source: https://context7.com/finsight/quiksharp/llms.txt Illustrates how to subscribe to and retrieve trading parameters like last price, bid, and offer for a specific instrument. It also covers handling parameter change events, canceling subscriptions, and fetching trade data. ```csharp // Request parameter subscription await quik.Trading.ParamRequest("TQBR", "SBER", ParamNames.LAST); await quik.Trading.ParamRequest("TQBR", "SBER", ParamNames.BID); await quik.Trading.ParamRequest("TQBR", "SBER", ParamNames.OFFER); // Get parameter values ParamTable lastPrice = await quik.Trading.GetParamEx("TQBR", "SBER", ParamNames.LAST); Console.WriteLine($"Last price: {lastPrice.ParamValue}"); ParamTable param = await quik.Trading.GetParamEx2("TQBR", "SBER", ParamNames.BID); Console.WriteLine($"Bid: {param.ParamValue}, Type: {param.ParamType}"); // Subscribe to parameter changes quik.Events.OnParam += (Param p) => { if (p.ClassCode == "TQBR" && p.SecCode == "SBER") { var bid = quik.Trading.GetParamEx2("TQBR", "SBER", ParamNames.BID).Result; Console.WriteLine($"Parameter changed - BID: {bid.ParamValue}"); } }; // Cancel parameter subscription await quik.Trading.CancelParamRequest("TQBR", "SBER", ParamNames.LAST); // Get trading date DateTime tradeDate = await quik.Trading.GetTradeDate(); // Get all trades (anonymous/public trades) List allTrades = await quik.Trading.GetAllTrades("TQBR", "SBER"); foreach (var trade in allTrades) { Console.WriteLine($"Trade: {trade.Price} x {trade.Qty} at {trade.TradeDateTime}"); } // Get client trades List myTrades = await quik.Trading.GetTrades("TQBR", "SBER"); ``` -------------------------------- ### Subscribe and Manage Order Book Data in C# Source: https://context7.com/finsight/quiksharp/llms.txt Demonstrates how to subscribe to, check the status of, retrieve, and unsubscribe from Level 2 order book data for a given instrument. It also shows how to access bid and ask prices and subscribe to order book change events. ```csharp // Subscribe to order book updates bool subscribed = await quik.OrderBook.Subscribe("TQBR", "SBER"); // Check subscription status bool isSubscribed = await quik.OrderBook.IsSubscribed("TQBR", "SBER"); // Get current order book snapshot OrderBook orderBook = await quik.OrderBook.GetQuoteLevel2("TQBR", "SBER"); Console.WriteLine($"Bid count: {orderBook.bid_count}, Offer count: {orderBook.offer_count}"); // Access bid prices (sorted descending - best bid first in last element) for (int i = orderBook.bid.Length - 1; i >= 0; i--) { Console.WriteLine($"Bid: {orderBook.bid[i].price} x {orderBook.bid[i].quantity}"); } // Access ask/offer prices (sorted ascending - best offer first) foreach (var offer in orderBook.offer) { Console.WriteLine($"Ask: {offer.price} x {offer.quantity}"); } // Subscribe to order book change events quik.Events.OnQuote += (OrderBook quote) => { if (quote.sec_code == "SBER" && quote.class_code == "TQBR") { decimal bestBid = Convert.ToDecimal(quote.bid[quote.bid.Length - 1].price); decimal bestAsk = Convert.ToDecimal(quote.offer[0].price); Console.WriteLine($"SBER: Bid={bestBid}, Ask={bestAsk}"); } }; // Unsubscribe from order book await quik.OrderBook.Unsubscribe("TQBR", "SBER"); ``` -------------------------------- ### Create and Manage Stop Orders in C# Source: https://context7.com/finsight/quiksharp/llms.txt Illustrates how to create various types of stop orders, including stop-limit, take-profit, and combined orders, using the QuikSharp library. It also covers retrieving all stop orders, filtering by instrument, cancelling orders, and subscribing to stop order events. ```csharp // Create simple stop-limit order StopOrder stopLimitOrder = new StopOrder { ClassCode = "SPBFUT", SecCode = "SiH4", Account = "SPBFUT001", Operation = Operation.Sell, Quantity = 1, StopOrderType = StopOrderType.StopLimit, ConditionPrice = 92000m, // Trigger price Price = 91950m // Execution price }; long stopOrderId = await quik.StopOrders.CreateStopOrder(stopLimitOrder); // Create take-profit order StopOrder takeProfitOrder = new StopOrder { ClassCode = "SPBFUT", SecCode = "SiH4", Account = "SPBFUT001", Operation = Operation.Sell, Quantity = 1, StopOrderType = StopOrderType.TakeProfit, ConditionPrice = 94000m, Offset = 50m, OffsetUnit = OffsetUnits.PRICE_UNITS, // In price steps Spread = 0.1m, SpreadUnit = OffsetUnits.PERCENTS // In percent }; await quik.StopOrders.CreateStopOrder(takeProfitOrder); // Create combined take-profit and stop-limit order StopOrder combinedOrder = new StopOrder { ClassCode = "SPBFUT", SecCode = "SiH4", Account = "SPBFUT001", ClientCode = "CLIENT001", Operation = Operation.Buy, Quantity = 1, StopOrderType = StopOrderType.TakeProfitStopLimit, ConditionPrice = 91000m, // Take-profit trigger ConditionPrice2 = 93500m, // Stop-limit trigger Price = 93600m, // Stop-limit execution price Offset = 5m, OffsetUnit = OffsetUnits.PRICE_UNITS, Spread = 0.1m, SpreadUnit = OffsetUnits.PERCENTS }; await quik.StopOrders.CreateStopOrder(combinedOrder); // Get all stop orders List allStopOrders = await quik.StopOrders.GetStopOrders(); // Get stop orders for specific instrument List instrumentStops = await quik.StopOrders.GetStopOrders("SPBFUT", "SiH4"); // Cancel stop order await quik.StopOrders.KillStopOrder(stopLimitOrder); // Subscribe to stop order events quik.Events.OnStopOrder += (StopOrder stopOrder) => { Console.WriteLine($"StopOrder {stopOrder.OrderNum}: State={stopOrder.State}"); }; // Subscribe to new stop order creation quik.StopOrders.NewStopOrder += (StopOrder stopOrder) => { Console.WriteLine($"New stop order: {stopOrder.OrderNum}"); }; ``` -------------------------------- ### Manage Orders in C# Source: https://context7.com/finsight/quiksharp/llms.txt Functions for creating, sending, retrieving, and canceling trading orders. Supports both limit and market orders, with options for specifying execution conditions and client codes. Includes event subscriptions for real-time order and trade updates. ```csharp // Send limit order Order limitOrder = await quik.Orders.SendLimitOrder( classCode: "TQBR", securityCode: "SBER", accountID: "L01+00000F00", operation: Operation.Buy, price: 245.50m, qty: 10, executionCondition: ExecutionCondition.PUT_IN_QUEUE, clientCode: "CLIENT001" ); if (limitOrder.OrderNum > 0) { Console.WriteLine($"Order placed: {limitOrder.OrderNum}"); } else { Console.WriteLine($"Order rejected: {limitOrder.RejectReason}"); } // Send market order Order marketOrder = await quik.Orders.SendMarketOrder( classCode: "TQBR", securityCode: "SBER", accountID: "L01+00000F00", operation: Operation.Buy, qty: 5 ); // Create order using Order object Order newOrder = new Order { ClassCode = "TQBR", SecCode = "SBER", Account = "L01+00000F00", Operation = Operation.Buy, Price = 248.00m, Quantity = 1, ClientCode = "CLIENT001" }; long transId = await quik.Orders.CreateOrder(newOrder); // Get all orders List allOrders = await quik.Orders.GetOrders(); // Get orders for specific instrument List sberOrders = await quik.Orders.GetOrders("TQBR", "SBER"); // Get order by number Order order = await quik.Orders.GetOrder("TQBR", 123456789); Order orderByNum = await quik.Orders.GetOrder_by_Number(123456789); // Get order by transaction ID Order orderByTransId = await quik.Orders.GetOrder_by_transID("TQBR", "SBER", transId); // Cancel order long killResult = await quik.Orders.KillOrder(limitOrder); // Subscribe to order events quik.Events.OnOrder += (Order order) => { Console.WriteLine($"Order {order.OrderNum}: State={order.State}, Balance={order.Balance}"); }; // Subscribe to trade events quik.Events.OnTrade += (Trade trade) => { Console.WriteLine($"Trade executed: {trade.Price} x {trade.Qty}"); }; ``` -------------------------------- ### Access QUIK Class and Security Information with C# Source: https://context7.com/finsight/quiksharp/llms.txt Provides access to class functions, including retrieving lists of all available classes, class information, and securities within a specific class. It also fetches detailed security information, finds security classes, and retrieves client codes and trade accounts. ```csharp // Get list of all available classes string[] classes = await quik.Class.GetClassesList(); // Returns: ["TQBR", "SPBFUT", "TQOB", ...] // Get class information ClassInfo classInfo = await quik.Class.GetClassInfo("TQBR"); Console.WriteLine($"Class: {classInfo.Name}, Instruments: {classInfo.Nsecs}"); // Get all securities in a class string[] securities = await quik.Class.GetClassSecurities("TQBR"); // Returns: ["SBER", "GAZP", "LKOH", ...] // Get security information SecurityInfo secInfo = await quik.Class.GetSecurityInfo("TQBR", "SBER"); Console.WriteLine($"Name: {secInfo.Name}"); Console.WriteLine($"Lot size: {secInfo.LotSize}"); Console.WriteLine($"Min price step: {secInfo.MinPriceStep}"); Console.WriteLine($"Scale: {secInfo.Scale}"); // Find security class from list string classCode = await quik.Class.GetSecurityClass("SPBFUT,TQBR,TQOB", "SBER"); // Returns: "TQBR" // Get client codes string clientCode = await quik.Class.GetClientCode(); List allClientCodes = await quik.Class.GetClientCodes(); // Get trade accounts List accounts = await quik.Class.GetTradeAccounts(); foreach (var account in accounts) { Console.WriteLine($"Firm: {account.Firmid}, Account: {account.TrdaccId}"); } // Get trade account for specific class string account = await quik.Class.GetTradeAccount("SPBFUT"); ``` -------------------------------- ### Event Handling for QUIK Real-time Data and Notifications in C# Source: https://context7.com/finsight/quiksharp/llms.txt Utilizes QUIKSharp event handlers to manage real-time market data, trading notifications, connection status, and session events. These handlers provide callbacks for various occurrences within the QUIK terminal. ```csharp quik.Events.OnConnectedToQuik += (int port) => { Console.WriteLine($"Connected to QUIK on port {port}"); }; quik.Events.OnDisconnectedFromQuik += () => { Console.WriteLine("Disconnected from QUIK"); }; quik.Events.OnConnected += () => { Console.WriteLine("QUIK connected to trading server"); }; quik.Events.OnDisconnected += () => { Console.WriteLine("QUIK disconnected from trading server"); }; quik.Events.OnAllTrade += (AllTrade trade) => { Console.WriteLine($"Public trade: {trade.SecCode} {trade.Price} x {trade.Qty}"); }; quik.Events.OnQuote += (OrderBook quote) => { Console.WriteLine($"Order book update: {quote.sec_code}"); }; quik.Events.OnParam += (Param param) => { Console.WriteLine($"Parameter changed: {param.SecCode}.{param.ClassCode}"); }; quik.Events.OnOrder += (Order order) => { Console.WriteLine($"Order update: {order.OrderNum} State={order.State}"); }; quik.Events.OnTrade += (Trade trade) => { Console.WriteLine($"Trade executed: {trade.TradeNum} {trade.Price} x {trade.Qty}"); }; quik.Events.OnStopOrder += (StopOrder stopOrder) => { Console.WriteLine($"Stop order update: {stopOrder.OrderNum} State={stopOrder.State}"); }; quik.Events.OnTransReply += (TransactionReply reply) => { Console.WriteLine($"Transaction reply: {reply.TransID} Status={reply.Status}"); }; quik.Events.OnFuturesClientHolding += (FuturesClientHolding holding) => { Console.WriteLine($"Futures position: {holding.secCode} Net={holding.totalNet}"); }; quik.Events.OnDepoLimit += (DepoLimitEx limit) => { Console.WriteLine($"Depo limit: {limit.SecCode} Balance={limit.CurrentBalance}"); }; quik.Events.OnMoneyLimit += (MoneyLimit limit) => { Console.WriteLine("Money limit update"); }; quik.Events.OnFuturesLimitChange += (FuturesLimits limit) => { Console.WriteLine("Futures limit update"); }; quik.Events.OnCleanUp += () => { Console.WriteLine("Session cleanup - new trading day"); }; quik.Events.OnClose += () => { Console.WriteLine("QUIK terminal closing"); }; quik.Events.OnStop += (int flag) => { Console.WriteLine($"Script stopping: {flag}"); }; ``` -------------------------------- ### Manage QUIK Service Functions with C# Source: https://context7.com/finsight/quiksharp/llms.txt Utilizes service functions to display messages in the QUIK terminal with different notification types (Info, Warning, Error). Also retrieves script paths, server time, user information, and manages chart labels by adding, deleting, or deleting all labels. ```csharp // Display messages in QUIK terminal await quik.Service.Message("Order placed successfully", NotificationType.Info); await quik.Service.Message("Warning: Low margin", NotificationType.Warning); await quik.Service.Message("Error: Connection lost", NotificationType.Error); // Get script path string scriptPath = await quik.Service.GetScriptPath(); // Get information window parameters string serverTime = await quik.Service.GetInfoParam(InfoParams.SERVERTIME); string userName = await quik.Service.GetInfoParam(InfoParams.USER); // Add label to chart double labelId = await quik.Service.AddLabel( chartTag: "SBER_M15", yValue: 250.50m, strDate: "20240115", strTime: "103000", text: "Entry Point", imagePath: "", alignment: "LEFT", hint: "Buy signal", r: 0, g: 255, b: 0, transparency: 0, tranBackgrnd: 1, fontName: "Arial", fontHeight: 12 ); // Delete label await quik.Service.DelLabel("SBER_M15", labelId); // Delete all labels from chart await quik.Service.DelAllLabels("SBER_M15"); ``` -------------------------------- ### Retrieve Account Limits and Positions in C# Source: https://context7.com/finsight/quiksharp/llms.txt Functions to fetch money limits, depo limits, and futures limits for trading accounts. These functions allow retrieval of current balances, positions, and margin information, with options for extended data and filtering by security. ```csharp // Get money limits (stock market) MoneyLimit moneyLimit = await quik.Trading.GetMoney("CLIENT001", "FIRM001", "EQTV", "SUR"); Console.WriteLine($"Available: {moneyLimit.CurrentBal}"); // Get extended money limits with limit type MoneyLimitEx moneyLimitEx = await quik.Trading.GetMoneyEx("FIRM001", "CLIENT001", "EQTV", "SUR", 2); Console.WriteLine($"T+2 Available: {moneyLimitEx.CurrentBal}"); // Get all money limits List allMoneyLimits = await quik.Trading.GetMoneyLimits(); // Get depo limits (security positions) DepoLimit depoLimit = await quik.Trading.GetDepo("CLIENT001", "FIRM001", "SBER", "L01+00000F00"); Console.WriteLine($"Position: {depoLimit.CurrentBal}"); // Get extended depo limits DepoLimitEx depoLimitEx = await quik.Trading.GetDepoEx("FIRM001", "CLIENT001", "SBER", "L01+00000F00", 2); Console.WriteLine($"T+2 Position: {depoLimitEx.CurrentBalance}"); // Get all depo limits List allDepoLimits = await quik.Trading.GetDepoLimits(); List sberLimits = await quik.Trading.GetDepoLimits("SBER"); // Get futures limits FuturesLimits futLimit = await quik.Trading.GetFuturesLimit("FIRM001", "SPBFUT001", 0, "SUR"); Console.WriteLine($"Free margin: {futLimit.CbpLUsed}"); // Get all futures limits List allFutLimits = await quik.Trading.GetFuturesClientLimits(); // Get futures positions FuturesClientHolding futPos = await quik.Trading.GetFuturesHolding("FIRM001", "SPBFUT001", "SiH4", 0); Console.WriteLine($"Net position: {futPos.totalNet}"); // Get all futures positions List allFutPositions = await quik.Trading.GetFuturesClientHoldings(); // Get portfolio info PortfolioInfo portfolio = await quik.Trading.GetPortfolioInfo("FIRM001", "CLIENT001"); PortfolioInfoEx portfolioEx = await quik.Trading.GetPortfolioInfoEx("FIRM001", "CLIENT001", 2); // Calculate max order quantity CalcBuySellResult calcResult = await quik.Trading.CalcBuySell( classCode: "TQBR", secCode: "SBER", clientCode: "CLIENT001", trdAccId: "L01+00000F00", price: 250.50, isBuy: true, isMarket: false ); Console.WriteLine($"Max lots: {calcResult.Qty}, Commission: {calcResult.Comission}"); // Get buy/sell info BuySellInfo bsInfo = await quik.Trading.GetBuySellInfo("FIRM001", "CLIENT001", "TQBR", "SBER", 250.50); ``` -------------------------------- ### Event Handlers API Source: https://context7.com/finsight/quiksharp/llms.txt Provides comprehensive event handlers for real-time market data, trading notifications, connection status, and session events. ```APIDOC ## Event Handlers API ### Description QUIKSharp provides comprehensive event handlers for real-time market data and trading notifications, connection status, and session events. ### Connection Events - **OnConnectedToQuik** - **Description**: Triggered when successfully connected to the QUIK terminal. - **Parameters**: `int port` - The port number QUIK is connected on. - **OnDisconnectedFromQuik** - **Description**: Triggered when disconnected from the QUIK terminal. - **OnConnected** - **Description**: Triggered when QUIK successfully connects to the trading server. - **OnDisconnected** - **Description**: Triggered when QUIK disconnects from the trading server. ### Market Data Events - **OnAllTrade** - **Description**: Triggered for every public trade executed. - **Parameters**: `AllTrade trade` - An object containing details of the trade. - **OnQuote** - **Description**: Triggered when the order book (quote) is updated. - **Parameters**: `OrderBook quote` - An object containing order book details. - **OnParam** - **Description**: Triggered when a parameter for a security changes. - **Parameters**: `Param param` - An object containing parameter details. ### Trading Events - **OnOrder** - **Description**: Triggered when an order's state changes. - **Parameters**: `Order order` - An object containing order details. - **OnTrade** - **Description**: Triggered when a trade is executed from an order. - **Parameters**: `Trade trade` - An object containing trade details. - **OnStopOrder** - **Description**: Triggered when a stop order's state changes. - **Parameters**: `StopOrder stopOrder` - An object containing stop order details. - **OnTransReply** - **Description**: Triggered in response to a transaction request. - **Parameters**: `TransactionReply reply` - An object containing transaction reply details. ### Position and Limit Events - **OnFuturesClientHolding** - **Description**: Triggered when there is an update to futures client holdings. - **Parameters**: `FuturesClientHolding holding` - An object containing futures holding details. - **OnDepoLimit** - **Description**: Triggered when deposit limits are updated. - **Parameters**: `DepoLimitEx limit` - An object containing deposit limit details. - **OnMoneyLimit** - **Description**: Triggered when money limits are updated. - **Parameters**: `MoneyLimit limit` - An object containing money limit details. - **OnFuturesLimitChange** - **Description**: Triggered when futures limits are updated. - **Parameters**: `FuturesLimits limit` - An object containing futures limit details. ### Session Events - **OnCleanUp** - **Description**: Triggered at the beginning of a new trading day (session cleanup). - **OnClose** - **Description**: Triggered when the QUIK terminal is closing. - **OnStop** - **Description**: Triggered when the script is stopping. - **Parameters**: `int flag` - A flag indicating the reason for stopping. ``` -------------------------------- ### Candlestick Data Management in C# Source: https://context7.com/finsight/quiksharp/llms.txt Functions for subscribing to, retrieving, and handling candlestick (OHLCV) data. Supports various intervals, parameters like bid/ask, and data from existing QUIK charts. Includes event handling for new candles. ```csharp await quik.Candles.Subscribe("TQBR", "SBER", CandleInterval.M15); bool isSubscribed = await quik.Candles.IsSubscribed("TQBR", "SBER", CandleInterval.M15); List allCandles = await quik.Candles.GetAllCandles("TQBR", "SBER", CandleInterval.M15); foreach (var candle in allCandles) { Console.WriteLine($"{candle.Datetime}: O={candle.Open}, H={candle.High}, L={candle.Low}, C={candle.Close}, V={candle.Volume}"); } List lastCandles = await quik.Candles.GetLastCandles("TQBR", "SBER", CandleInterval.H1, count: 100); await quik.Candles.Subscribe("TQBR", "SBER", CandleInterval.M15, "bid"); List bidCandles = await quik.Candles.GetAllCandles("TQBR", "SBER", CandleInterval.M15, "bid"); int numCandles = await quik.Candles.GetNumCandles("SBER_M15_Chart"); List chartCandles = await quik.Candles.GetAllCandles("SBER_M15_Chart"); List rangeCandles = await quik.Candles.GetCandles( graphicTag: "SBER_M15_Chart", line: 0, first: 100, count: 50 ); quik.Candles.NewCandle += (Candle candle) => { if (candle.ClassCode == "TQBR" && candle.SecCode == "SBER" && candle.Interval == CandleInterval.M15) { Console.WriteLine($"New candle: {candle.Datetime} Close={candle.Close}"); } }; await quik.Candles.Unsubscribe("TQBR", "SBER", CandleInterval.M15); // Available intervals: TICK, M1, M2, M15, M20, M30, H1, H2, H4, D1, W1, MN1 ``` -------------------------------- ### Stop Order Functions API Source: https://context7.com/finsight/quiksharp/llms.txt Enables the creation and management of stop orders, including stop-limit, take-profit, and combined orders. Allows retrieval of all stop orders or those for a specific instrument, and cancellation of stop orders. ```APIDOC ## Stop Order Functions ### Description Functions for creating and managing stop orders including stop-limit, take-profit, and combined orders. ### Method POST (for creating), GET (for retrieving), DELETE (for canceling) - Implied by `CreateStopOrder`, `GetStopOrders`, `KillStopOrder` ### Endpoint `/finsight/quiksharp/stoporders` (Implied) ### Parameters #### Request Body (for CreateStopOrder) - **stopOrder** (StopOrder object) - Required - Details of the stop order to create. - **ClassCode** (string) - Required - The class code of the instrument. - **SecCode** (string) - Required - The security code of the instrument. - **Account** (string) - Required - The account number. - **Operation** (Operation) - Required - The operation type (e.g., Sell, Buy). - **Quantity** (int) - Required - The quantity of the instrument. - **StopOrderType** (StopOrderType) - Required - The type of stop order (e.g., StopLimit, TakeProfit, TakeProfitStopLimit). - **ConditionPrice** (decimal) - Required - The trigger price for the stop order. - **Price** (decimal) - Optional - The execution price for stop-limit orders. - **Offset** (decimal) - Optional - Offset value for take-profit or stop-limit orders. - **OffsetUnit** (OffsetUnits) - Optional - Unit for the offset (e.g., PRICE_UNITS, PERCENTS). - **Spread** (decimal) - Optional - Spread value for take-profit or stop-limit orders. - **SpreadUnit** (OffsetUnits) - Optional - Unit for the spread (e.g., PRICE_UNITS, PERCENTS). - **ClientCode** (string) - Optional - The client code. - **ConditionPrice2** (decimal) - Optional - The second trigger price for combined orders. #### Path Parameters (for GetStopOrders) - **classCode** (string) - Optional - The class code of the instrument to filter by. - **secCode** (string) - Optional - The security code of the instrument to filter by. #### Request Body (for KillStopOrder) - **stopOrder** (StopOrder object) - Required - The stop order object to cancel. ### Request Example ```csharp StopOrder stopLimitOrder = new StopOrder { ClassCode = "SPBFUT", SecCode = "SiH4", Account = "SPBFUT001", Operation = Operation.Sell, Quantity = 1, StopOrderType = StopOrderType.StopLimit, ConditionPrice = 92000m, // Trigger price Price = 91950m // Execution price }; long stopOrderId = await quik.StopOrders.CreateStopOrder(stopLimitOrder); ``` ### Response #### Success Response (200) - **stopOrderId** (long) - The ID of the created stop order. - **List** - A list of stop orders when retrieving all or filtered stop orders. #### Error Response - Error details if the operation fails. ### Event Handling - **OnStopOrder** (StopOrder) - Event triggered when a stop order's state changes. - **NewStopOrder** (StopOrder) - Event triggered when a new stop order is created. ``` -------------------------------- ### Transaction Functions API Source: https://context7.com/finsight/quiksharp/llms.txt Provides direct transaction API for advanced order operations including REPO, negotiated deals, and order modifications. Supports creating new orders, canceling orders, and subscribing to transaction replies and events. ```APIDOC ## Transaction Functions ### Description Direct transaction API for advanced order operations including REPO, negotiated deals, and order modifications. ### Method POST (Implied by `SendTransaction`) ### Endpoint `/finsight/quiksharp/transactions` (Implied) ### Parameters #### Request Body - **transaction** (Transaction object) - Required - Details of the transaction to be sent. - **ACTION** (TransactionAction) - Required - The action to perform (e.g., NEW_ORDER, KILL_ORDER). - **CLASSCODE** (string) - Required - The class code of the instrument. - **SECCODE** (string) - Required - The security code of the instrument. - **ACCOUNT** (string) - Required - The account number. - **CLIENT_CODE** (string) - Optional - The client code. - **OPERATION** (TransactionOperation) - Required - The operation type (e.g., B for Buy, S for Sell). - **PRICE** (decimal) - Optional - The price for the order. - **QUANTITY** (int) - Optional - The quantity of the instrument. - **TYPE** (TransactionType) - Optional - The type of order (e.g., L for Limit). - **EXECUTION_CONDITION** (ExecutionCondition) - Optional - The execution condition. - **ORDER_KEY** (string) - Required for KILL_ORDER - The order number to cancel. ### Request Example ```csharp Transaction transaction = new Transaction { ACTION = TransactionAction.NEW_ORDER, CLASSCODE = "TQBR", SECCODE = "SBER", ACCOUNT = "L01+00000F00", CLIENT_CODE = "CLIENT001", OPERATION = TransactionOperation.B, // Buy PRICE = 250.00m, QUANTITY = 10, TYPE = TransactionType.L, // Limit order EXECUTION_CONDITION = ExecutionCondition.PUT_IN_QUEUE }; long transId = await quik.Trading.SendTransaction(transaction); ``` ### Response #### Success Response (200) - **transId** (long) - The transaction ID if successful. #### Error Response - **ErrorMessage** (string) - Error message if the transaction failed. ### Event Handling - **OnTransReply** (TransactionReply) - Event triggered when a transaction reply is received. - **OnOrder** (Order) - Event triggered when an order is created. - **OnTrade** (Trade) - Event triggered when a trade occurs from a transaction. ``` -------------------------------- ### Candle Functions API Source: https://context7.com/finsight/quiksharp/llms.txt Functions for subscribing to and retrieving historical candlestick (OHLCV) data, with options for different intervals, parameters, and chart tags. ```APIDOC ## Candle Functions API ### Description Functions for subscribing to and retrieving historical candlestick (OHLCV) data. Supports various intervals, parameters like 'bid', and retrieval by chart tag. ### Methods - **Subscribe** - **Description**: Subscribes to real-time candle updates for a given instrument and interval. - **Parameters**: - `classCode` (string) - Required - The class code of the instrument. - `secCode` (string) - Required - The security code of the instrument. - `interval` (CandleInterval) - Required - The candle interval (e.g., M15, H1). - `param` (string) - Optional - Additional parameter (e.g., 'bid'). - **IsSubscribed** - **Description**: Checks if a subscription to candle updates is active for a given instrument and interval. - **Parameters**: - `classCode` (string) - Required - The class code of the instrument. - `secCode` (string) - Required - The security code of the instrument. - `interval` (CandleInterval) - Required - The candle interval. - `param` (string) - Optional - The subscription parameter. - **Returns**: `bool` - True if subscribed, false otherwise. - **GetAllCandles** - **Description**: Retrieves all historical candles for a given instrument and interval. - **Parameters**: - `classCode` (string) - Required - The class code of the instrument. - `secCode` (string) - Required - The security code of the instrument. - `interval` (CandleInterval) - Required - The candle interval. - `param` (string) - Optional - The parameter for which to retrieve candles. - **Returns**: `List` - A list of Candle objects. - **GetLastCandles** - **Description**: Retrieves the last N candles for a given instrument and interval. - **Parameters**: - `classCode` (string) - Required - The class code of the instrument. - `secCode` (string) - Required - The security code of the instrument. - `interval` (CandleInterval) - Required - The candle interval. - `count` (int) - Required - The number of candles to retrieve. - `param` (string) - Optional - The parameter for which to retrieve candles. - **Returns**: `List` - A list of Candle objects. - **GetNumCandles** - **Description**: Retrieves the number of candles available for a specific chart tag. - **Parameters**: - `graphicTag` (string) - Required - The tag of the chart. - **Returns**: `int` - The number of candles. - **GetCandles** - **Description**: Retrieves a specific range of candles from a chart by its tag. - **Parameters**: - `graphicTag` (string) - Required - The tag of the chart. - `line` (int) - Required - The line index within the chart. - `first` (int) - Required - The starting index of the candle range. - `count` (int) - Required - The number of candles to retrieve. - **Returns**: `List` - A list of Candle objects. - **Unsubscribe** - **Description**: Unsubscribes from real-time candle updates. - **Parameters**: - `classCode` (string) - Required - The class code of the instrument. - `secCode` (string) - Required - The security code of the instrument. - `interval` (CandleInterval) - Required - The candle interval. - `param` (string) - Optional - The subscription parameter. ### Events - **NewCandle** - **Description**: Event triggered when a new candle is formed. - **Parameters**: `Candle candle` - The newly formed candle object. ### Available Intervals TICK, M1, M2, M3, M4, M5, M6, M10, M15, M20, M30, H1, H2, H4, D1, W1, MN1 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.