You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Matriks IQ平台C#编译错误:OrderStatusEventArgs不是类型

问题:Matriks IQ平台自定义交易算法OnOrderUpdate方法编译错误:"OrderStatusEventArgs is not a type"

我在Matriks IQ平台开发继承自MatriksAlgo的自定义交易算法时,重写OnOrderUpdate方法遇到编译错误:"OrderStatusEventArgs is not a type"

已尝试的修复措施(均未解决)

  • 确认已正确导入所需命名空间(using Matriks.Trader.Core.Events; 和 using Matriks.Trader.Core.Orders;);
  • 查阅Matriks API文档确认OrderStatusEventArgs是否存在;
  • 尝试使用ExecutionReportEventArgs、OrderEventArgs等替代事件参数类;
  • 手动定义自定义OrderStatusEventArgs类,但引发冲突或异常行为。

相关代码

using System;

using Matriks.Data.Symbol;
using Matriks.Engines;
using Matriks.Symbols;
using Matriks.Trader.Core;
using Matriks.Trader.Core.Fields;
using Matriks.Trader.Core.TraderModels;
using Matriks.Lean.Algotrader.AlgoBase;
using Matriks.Lean.Algotrader.Models;
using Matriks.Lean.Algotrader.Trading;
using Matriks.Data.Tick;
using Matriks.Enumeration;

namespace Matriks.Lean.Algotrader
{
    public class OrderStatusEventArgs : EventArgs 
    { 
        public string OrderId { get; set; } 
        public OrdStatus Status { get; set; }   
        
        public OrderStatusEventArgs(string orderId, OrdStatus status)
        {
            OrderId = orderId;
            Status = status;
        }
    }

    public class oco_v2 : MatriksAlgo
    {
        [SymbolParameter("ENDAE")]
        public string Symbol;

        [Parameter(SymbolPeriod.Min5)]
        public SymbolPeriod SymbolPeriod;

        [Parameter(3)]  // 卖出数量
        public decimal SellOrderQuantity;

        [Parameter(16.5)]  // 目标价格(限价卖出)
        public decimal TargetSellPrice;

        [Parameter(16.35)]  // 止损触发价格
        public decimal StopTriggerPrice;

        [Parameter(16)]  // 止损限价卖出价格
        public decimal StopLimitSellPrice;

        private bool limitOrderPlaced = false;
        private bool stopOrderPlaced = false;
        private string limitOrderId;
        private string stopOrderId;
        private string OrderId;

        public override void OnInit()
        {
            AddSymbol(Symbol, SymbolPeriod);
            AddSymbolMarketData(Symbol);
            Debug("限价与止损限价卖出策略启动。");
        }

        public override void OnDataUpdate(BarDataEventArgs barData)
        {
            decimal currentPrice = barData.BarData.Close;
            Debug($"当前价格: {currentPrice}, 目标卖出价格: {TargetSellPrice}, 止损触发价格: {StopTriggerPrice}, 止损限价卖出价格: {StopLimitSellPrice}");

            // 发送限价卖出订单(价格达到目标时)
            if (currentPrice >= TargetSellPrice && !limitOrderPlaced)
            {
                limitOrderId = SendLimitOrder(Symbol, SellOrderQuantity, OrderSide.Sell, TargetSellPrice);
                Debug($"限价卖出订单已发送 -> ID: {limitOrderId}, 价格: {TargetSellPrice}, 数量: {SellOrderQuantity}");
                limitOrderPlaced = true;
            }

            // 触发止损限价时发送限价订单
            if (currentPrice <= StopTriggerPrice && !stopOrderPlaced)
            {
                stopOrderId = SendLimitOrder(Symbol, SellOrderQuantity, OrderSide.Sell, StopLimitSellPrice );
                Debug($"止损限价卖出订单已发送 -> ID: {stopOrderId}, 止损价格: {StopTriggerPrice}, 限价价格: {StopLimitSellPrice}, 数量: {SellOrderQuantity}");
                stopOrderPlaced = true;
            }
        }

        public override void OnOrderUpdate (object sender, OrderEventArgs orderStatus)
        {
            if (orderStatus.OrderId == limitOrderId && orderStatus.Status == OrdStatus.Filled)
            {
                Debug("限价卖出订单已成交!正在取消止损订单...");
                if (!string.IsNullOrEmpty(stopOrderId))
                {
                    CancelStopLoss(stopOrderId);
                    Debug($"止损限价订单已取消 -> ID: {stopOrderId}");
                }
            }

            if (orderStatus.OrderId == stopOrderId && orderStatus.Status == OrdStatus.Filled)
            {
                Debug("止损限价卖出订单已成交!正在取消限价订单...");
                if (!string.IsNullOrEmpty(limitOrderId))
                {
                    CancelTakeProfit(limitOrderId);
                    Debug($"限价卖出订单已取消 -> ID: {limitOrderId}");
                }
            }
        }

        public override void OnStopped()
        {
            Debug("限价与止损限价卖出策略已停止。");
        }
    }
}

内容的提问来源于stack exchange,提问作者Sarp Acar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 06:17:14