Documentation

##### WSO2 WSAS 2.2-RC1

- Release Notes
- Contents
- Home

##### Downloads

- Releases

##### Documentation

- User Guide
- FAQs
- Installation Guide
- Source
- Running Behind a Proxy
- Data Services Guide
  - RDBMS Data Source
  - CSV Data Source
  - Excel Data Source
  - JNDI Data Source
- EJB Guide
- Clustering Guide
- JMX Guide
- XKMS Guide
- Changing Keys

##### Samples

- Chad
- Commodity Quote
- Data Services
- Flickr
- Javascript
- Jaxws
- JiBX
- Mtom
- STS
- Trader
- Tiny URL
- Metadata Exchange
- WS-Transfer
- XML Key Managment Specification
- Cluster Management

##### API Documentation

- Java Docs

##### Tools

- Code Generation
- Change Password
- Eclipse IDE Integration
- TCP Monitor
- WSDL2Code
- WSDL View
- Try It
- AAR Validation
- MAR Validation

##### Resources

- News

##### Get Involved

- Mailing Lists
- Integration

##### Project Information

- Project Team
- Issue Tracking
- License

# Trader Sample Guide

## INTRODUCTION

We will use this sample to demonstrate the capabilities of WSO2 WSAS, highlighting the ease of integration of QoS modules. In the context of this trading scenario, this emphasizes the use of security and reliable messaging.

In a nutshell, the trading sample takes place in a scenario where there are interactions taking place between a stock exchange, trader (stock broker) & client (shareholder). A shareholder who buys and sells shares on the stock market needs to do so through a stock broker or trader, in which case he would first need to become a client of that particular trader. The shareholder uses his Central Depository System (CDS) account which registers him with the stock exchange to sell & buy shares on the stock market. A trader can register his client (the shareholder) with the stock exchange.

The following section describes the services offered by each of the parties involved in this scenario.

## SCENARIO

Client creates an account with a trader by which the Client receives an user ID. The Trader in return, registers the Client with the stock exchange using client information. The Client obtains a CDS account at this registration through which he is allowed to trade on the stock market. The Client can only buy & sell shares on the market through the Trader. The Trader places these buy & sell orders of the Client on the stock exchange.

The Trader also registers feed targets to the Exchange.

To access any of the services from the stock exchange, The Trader needs to first login to the Exchange using the Trader's username & password.

The Clients get stock quotes (company name, symbol, selling price, high, low), and portfolio information from the Trader. He also deposits money in his account through the Trader.

The User (shareholder) can directly gain market information such as total traded shares, average price, and average size of trade from The stock exchange.

Trader provides market data updates to stock exchange

### In summary the services are as follows:

1. Services offered by Stock Exchange to Trader
   - Registering clients
   - Logging in to Stock Exchange
   - Buying and selling shares for Clients
   - Registering feed targets
2. Services offered by Stock Exchange to Client
   - Provide market information such as total traded shares, average price, average size of trade
3. Services offered by Trader to Client
   - Create accounts
   - Ability to make deposits to account
   - buying/ selling shares
   - get stock quote (name, symbol, price, high, low) and portfolio
4. Services offered by Trader to Stock Exchange
   - Provide market data updates

Note: attributes of Stock Quote are name, symbol, selling price, high price and low price

## HOW TO BUILD AND RUN THE SAMPLE

Trader sample is in WSO2WSAS_HOME|samples|Trader. To build the samples you need the Apache Ant build tool.

### Now follow these simple instructions:

1. Install and start WSO2 WSAS. See Installation Guide for installation details.
2. Switch to the Trader directory, e.g.

      cd WSO2WSAS_HOME\samples\Trader

3. From there simply type

      ant

You should see messages like this:

     Buildfile: build.xml

     clean:
     [delete] Deleting directory C:\wso2wsas-2.2-RC1\samples\Trader\temp

     init:
     [mkdir] Created dir: C:\wso2wsas-2.2-RC1\samples\Trader\temp
     [mkdir] Created dir: C:\wso2wsas-2.2-RC1\samples\Trader\temp\classes

     [some lines deleted here]

     build-all:
     [echo] Copying the created aar files in to the repository
     [copy] Copying 4 files to C:\wso2wsas-2.2-RC1\repository\services

     BUILD SUCCESSFUL
     Total time: 10 seconds
     C:\wso2wsas-2.2-RC1\samples\Trader>

The build automatically copies the .aar files containing the necessary services into the repository.
4. If you select the Services page in the Management Console you should now see the ExchangeTrader, ExchangeClient, TraderClient and TraderExchange services deployed. If you still don't see it, try restarting the system from the System page.
(See Administrator's Guide on how to sign into Management Console and to navigate through it.)
5. If you are still in the Trader directory, you will find the run-client.bat and run-client.sh files. Use the following command syntax at the prompt to run the client:
On MS Windows: run-client.bat [ -qos (rm | secure | securerm)] [-te <TraderService URL>] [-ee <ExchangeService URL> ] On Linux: run-client.sh [ -qos (rm | secure | securerm)] [-te <TraderService URL>] [-ee <ExchangeService URL> ] Terms used:

- TraderService URL is the End Point Reference (EPR) of the TraderClient. This can be obtained from the Management Console: The relevant service EPR can be found at Manage Services > Available services > service. For this sample the URL is "http://127.0.0.1:9762/services/TraderClient".
- ExchangeService URL is the EPR of the ExchangeClient. This can be obtained from the Management Console: The relevant service EPR can be found at Manage Services > Available services > service. For this example it is "http://127.0.0.1:9762/services/ExchangeClient".
- If rm, secure or securerm is to be used the following modules should be engaged. This can be done by selecting the Engage Module option from the Service Information page for the services listed in the management console.
  - rm - Sandesha (Sandesha2)
  - secure - Security (Rampart)
  - securerm - Both Sandesha and Security

Note:

1. If security is used the default username / password for the client is test / test.
2. The listed EPR's are for the standalone server. When WSO2 WSAS is running inside a servlet container, the EPR's are different and it is safe to get the EPR through the management console (services -> [service name])

### Let's illustrate the Trader with few examples:

#### Example 1: Without any module engaged.

From Trader directory type:

       ./run-client.sh

You should see:

       Populating the stock market ................Done.
       Using following parameters
       TraderService URL : http://localhost:9762/services/TraderClient
       ExchangeService URL :
       http://localhost:9762/services/ExchangeClient

       STARTING TRADE SAMPLE CLIENT
       =============================

       ...

       Please select your operation...
       ---------------------------------

       (1) createAccount
       (2) getQuote
       (3) getSymbols
       (4) deposit
       (5) buy
       (6) sell
       (7) getPortFolio
       (8) getMarketInfo
       (9) Exit

#### Example 2: With the security module engaged.

Logging to management console. Go to Security > Users > User Management. Then add a user "test" with password "test". Then go to Services > TraderClient > Security Configuration and select "Username Token authentication" and select "Continue". Then select user "test" and apply it. Follow the same steps for ExchangeClient service. From Trader directory type:

       ./run-client.sh -qos secure

You would see a prompt asking for the username and password before listing the operations available as follows:

       Populating the stock market ................Done.

       Using following parameters
       TraderService URL : http://localhost:9762/services/TraderClient
       ExchangeService URL :
       http://localhost:9762/services/ExchangeClient
       QOS : security

       STARTING TRADE SAMPLE CLIENT

       =============================

       ...

       Please enter your username :test
       Please enter your password :test

#### Example 3: Creating an account.

       ...Creating account...

       Please enter the Name:test1
       Please enter the password:test1

       Results
       -------

       User ID :test1

#### Example 4: Depositing money in the exchange.

       ...Doing deposit...

       Please enter the username:test1
       Please enter the password:test1
       Please enter the amount:100

       Deposit Successful !!

#### Example 5: Buying '100 mn' stocks in the exchange.

       ...Buying stocks...

       Please enter the username:test1
       Please enter the password:test1
       Please enter the symbol:mn
       Please enter the quantity:100

       Results
       -------

       Status :true
       Reason :Success

#### Example 6: Selling '50 mn' stocks in the exchange.

       ...Selling stocks...

       Please enter the username:test1
       Please enter the password:test1
       Please enter the symbol:mn
       Please enter the quantity:50

       Results
       ---------

       Status :true
       Reason :Success

#### Example 7: Getting the portfolio of the user 'test1' after buying a further '200 h' stocks.

       ...Getting Portfolio...

       Please enter the username:test1
       Please enter the password:test1

       Results
       -------

       Symbol:mn Amount:50
       Symbol:h Amount:200

Likewise, please explore the options available in the Trader client and see how it works for yourself!

## Things to Remember!

The behavior of the Trader service is that it internally calls the Stock exchange services. Since the internally used stubs try to use the configuration of the container by default, Engaging QoS on the Stock Exchange service will break the trader sample. Hence for the trader sample to run properly QoS should not be engaged on the Stock Exchange service.

## APPENDIX

- WSDL for services offered by Stock Exchange to Trader - "Exchange_Trader.wsdl"
- WSDL for services offered by Stock Exchange to Client - "Exchange_Client.wsdl"
- WSDL for services offered by Trader to Client - "Trader_Client.wsdl"
- WSDL for services offered by Trader to Stock Exchange - "Trader_Exchange.wsdl"