One of our customers has set us the task – develop a system for clients and brokerage accounts management through the web interface. One of the components of this system was to interact with web services provided by Currenex and perform several functions like accounts management (creation, modification) and generating reports based on a list of open positions.
Before us was the choice of programming language and development platform. Initially we planned to use Java, but after two days of fighting with documentation on web services, it was decided to use perl. Why perl? First of all, because perl will do more complicated things simple (and simple – well, as indeed some do).
There are several good modules on CPAN that allow to write applications using SOAP / Web Services, for example, SOAP:: Lite or SOAP:: WSDL. I already had experience of working with SOAP:: Lite (true five years ago:)), so we decided to stay on it.
According to the Currenex documentation each request must contain information about the open session, which is obtained as a result Login message.
my $login = "LOGIN"; my $password = "PASSWORD"; $SOAP::Constants::PREFIX_ENV = 'SOAP-ENV'; my $service = SOAP::Lite->service("https://pret-dl.currenex.com/webservice/xml/SharedMessages.wsdl"); $service->proxy("https://pret-dl.currenex.com/webservice/request/AuthenticationService"); my @res = $service->Login( SOAP::Data->name('userID')->value($login), SOAP::Data->name('password')->value($password), ); #This function returns array where second position is session ID my $sessionId = $res[1];
Lets fetch list of all registered accounts
$service->service("https://pret-dl.currenex.com/webservice/xml/HubRetailService.wsdl"); $service->proxy("https://pret-dl.currenex.com/webservice/request/HubRetailService"); my @result = $service->GetAccountList( SOAP::Data->name("hubUserID")->value($login), SOAP::Header->name("cx:session" => \SOAP::Header->value( SOAP::Header->name("cx:sessionTicket")->value($sessionId), SOAP::Header->name("cx:userID")->value($login) )) ); #Go through all accounts foreach (@result) { my $account = CNX::Account->new(); $account->account_id($_->{'accountID'}); $account->create_date($_->{'creationDate'}); my $settings = { 'marginStatus' => $_->{'marginStatus'} }; $account->settings($settings); push(@accounts, $account); }
Here is example of request to fetch list of all open positions and margin requirements.
my @result = $service->GetHubMarginBalances( SOAP::Header->name("cx:session" => \SOAP::Header->value( SOAP::Header->name("cx:sessionTicket")->value($sessionId), SOAP::Header->name("cx:userID")->value($login) )), SOAP::Data->name("hubUserID")->value($login), SOAP::Data->name("accountID")->value(@account_ids) );
As you can see, working with Web services Currenex of perl and use SOAP:: Lite’s no magic and all done simply and transparently. Specify at once that what we have done, is not a normal incarnation of web services, and the only solution was created in haste. So now we are working to transfer the developed solution for clean, classic WSDL.