"ClientConfigRequest", "ClientConfigResponse" => "ClientConfigResponse"); // create client in WSDL mode $client = new WSClient(array ("wsdl" =>"wsdl/config_svc.wsdl", "classmap" => $class_map, "to" => GetEndpoint())); // get proxy object reference form client $proxy = $client->getProxy(); $input = new ClientConfigRequest(); $input->Client = CLIENT_NAME; $response = $proxy->ClientConfigRequest($input); if($response) { $endPoint = $response->BS; } return $endPoint; } /** * This method registes a new user in the system * @param userID id of the user * @param password password of the user * @param fullname full name of the user * @param address address of the user * @param email email address of the user * @param creditcard credit card number of the user * @param openBalance initial balance of the user * @return account details of the registerd user on success. NULL otherwise. */ function RegisterUser($userID, $password, $fullname, $address, $email, $creditcard, $openBalance) { $proxy = GetProxy(); $input = new register(); $input->userID = $userID; $input->password = $password; $input->fullname = $fullname; $input->address = $address; $input->email = $email; $input->creditcard = $creditcard; $input->openBalance = $openBalance; $response = $proxy->register($input); return $response; } /** * Updates account profile information * @param userID id of the user * @param fullname full name of the user * @param email email address of the user * @param address address of the user * @param creditcard credit card number of the user * @param password password of the user * @return account details of the modified user on success. NULL otherwise. */ function UpdateAccountProfile($userID, $fullName, $email, $address, $creditCard, $password) { $proxy = GetProxy(); $input = new updateAccountProfile(); $input->profileData = new AccountProfileDataBean(); $input->profileData->userID = $userID; $input->profileData->password = $password; $input->profileData->fullName = $fullName; $input->profileData->address = $address; $input->profileData->email = $email; $input->profileData->creditCard = $creditCard; $response = $proxy->updateAccountProfile($input); return $response; } /** * Given the order details of a user, this method calculates summery of * activities of the user. This includes total money spent on buying stocks * total money earned from selling them etc. * @param ordersReturn collection of orders of a user * @return summery of user's activities */ function GetUserAccountSummary($ordersReturn) { $index = 0; while($ordersReturn->OrderDataBean[$index]) { if ($ordersReturn->OrderDataBean[$index]->orderType == ORDER_TYPE_BUY) { $buys = $buys + (($ordersReturn->OrderDataBean[$index]->price) * ($ordersReturn->OrderDataBean[$index]->quantity)) + ($ordersReturn->OrderDataBean[$index]->orderFee); } else if ($ordersReturn->OrderDataBean[$index]->orderType == ORDER_TYPE_SELL) { $sells = $sells + (($ordersReturn->OrderDataBean[$index]->price) * ($ordersReturn->OrderDataBean[$index]->quantity)) - ($ordersReturn->OrderDataBean[$index]->orderFee); } $tax = $tax + $ordersReturn->OrderDataBean[$index]->orderFee; $index ++; } $accountSummary = new userAccountSummary(); $accountSummary->totalBuys = $buys; $accountSummary->totalSells = $sells; $accountSummary->totalTax = $tax; $accountSummary->totalImpact = $buys + $tax - $sells; return $accountSummary; } /** * Given the holdings of a user, this methods calculate total market value of * holding and number of holdings * @param holdings collection of holdings of a user * @return summery of holding details */ function GetHoldingInformation($holdings) { $holdingsReturn = $holdings->getHoldingsReturn; $index = 0; $totalHoldings= 0; $marketValue = 0; while($holdingsReturn->HoldingDataBean[$index]) { $bean = $holdingsReturn->HoldingDataBean[$index]; if (!$quoteInfo[$bean->quoteID]) { $quotes = GetQuote($bean->quoteID); if ($quotes) $quotesReturn = $quotes->getQuoteReturn; $quoteInfo[$bean->quoteID] = $quotesReturn->price; } $marketValue = $marketValue + ($quoteInfo[$bean->quoteID]) * ($bean->quantity); $totalHoldings = $totalHoldings + $holdingsReturn->HoldingDataBean[$index]->quantity * $holdingsReturn->HoldingDataBean[$index]->purchasePrice; $index ++; } $holdingInfo = new holdingInformation(); $holdingInfo->totalHoldings = $marketValue; $holdingInfo->noOfHoldings = $index; return $holdingInfo; } /** * Writes user id to cookie * @param username user id of the current user */ function WriteCookie($username) { setcookie(COOKIE_USERNAME, $username, time()+3600); } /** * Deletes user id from cookie * @param username user id of current user */ function DeleteCookie($username) { setcookie(COOKIE_USERNAME, $username, time()-3600); if (isset($_COOKIE[COOKIE_USERNAME])) unset($_COOKIE[COOKIE_USERNAME]); } /** * When user logout, user id will be deleted from the cookie * @param username user id of current user */ function LogoutUser($username) { $proxy = GetProxy(); $input = new logout(); $input->userID = $username; $response = $proxy->logout($input); DeleteCookie($username); } /** * Gets user id from cookie */ function GetUserFromCookie() { return ($_COOKIE[COOKIE_USERNAME]); } /** * Checks whether user is logged in. If so, user id cookie would have * been already set. Checking whether cookie is set equals to check * whether user is logged in */ function IsLoggedIn() { return isset($_COOKIE[COOKIE_USERNAME]); } /** * Gets user id of current user */ function GetUser() { return ($_COOKIE[COOKIE_USERNAME]); } /** * Store business service's endpoint in cookie * @param endPoint end point address of the business service */ function WriteEndpoint($endPoint) { setcookie(COOKIE_ENDPOINT, $endPoint, time()+3600); } /** * Sets default end point */ function SetDefaultEndpoint() { if(GetEndpoint() == "") WriteEndpoint(DEFAULT_ENDPOINT); } /** * Gets stored end point address of business service */ function GetEndpoint() { return ($_COOKIE[COOKIE_ENDPOINT]); } /** * Gets proxy object to make communication with business service */ function GetProxy() { /*define the class map */ $class_map = array( "anyType" => "anyType", "login" => "login", "loginResponse" => "loginResponse", "AccountDataBean" => "AccountDataBean", "getOrders" => "getOrders", "getOrdersResponse" => "getOrdersResponse", "ArrayOfOrderDataBean" => "ArrayOfOrderDataBean", "OrderDataBean" => "OrderDataBean", "getAccountData" => "getAccountData", "getAccountDataResponse" => "getAccountDataResponse", "getAccountProfileData" => "getAccountProfileData", "getAccountProfileDataResponse" => "getAccountProfileDataResponse", "AccountProfileDataBean" => "AccountProfileDataBean", "updateAccountProfile" => "updateAccountProfile", "updateAccountProfileResponse" => "updateAccountProfileResponse", "logout" => "logout", "logoutResponse" => "logoutResponse", "buy" => "buy", "buyResponse" => "buyResponse", "sell" => "sell", "sellResponse" => "sellResponse", "getHoldings" => "getHoldings", "getHoldingsResponse" => "getHoldingsResponse", "ArrayOfHoldingDataBean" => "ArrayOfHoldingDataBean", "HoldingDataBean" => "HoldingDataBean", "register" => "register", "registerResponse" => "registerResponse", "getClosedOrders" => "getClosedOrders", "getClosedOrdersResponse" => "getClosedOrdersResponse", "getMarketSummary" => "getMarketSummary", "getMarketSummaryResponse" => "getMarketSummaryResponse", "MarketSummaryDataBeanWS" => "MarketSummaryDataBeanWS", "ArrayOfQuoteDataBean" => "ArrayOfQuoteDataBean", "QuoteDataBean" => "QuoteDataBean", "getQuote" => "getQuote", "getQuoteResponse" => "getQuoteResponse", "getHolding" => "getHolding", "getHoldingResponse" => "getHoldingResponse", "getTopOrders" => "getTopOrders", "getTopOrdersResponse" => "getTopOrdersResponse", "sellEnhanced" => "sellEnhanced", "sellEnhancedResponse" => "sellEnhancedResponse", "isOnline" => "isOnline", "isOnlineResponse" => "isOnlineResponse"); $client = new WSClient(array ("wsdl" =>"wsdl/TradeServiceWcf.svc.wsdl", "classmap" => $class_map, "to" => GetBSEndPoint())); //We can set this port through tcpmon $proxy = $client->getProxy(); return $proxy; } /** * Sends login request to verify whether current user is authorized * @param userid user id of current user * @param password password given by current user * @return profile id of the user if login is success. NULL otherwise */ function Login($userid, $password) { $proxy = GetProxy(); $input = new login(); $input->userID = $userid; $input->password = $password; $response = $proxy->login($input); return $response->loginReturn->profileID; } /** * Gets orders of current user * @param userid user id of current user * @return collection of orders of the user */ function GetOrders($userid) { $proxy = GetProxy(); $input = new getOrders(); $input->userID = $userid; $response = $proxy->getOrders($input); return $response; } /** * Gets market summary * @return market summery */ function GetMarketSummary() { $proxy = GetProxy(); $input = new getMarketSummary(); $response = $proxy->getMarketSummary($input); return $response; } /** * Gets account details of current user * @param userid user id of current user * @return account details if success. NULL otherwise */ function GetAccountData($userid) { $proxy = GetProxy(); $input = new getAccountData(); $input->userID = $userid; $response = $proxy->getAccountData($input); return $response; } /** * Gets account profile information of current user * @param userid user id of current user * @return account profile data of current user if success. NULL otherwise */ function GetAccountProfileData($userid) { $proxy = GetProxy(); $input = new getAccountProfileData(); $input->userID = $userid; $response = $proxy->getAccountProfileData($input); return $response; } /** * Gets holding details of given user * @param userid user id of current user * returns collection of holding if success. NULL otherwise */ function GetHoldings($userid) { $proxy = GetProxy(); $input = new getHoldings(); $input->userID = $userid; $response = $proxy->getHoldings($input); return $response; } /** * Gets quote of given symbol * @param symbol id of the stock * @return details of the symbol when success. NULL otherwise */ function GetQuote($symbol) { $proxy = GetProxy(); $input = new getQuote(); $input->symbol = $symbol; $response = $proxy->getQuote($input); return $response; } /** * Sells given holding or part of it of given user * @param userID user id of current user * @param holdingID holding id of the holding * @param quantity number of stocks to be sold * @return details of sell order if success. NULL otherwise */ function SellEnhanced($userID, $holdingID, $quantity) { $proxy = GetProxy(); $input = new sellEnhanced(); $input->userID = $userID; $input->holdingID = $holdingID; $input->quantity = $quantity; $response = $proxy->sellEnhanced($input); return $response; } /** * Buys number of stocks of given symbol * @param userID user id of current user * @param symbol symbol of needed stock * @quantity number of stocks needed * @mode mode of buying * @return details of buy order if success. NULL otherwise */ function Buy($userID, $symbol, $quantity, $mode) { $proxy = GetProxy(); $input = new buy(); $input->symbol = $symbol; $input->userID = $userID; $input->quantity = $quantity; $input->orderProcessingMode = $mode; $response = $proxy->buy($input); return $response; } /** * Gets closed orders of current user * @return collection of orders whose status is closed */ function GetClosedOrders() { $proxy = GetProxy(); $input = new getClosedOrders(); $input->userID = GetUserFromCookie(); if($input->userID) { $response = $proxy->getClosedOrders($input); $getClosedOrdersReturn = $response->getClosedOrdersReturn; } return $getClosedOrdersReturn; } /** * Gets closed orders of current user if there are any. Then prints it */ function checkForClosedOrders() { $proxy = GetProxy(); $input = new getClosedOrders(); $input->userID = GetUserFromCookie(); if($input->userID) { $response = $proxy->getClosedOrders($input); $getClosedOrdersReturn = $response->getClosedOrdersReturn; $index = 0; while ($getClosedOrdersReturn->OrderDataBean[$index]) { print("THIS IS THE ID OF THE JUST CLOSED ORDER:"); print($getClosedOrdersReturn->OrderDataBean[$index]->orderID); print("\n"); $index ++; } } } ?>