Exemplo n.º 1
0
 //构造器
 public StrategyBase(string StrategyName, CMdApi mktApi, CTradeApi trdApi)
 {
     this._strategyName = StrategyName;
     this._mktApi       = mktApi;
     this._trdApi       = trdApi;
     //this._mktApi.OnTick += this.OnTick;
 }
Exemplo n.º 2
0
        /// <summary>
        /// 构造函数,传入PlatForm中的行情和交易Api作为参数
        /// </summary>
        public LoginWindow(MainWindow mw, CMdApi quoteApi, CTradeApi tradeApi)
        {
            InitializeComponent();

            //内部变量赋值
            this._mw           = mw;
            this._quoteApi     = quoteApi;
            this._tradeApi     = tradeApi;
            this._listBroker   = this.GetBrokerList();
            this._listInvestor = this.GetInvestorList();

            //行情交易参数初始化
            this.cbxServer.ItemsSource    = _listBroker.Select(fb => fb.Name);
            this.cbxBrokerID.ItemsSource  = _listBroker.Select(fb => fb.BrokerID);
            this.cbxQuoteIP.ItemsSource   = _listBroker.Select(fb => fb.QuoteIP);
            this.cbxQuotePort.ItemsSource = _listBroker.Select(fb => fb.QuotePort);
            this.cbxTradeIP.ItemsSource   = _listBroker.Select(fb => fb.TradeIP);
            this.cbxTradePort.ItemsSource = _listBroker.Select(fb => fb.TradePort);

            //账户参数初始化
            this.cbxInvestorID.ItemsSource = _listInvestor.Select(i => i.InvestorID);
            this.cbxPassword.ItemsSource   = _listInvestor.Select(i => i.Password);

            #if DEBUG
            this.cbxBrokerID.SelectedIndex   = 0;
            this.cbxPassword.SelectedIndex   = 0;
            this.cbxServer.SelectedIndex     = 0;
            this.cbxInvestorID.SelectedIndex = 0;
            this.cbxPassword.SelectedIndex   = 0;
            #else
            this.cbxBrokerID.SelectedIndex   = 1;
            this.cbxPassword.SelectedIndex   = 1;
            this.cbxServer.SelectedIndex     = 5;
            this.cbxInvestorID.SelectedIndex = 1;
            this.cbxPassword.SelectedIndex   = 1;
            #endif
        }
Exemplo n.º 3
0
 /// <summary>
 /// 3. Trade API
 /// </summary>
 public static async void XTradeApi(int debug_step = 1)
 {
     var _c_trade_api = new CTradeApi("", "");
 }
Exemplo n.º 4
0
        //登录
        async private void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                //禁用
                this.btnLogin.IsEnabled  = false;
                this.btnCancel.IsEnabled = true;
                //API初始化
                this._trdApi = new CTradeApi(this.cbxInvestorID.Text, this.cbxPassword.Text, this.cbxBrokerID.Text, "tcp://" + cbxTradeIP.Text + ":" + cbxTradePort.Text);
                this._mktApi = new CMdApi(this.cbxInvestorID.Text, this.cbxPassword.Text, this.cbxBrokerID.Text, "tcp://" + cbxQuoteIP.Text + ":" + cbxQuotePort.Text);
                Body.trdApi  = this._trdApi;
                Body.mktApi  = this._mktApi;

                #region 绑定后台Body
                this._mktApi.OnTick  += Body.Body_OnTick;
                this._trdApi.OnTrade += Body.Body_OnRtnTrade;
                //this._trdApi.OnDetailPosition += Body.Body_OnDetailPosition;
                //this._trdApi.OnPosition += Body.Body_OnPosition;
                this._trdApi.OnOrder          += Body.Body_OnOrderField;
                this._trdApi.OnErrorOrder     += Body.Body_OnErrorOrder;
                this._trdApi.OnUpdate         += Body.Body_OnUpdate;
                this._trdApi.OnTradingAccount += Body.Body_OnTradingAccount;
                #endregion

                //连接
                tbStatus.Text = "正在连接行情端...";
                await this._mktApi.AsyncConnect(_cts.Token);

                tbStatus.Text      = "行情端已连接!";
                progressBar.Value += 10;
                tbStatus.Text      = "正在连接交易端...";
                await _trdApi.AsyncConnect(_cts.Token);

                tbStatus.Text      = "交易端已连接!";
                progressBar.Value += 10;
                //登陆
                tbStatus.Text = "正在登陆行情端...";
                await _mktApi.AsyncLogin(_cts.Token);

                tbStatus.Text      = "行情端已登陆!";
                progressBar.Value += 10;
                tbStatus.Text      = "正在登陆交易端...";
                await _trdApi.AsyncLogin(_cts.Token);

                tbStatus.Text      = "交易端已登陆!";
                progressBar.Value += 10;
                //如果是今天第一次登陆,则要确认结算单
                if (IsFirstTimeLogin() || (bool)this.chxIsConfirmSettlementInfo.IsChecked)
                {
                    tbStatus.Text = "正在查询结算信息...";
                    _trdApi.StackQuery.Push(new Tuple <EnumReqCmdType, object>(EnumReqCmdType.QrySettlementInfo, string.Empty));
                    await _trdApi.ExecStackQuery();

                    MessageBox.Show(_trdApi.SettlementInfoContent);
                    tbStatus.Text = "正在确认结算信息...";
                    _trdApi.StackQuery.Push(new Tuple <EnumReqCmdType, object>(EnumReqCmdType.SettlementInfoConfirm, string.Empty));
                    await _trdApi.ExecStackQuery();

                    tbStatus.Text      = "已确认结算单!";
                    progressBar.Value += 10;
                }
                //查询合约
                tbStatus.Text = "正在查询合约...";
                _trdApi.StackQuery.Push(new Tuple <EnumReqCmdType, object>(EnumReqCmdType.QryInstrument, string.Empty));
                await _trdApi.ExecStackQuery();

                tbStatus.Text      = "合约查询完毕!";
                progressBar.Value += 10;
                //查询持仓细节
                tbStatus.Text = "正在查询持仓细节...";
                _trdApi.StackQuery.Push(new Tuple <EnumReqCmdType, object>(EnumReqCmdType.QryInvestorPositionDetail, string.Empty));
                await _trdApi.ExecStackQuery();

                tbStatus.Text      = "持仓细节查询完毕!";
                progressBar.Value += 10;
                //查询持仓
                tbStatus.Text = "正在查询持仓...";
                _trdApi.StackQuery.Push(new Tuple <EnumReqCmdType, object>(EnumReqCmdType.QryInvestorPosition, string.Empty));
                await _trdApi.ExecStackQuery();

                tbStatus.Text      = "持仓查询完毕!";
                progressBar.Value += 10;
                //查询交易账户信息
                tbStatus.Text = "正在交易账户...";
                _trdApi.StackQuery.Push(new Tuple <EnumReqCmdType, object>(EnumReqCmdType.QryTradingAccount, string.Empty));
                await _trdApi.ExecStackQuery();

                tbStatus.Text      = "交易账户查询完毕!";
                progressBar.Value += 10;
                //订阅行情数据
                tbStatus.Text = "正在订阅行情数据...";
                _mktApi.ReqSubscribeMarketData(_trdApi.DicInstrumentField.Keys.ToArray());
                progressBar.Value += 10;

                //调用主交易窗口
                Hide();
                MainWindow mainWindow = new MainWindow();
                Body.mainWindow = mainWindow;
                mainWindow.ShowDialog();
            }
            catch (Exception ex)
            {
                //this._mktApi.ReqUserLogout();
                //this._trdApi.ReqUserLogout();
                MessageBox.Show(ex.Message);
                this.btnCancel.IsEnabled = false;
                this.btnLogin.IsEnabled  = true;
                this.progressBar.Value   = 0;
            }
            finally
            {
                //关闭登录窗口
                Close();
            }
        }
Exemplo n.º 5
0
        //所有合约的市场行情数据
        public async static Task <ObservableCollection <DepthMarketData> > GenerateOCAllMarketDepthData(CMdApi MktApi, CTradeApi TrdApi)
        {
            var oc = new ObservableCollection <DepthMarketData>();

            while (MktApi.DicDepthMarketData.Count < TrdApi.DicInstrumentField.Count)
            {
                await Task.Delay(100);
            }
            lock (oc)
            {
                foreach (var kvp in Body.mktApi.DicDepthMarketData)
                {
                    oc.Add(kvp.Value);
                }
                return(oc);
            }
        }