www.gusucode.com > trading工具箱matlab源码程序 > trading/trading/@cqg/createOrder.m
function o = createOrder(c,s,orderType,accHandle,quantity,varargin) %CREATEORDER Create CQG order. % O = CREATEORDER(C,S,TYPE,ACCOUNT,QUANTITY) creates a CQG order % given the CQG connection handle, C, the security string or instrument % object, S, the order type, TYPE, account handle, ACCOUNT, and % QUANTITY. A positive QUANTITY denotes a Buy order and a negative % QUANTITY denotes a Sell order. % % Valid TYPE values are: % % 1 = Market Order % 2 = Limit Order % 3 = Stop Order % 4 = Stop Limit Order % % O = CREATEORDER(C,S,2,ACCOUNT,QUANTITY,LIMITPRICE) creates a CQG limit order % given the CQG connection handle, C, the security string or instrument % object, S, the order type, 2, account handle, ACCOUNT, % QUANTITY and the limit price, LIMITPRICE. % % O = CREATEORDER(C,S,3,ACCOUNT,QUANTITY,STOPPRICE) creates a CQG stop order % given the CQG connection handle, C, the security string or instrument % object, S, the order type, 3, account handle, ACCOUNT, % QUANTITY and the stop price, STOPPRICE. % % O = CREATEORDER(C,S,4,ACCOUNT,QUANTITY,LIMITPRICE,STOPPRICE) creates a % CQG stop limit order given the CQG connection handle, C, the security % string or instrument object, S, the order type, 4, account handle, % ACCOUNT, QUANTITY, the limit price, LIMITPRICE, and the stop price, % STOPPRICE. % % The example script CQGOrderWorkflow outlines using the different order % types and how to set up the input arguments. % % See also CQG, HISTORY, REALTIME, TIMESERIES. % Copyright 2013 The MathWorks, Inc. % Order side undefined currentOrderSide = 0; % Convert character input to cell array to allow for both input types of % string input if ischar(s) s = cellstr(s); end if ~iscell(s) s = {s}; end % Determine whether instrument input is name or object instType = class(s{1}); % Use appropriate CreateOrder* method switch instType case 'char' switch orderType case 1 %Market o = c.Handle.CreateOrderByInstrumentName(orderType,s{1},accHandle,quantity,currentOrderSide); case 2 %Limit % varargin{1} is the limit price o = c.Handle.CreateOrderByInstrumentName(orderType,s{1},accHandle,quantity,currentOrderSide,varargin{1}); case 3 %Stop % varargin{1} is the stop price o = c.Handle.CreateOrderByInstrumentName(orderType,s{1},accHandle,quantity,currentOrderSide,0,varargin{1}); case 4 %StopLimit % varargin{1} is the limit price, varargin{2} is the stop price o = c.Handle.CreateOrderByInstrumentName(orderType,s{1},accHandle,quantity,currentOrderSide,varargin{1},varargin{2}); end otherwise % CQG Interface.CQG_4.0_Type_Library_-_Revised_API.ICQGInstrument switch orderType case 1 %Market o = c.Handle.CreateOrder(orderType,s{1},accHandle,quantity,currentOrderSide); case 2 %Limit % varargin{1} is the limit price o = c.Handle.CreateOrder(orderType,s{1},accHandle,quantity,currentOrderSide,varargin{1}); case 3 %Stop % varargin{1} is the stop price o = c.Handle.CreateOrder(orderType,s{1},accHandle,quantity,currentOrderSide,0,varargin{1}); case 4 %StopLimit % varargin{1} is the limit price, varargin{2} is the stop price o = c.Handle.CreateOrder(orderType,s{1},accHandle,quantity,currentOrderSide,varargin{1},varargin{2}); end end end