Main Content

Create Order Using Real-Time Snapshot WDS Data

This example shows how to connect to Wind Data Feed Services (WDS), retrieve real-time snapshot data, and perform simple data analysis to make an investment decision. The example then shows how to log in to the WDS order management system, create an order, and query information about the order. This example requires that you open and log in to the Wind Financial Terminal.

Connect to WDS

c = wind;

Retrieve Snapshot Data

Format output data for currency.

format bank

Using the 600000.SH security and the WDS connection, retrieve real-time snapshot data for the last price and volume fields.

s = '600000.SH';
f = {'rt_last','rt_vol'};

d = realtime(c,s,f)
d =
		
  1×3 timetable
		
            Time               Codes       RT_LAST       RT_VOL   
    ____________________    ___________    _______    ____________
		
    05-Dec-2017 12:33:50    '600000.SH'     13.17     123796797.00

d is a timetable that contains a row for the security with the time and these variables:

  • Security

  • Last price

  • Volume

Analyze Snapshot Price

Assume a price threshold of 12, specified in the CNY currency. Compare the snapshot price to the threshold. The sell indicator contains the logical value 1.

sellnow = (d.RT_LAST > 12);

Set the direction of the order by using the sell indicator.

if (sellnow)
    direction = 'Sell';
else
    direction = 'Buy';
end

Create WDS Order

Log in to the WDS order management system using the WDS connection. Specify the broker, branch, user name, password, and account type.

broker = "0000";
branch = "0";
capitalaccount = "1234567891011";
password = "abcdefghi";
accttype = "SHSZ";
dlogin = tradelogin(c,broker,branch, ...
    capitalaccount,password,accttype);

Create a sell order of 100 shares of the 600000.SH security using the WDS connection. Sell shares with the order price 13.17, specified in the CNY currency. Use the 'LogonID' name-value pair argument to specify the login identifier. Use the 'TradePassword' name-value pair argument to specify the password.

price = '13.17';
quantity = '100';
logonid = '1';
password = "abcdefghi";
d = createorder(c,s,direction,price,quantity, ...
    'LogonID',logonid,'TradePassword',password)
d =

  1×8 table

    RequestID    SecurityCode    TradeSide    OrderPrice    OrderVolume    LogonID    ErrorCode      ErrorMsg   
    _________    ____________    _________    __________    ___________    _______    _________    _____________

       20        '600000.sh'      'SELL'        '13.17'        '100'         '1'          0        'Sending ...'

d is a table with these variables:

  • Request identifier

  • Security code

  • Direction

  • Order price

  • Order volume

  • Login identifier

  • Error code

  • Error message

Query for the status of the executed order and display the status. The order status 'Normal' indicates successful order execution.

d = query(c,'Order');
d.OrderStatus
d =

  'Normal'

Close WDS Connection

Log out from the WDS order management system using the login identifier returned by the tradelogin function.

logonid = dlogin.LogonID;
d = tradelogout(c,logonid);

Close the WDS connection.

close(c)

See Also

| | | | | |

Related Topics

External Websites