Пример #1
0
        public ApiResult Login()
        {
            var success = new ApiResult {
                Result = true
            };

            if (LoginAccounts.ContainsKey(Account.MainID))
            {
                return(success);
            }

            TdxTrade1Api.OpenTdx();
            var error = new StringBuilder(ErrorCapacity);

            var clientId = TdxTrade1Api.Logon(Host.IPAddress, (short)Host.Port,
                                              Account.TradeApiVersion, Account.YingYeBuDM,
                                              Account.MainID, Account.MainID, Account.TradePassword, Account.MessagePassword, error);

            if (clientId > -1)
            {
                LoginAccounts.GetOrAdd(Account.MainID, clientId);
            }
            return(new ApiResult
            {
                Result = clientId == -1,
                Error = error.ToString()
            });
        }
Пример #2
0
        public ApiResult Cancel(string stockCode, string authorizeIndex)
        {
            var data  = new StringBuilder(ResultCapacity);
            var error = new StringBuilder(ErrorCapacity);

            TdxTrade1Api.CancelOrder(GetClientId(), authorizeIndex, data, error);
            return(new ApiResult
            {
                Result = error.Length == 0,
                Data = data.ToString(),
                Error = error.ToString()
            });
        }
Пример #3
0
        public ApiResult Buy(string stockCode, int number, double price)
        {
            var data  = new StringBuilder(ResultCapacity);
            var error = new StringBuilder(ErrorCapacity);

            TdxTrade1Api.SendOrder(GetClientId(), 0, 0, GetGDDM(stockCode), stockCode, (float)price, number, data, error);
            return(new ApiResult
            {
                Result = error.Length == 0,
                Data = data.ToString(),
                Error = error.ToString()
            });
        }
Пример #4
0
        public ApiResult QueryTrades()
        {
            var data  = new StringBuilder(ResultCapacity);
            var error = new StringBuilder(ErrorCapacity);

            TdxTrade1Api.QueryData(GetClientId(), 3, data, error);
            RemoveFirstLine(data);
            return(new ApiResult
            {
                Result = error.Length == 0,
                Data = data.ToString(),
                Error = error.ToString()
            });
        }
Пример #5
0
        public ApiResult QueryHistoryTrade(DateTime startTime, DateTime endTime)
        {
            var data  = new StringBuilder(ResultCapacity);
            var error = new StringBuilder(ErrorCapacity);

            TdxTrade1Api.QueryHistoryData(GetClientId(), 1, startTime.ToString("yyyyMMdd"), endTime.ToString("yyyyMMdd"), data, error);
            RemoveFirstLine(data);
            return(new ApiResult
            {
                Result = error.Length == 0,
                Data = data.ToString(),
                Error = error.ToString()
            });
        }