Streamster API

The content below describe how to use the Streamster API to create applications that interface with the Streamster trading platform. Applications using the Streamster API can retrieve various data from the platform, execute and modify orders andpositions, and perform a variety of related actions.

To open and read a particular section, please click on its title.

1. Introduction to Streamster™ API

Streamster API exposes its functionality via the industry standard SOAP protocol. SOAP is widely supported on practically every programming platform, including PHP, Visual Basic, C#, C++, Java and many other languages and platforms.

To use Streamster API, an application connects to the SOAP service which is built into Streamster. To enable Streamster API and Streamster’s SOAP service, log on to your account and click the Settings button. Under “Advanced”, tick the “Enable web service API” box and click OK. Windows Firewall will then ask you to allow Streamster to accept connections on port 8018 – click the “Keep Blocking” button, which will prevent other computers on internet or your network from accessing Streamster API.

Once enabled, Streamster API is ready to service any requests coming from your computer. It is very important to note that requests coming from any computer other than yours will be always rejected, even if you allow Windows Firewall access to port 8018 from internet or any other computer or network. This is to prevent others on internet from accessing Streamster API on your computer and account. Note that there is no option in Streamster allowing circumvention of this protection.

With Streamster API enabled, you can use languages such as PHP and Visual Basic to run samples shown in the remainder of this document, or your own applications. For each Streamster API function you will see samples in PHP and Visual Basic. If you intend to use another language or platform, conversion of the sample code is usually very straightforward.

1.1. Using API from PHP

PHP supports SOAP and Streamster API very well. Installing PHP on your computer is simple – download and install the Windows binaries from the PHP.net site. PHP version 5 or later is required. Some PHP versions on Windows do not have SOAP enabled by default – you can enable the SOAP extension by editing the PHP.INI file and uncommenting the extension=php_soap.dll line.

To perform a simple PHP test, create a PHP file named “test.php” and edit it in Windows Notepad. Paste the following code into it:

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$quote = $api -> GetQuote("EUR/USD");
echo $quote -> Last;

?>

Test the above PHP script by running “php test.php” and it should simply display the last price of EUR/USD.

To test for critical errors (for example, when Streamster is not started at all, when method parameters are invalid, etc), you can use the standard PHP exception handling.

1.2. Using API from Visual Basic

Using Streamster API from Visual Basic is simple because it natively supports SOAP web services. There are numerous ways to consume a web service from Visual Basic, but the simplest is to add a “Web Service Reference” to your Visual Basic project. The address of the Streamster API Web Service is http://127.0.0.1:8018/service.wsdl and this is what needs to be specified when adding the web service reference to your Visual Basic project.

Once the reference is added to your project, using Streamster API is as simple as using any other Visual Basic object. For example, try the code below:

Dim api As StreamsterApi = New StreamsterApi
Dim q As Quote = api.GetQuote("EUR/USD")

Console.WriteLine ("Last = " & q.Last)

If your Visual Basic project is a Windows Forms application, you can change the last line to Label1.Text = q.Last or similar.

Depending on your version of Visual Basic, you will need to make sure you add a “Web Service Reference”, not a “Service Reference”. If you add a “Service Reference”, the name of the Streamster API class will be “StreamsterApiClientInterface” instead of just “StreamsterApi” so examples shown in this document would have to be updated accordingly in this case.

After Streamster API web service reference is added to your Visual Basic project, it is also necessary to add Streamster API web service reference to the list of “Imported Namespaces” in your Visual Basic project. This is necessary so that you will not have to prefix each Streamster API type with a web service reference name, which can be tedious.

To find out how to add a web service reference to the list of “Imported Namespaces” in your project, please consult the Visual Basic help system.

2. Streamster™ API Retrieval Methods

Once the SOAP object is created, Streamster API exposes a number of methods you can invoke to communicate with Streamster from your script or application. The following section explores available retrieval methods and related structures.

2.1. GetQuote

GetQuote method returns a “Quote” structure for a given instrument name. The Quote structure contains fields equivalent to columns in Rates windows in Streamster. GetQuote returns only fields available in Streamster – if you wish to retrieve any fields not currently shown in Streamster, you have to add them by clicking the Columns button.

Sample – PHP: The following sample retrieves a quote for EUR/USD, displays the “Last” field and then lists all available fields.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$quote = $api -> GetQuote("EUR/USD");

echo $quote -> Last . "\n";

foreach($quote as $field => $value) {
    echo $field . " = " . $value . "\n";
}

?>

Sample – Visual Basic: The following sample retrieves a quote for EUR/USD, displays the “Last” field and then displays all other fields.

Dim api As StreamsterApi = New StreamsterApi

Dim q As Quote
q = api.GetQuote("EUR/USD")

Console.WriteLine("Last: " & q.Last)
Console.WriteLine("Bid: " & q.Bid)
Console.WriteLine("Offer: " & q.Offer)
Console.WriteLine("Change: " & q.Change)
Console.WriteLine("High: " & q.High)
Console.WriteLine("Low: " & q.Low)
Console.WriteLine("Open: " & q.Open)
Console.WriteLine("Close: " & q.Close)
Console.WriteLine("Time: " & q.Time)
Console.WriteLine("Currency: " & q.Currency)
Console.WriteLine("Yield: " & q.Yield)
Console.WriteLine("Ask: " & q.Ask)
2.2. GetOrders

GetOrders method returns an array of “Order” structures. This array corresponds directly to the Orders window in Streamster. Each Order structure in the returned array contains one order with its associated fields as displayed in Streamster. GetOrders returns an array of Order structures which contain only fields available in Streamster – if you wish to retrieve any fields not currently shown in Streamster’s Orders window, you have to add them by clicking the Columns button.

Sample – PHP: The following sample retrieves all orders and lists them.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$r = $api -> GetOrders();
if(property_exists($r, "Order")) {
    foreach($r -> Order as $n => $OrderInfo) {
        echo "\tOrder " . $n . "\n";
        foreach($OrderInfo as $field => $value) {
            echo "\t\tField: " . $field . " = " . $value . "\n";
        }
    }
}

?>

Sample – Visual Basic: The following sample retrieves all orders and lists them.

Dim api As StreamsterApi = New StreamsterApi

Dim ao As Order()
Dim o As Order

ao = api.GetOrders()

For Each o In ao
    Console.WriteLine("")
    Console.WriteLine("Order:")

    Console.WriteLine("OrderID: " & o.OrderID)
    Console.WriteLine("Desk: " & o.Desk)
    Console.WriteLine("Instrument: " & o.Instrument)
    Console.WriteLine("Side: " & o.Side)
    Console.WriteLine("Phase: " & o.Phase)
    Console.WriteLine("PriceType: " & o.PriceType)
    Console.WriteLine("Price: " & o.Price)
    Console.WriteLine("ActiveQuantity: " & o.ActiveQuantity)
    Console.WriteLine("TradedQuantity: " & o.TradedQuantity)
    Console.WriteLine("ExitStopLoss: " & o.ExitStopLoss)
    Console.WriteLine("ExitTarget: " & o.ExitTarget)
    Console.WriteLine("Status: " & o.Status)
    Console.WriteLine("PositionID: " & o.PositionID)
    Console.WriteLine("Currency: " & o.Currency)
    Console.WriteLine("Duration: " & o.Duration)
    Console.WriteLine("DurationType: " & o.DurationType)
    Console.WriteLine("Quantity: " & o.Quantity)
    Console.WriteLine("QuantityType: " & o.QuantityType)
    Console.WriteLine("Text: " & o.Text)
    Console.WriteLine("Entered: " & o.Entered)
Next
2.3. GetTrades

GetTrades method returns an array of “Trade” structures. This array corresponds directly to the Trades window in Streamster. Each Trade structure in the returned array contains one trade with its associated fields as displayed in Streamster. GetTrades returns an array of Trade structures which contain only fields available in Streamster – if you wish to retrieve any fields not currently shown in Streamster’s Trades window, you have to add them by clicking the Columns button.

Sample – PHP: The following sample retrieves all trades and lists them.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$r = $api -> GetTrades();
if(property_exists($r, "Trade")) {
    foreach($r -> Trade as $n => $TradeInfo) {
        echo "\tTrade " . $n . "\n";
        foreach($TradeInfo as $field => $value) {
            echo "\t\tField: " . $field . " = " . $value . "\n";
        }
    }
}

?>

Sample – Visual Basic: The following sample retrieves all trades and lists them.

Dim api As StreamsterApi = New StreamsterApi

Dim at As Trade()
Dim t As Trade

at = api.GetTrades()

For Each t In at
    Console.WriteLine("")
    Console.WriteLine("Trade:")

    Console.WriteLine("TradeID: " & t.TradeID)
    Console.WriteLine("Desk: " & t.Desk)
    Console.WriteLine("Instrument: " & t.Instrument)
    Console.WriteLine("Side: " & t.Side)
    Console.WriteLine("Phase: " & t.Phase)
    Console.WriteLine("Price: " & t.Price)
    Console.WriteLine("Quantity: " & t.Quantity)
    Console.WriteLine("Executed: " & t.Executed)
    Console.WriteLine("Status: " & t.Status)
    Console.WriteLine("Currency: " & t.Currency)
    Console.WriteLine("Text: " & t.Text)
    Console.WriteLine("OrderID: " & t.OrderID)
Next
2.4. GetPositions

GetPositions method returns an array of “Position” structures. This array corresponds directly to the Positions window in Streamster. Each Position structure in the returned array contains one position with its associated fields as displayed in Streamster. GetPositions returns an array of Position structures which contain only fields available in Streamster – if you wish to retrieve any fields not currently shown in Streamster’s Positions window, you have to add them by clicking the Columns button.

Sample – PHP: The following sample retrieves all positions and lists them.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$r = $api -> GetPositions();
if(property_exists($r, "Position")) {
    foreach($r -> Position as $n => $PositionInfo) {
        echo "\tPosition " . $n . "\n";
        foreach($PositionInfo as $field => $value) {
            echo "\t\tField: " . $field . " = " . $value . "\n";
        }
    }
}

?>

Sample – Visual Basic: The following sample retrieves all positions and lists them.

Dim api As StreamsterApi = New StreamsterApi

Dim ap As Position()
Dim p As Position

ap = api.GetPositions()

For Each p In ap
    Console.WriteLine("")
    Console.WriteLine("Position:")

    Console.WriteLine("PositionID: " & p.PositionID)
    Console.WriteLine("Desk: " & p.Desk)
    Console.WriteLine("Instrument: " & p.Instrument)
    Console.WriteLine("Side: " & p.Side)
    Console.WriteLine("OpenPrice: " & p.OpenPrice)
    Console.WriteLine("Currency: " & p.Currency)
    Console.WriteLine("Quantity: " & p.Quantity)
    Console.WriteLine("Points: " & p.Points)
    Console.WriteLine("Profit: " & p.Profit)
    Console.WriteLine("ExitStopLoss: " & p.ExitStopLoss)
    Console.WriteLine("ExitTarget: " & p.ExitTarget)
    Console.WriteLine("Entered: " & p.Entered)
    Console.WriteLine("Exited: " & p.Exited)
    Console.WriteLine("Status: " & p.Status)
    Console.WriteLine("Text: " & p.Text)
    Console.WriteLine("ClosePrice: " & p.ClosePrice)
    Console.WriteLine("Interest: " & p.Interest)
Next
2.5. GetDesks

GetDesks method returns an array of “Desk” structures. Each Desk structure in the returned array describes one desk on your account, including the name of the desk, the amount available on the desk, and the currency in which this amount is available.

Sample – PHP: The following sample retrieves all desks and lists them.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$r = $api -> GetDesks();
if(property_exists($r, "Desk")) {
    foreach($r -> Desk as $n => $Desk) {
        echo "Name: " . $Desk -> Name;
        echo ", Currency: " . $Desk -> Currency;
        echo ", Amount: " . $Desk -> Amount;
        echo "\n";
    }
}

?>

Sample – Visual Basic: The following sample retrieves all desks and lists them.

Dim api As StreamsterApi = New StreamsterApi

Dim ad As Desk()
Dim d As Desk

ad = api.GetDesks()

For Each d In ad
    Console.WriteLine("Name: " & d.Name & ", Currency: " & d.Currency &
        ", Amount: " & d.Amount)
Next
2.6. GetBars

GetBars method retrieves an array of bars for a specified instrument and period. Each bar in the returned array of bars contains price at a specific point in time.

NOTE: Only bars from any open Charting windows in Streamster can be retrieved. If you wish to retrieve bars from your script for a specific instrument and period, you have to make sure that this instrument/period is shown in one of Streamster’s Charting windows.

The GetBars method has three parameters: instrument, period and a flag for options.

First parameter of the GetBars method is a string that specifies the instrument for which bars will be retrieved. The second parameter, Period, specifies the required period such as “5 Minutes”, “15 Minutes”, “30 Minutes”, “Hourly”, “4 Hours”, “Daily”, “Weekly”, or “Monthly”. The third parameter is a string that determines the order in which bars are returned: a blank string if bars are to be returned in descending order or a string “f” (as in “flip”) for ascending order.

Each bar in the returned array of bars has the following fields: BarDateTime, Open, High, Low, Close and Volume.

Sample – PHP: The following code retrieves 5-minute EUR/USD bars and shows them all.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$r = $api -> GetBars("EUR/USD", "5 minutes", "f");

if(property_exists($r, "Bar")) {
    foreach($r -> Bar as $n => $Bar) {
        echo $Bar -> BarDateTime . " " . $Bar -> Open . " " . $Bar -> High .
            " " . $Bar -> Low . " " . $Bar -> Close . "\n";
    }
}

?>

Sample – Visual Basic: The following code retrieves 5-minute EUR/USD bars and shows them all.

Dim api As StreamsterApi = New StreamsterApi

Dim ab As Bar()
Dim b As Bar

ab = api.GetBars("EUR/USD", "5 minutes", "")

For Each b In ab
    Console.WriteLine(b.BarDateTime & " " & b.Open & " " & b.High &
        " " & b.Low & " " & b.Close)
Next
2.7. GetLastMessage

GetLastMessage retrieves the last error or warning message displayed in Streamster, if any. The GetLastMessage method returns a blank string if there were no messages after the previous GetLastMessage call.

Sample – PHP: The following code shows the last error or warning message.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$r = $api -> GetLastMessage();

if($r != "") {
    echo($r);
}

?>

Sample – Visual Basic: The following code shows the last error or warning message.

Dim api As StreamsterApi = New StreamsterApi

Dim s As String

s = api.GetLastMessage()

If s <> "" Then Console.WriteLine(s)

3. Streamster™ API Trading Methods

Once the SOAP object is created, Streamster API exposes a number of methods you can invoke to communicate with Streamster from your script or application. The following section explores available trading methods and related structures.

3.1. SendOrder

SendOrder method sends a new order. It is an equivalent to clicking a New button in the Orders window in Streamster and then filling out the form and clicking OK. The SendOrder method has one parameter, an “Order” structure which contains details of the new order. The meaning of fields in the Order structure is the same as in the Send Order form in Streamster.

The following fields in the Order structure are valid and used when calling the SendOrder method:

Instrument: Name of the instrument (for example, EUR/USD), a required field
Side: BUY (Default) or SELL
PriceType: MARKET (Default), LIMIT or STOP
Price: Required field when PriceType parameter is set to LIMIT or STOP
DurationType: GTC (Default), GTD or IOC
Duration: Required when DurationType parameter is set to GTD (Good Till Date)
Quantity: Required field
QuantityType: FULL (Default) or PARTIAL
ExitStopLoss: Optional
ExitTarget: Optional
Desk: Name of the desk to use for the order, a required field
Currency: Required if there is more than one currency on the specified desk
Text: Optional

The SendOrder method has no return value – if an order is successful, it would normally appear in the Orders window shortly. If any parameter is invalid, an exception will be raised (as in all other Streamster API methods).

Sample – PHP: The following code sends a basic order.

 SOAP_SINGLE_ELEMENT_ARRAYS));

$api -> SendOrder(array(
    "Instrument" => "EUR/USD",
    "Desk" => "Virtual Forex",
    "Quantity" => 10
));

?>

The following code creates an order variable, fills out most of its fields and sends an order.

 SOAP_SINGLE_ELEMENT_ARRAYS));

$order -> Instrument = "Dow Jones";
$order -> Side = "BUY";
$order -> Price = 8756.24;
$order -> PriceType = "LIMIT";
$order -> ExitTarget = 8770;
$order -> Desk = "Testing";
$order -> Currency = "EUR";
$order -> Quantity = 10;
$order -> DurationType = "GTD";
$order -> Duration = date("c", time() + 3600);
$order -> Text = "test order from my script";

$api -> SendOrder($order);

?>

Sample – Visual Basic: The following code sends a basic order.

Dim api As StreamsterApi = New StreamsterApi

Dim o As Order = New Order

o.Instrument = "EUR/USD"
o.Desk = "Virtual Forex"
o.Quantity = 10
o.QuantitySpecified = True

api.SendOrder(o)

The following code sends an order with lots of optional parameters.

Dim api As StreamsterApi = New StreamsterApi

Dim o As Order = New Order

o.Instrument = "Dow Jones"
o.Side = "BUY"
o.Price = 8756.24
o.PriceSpecified = True
o.PriceType = "LIMIT"
o.ExitTarget = 8770
o.ExitTargetSpecified = True
o.Desk = "Testing"
o.Currency = "EUR"
o.Quantity = 10
o.QuantitySpecified = True
o.DurationType = "GTD"
o.Duration = DateAdd("d", 1, Now())
o.DurationSpecified = True
o.Text = "test order from my script"

api.SendOrder(o)
3.2. ChangeOrder

ChangeOrder changes certain parameters of a pending order. The ChangeOrder method has one parameter, an “Order” structure, which specifies the ID of the order to be changed and the new parameters of the order.

The following fields in the Order structure are valid and used when calling the ChangeOrder method:

OrderID: Contains the ID of the order to be changed
PriceType: MARKET (Default), LIMIT or STOP
Price: Required field when PriceType parameter is set to LIMIT or STOP
DurationType: GTC (Default), GTD or IOC
Duration: Required when DurationType parameter is set to GTD (Good Till Date)
Quantity: Required field
QuantityType: FULL (Default) or PARTIAL
ExitStopLoss: Optional; when empty, Exit Stop Loss parameter will be reset for the position
ExitTarget: Optional; when empty, Exit Target parameter will be reset for the position
Text: Sets the Text parameter of the position

All other fields in the Order structure are ignored when the ChangeOrder method is called.

NOTE: If any of the above fields are left empty, a default value will be assumed, not the previous value associated with the order. For example, if ChangeOrder is invoked with ExitStopLoss field left empty, the Exit Stop Loss value will be reset – it will not have the value as it was before the call.

Sample – PHP: The following code changes an order.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$order -> OrderID = "CR82JA01D";
$order -> Price = 8756.24;
$order -> PriceType = "LIMIT";
$order -> ExitTarget = 8765;
$order -> Quantity = 10;
$order -> DurationType = "GTD";
$order -> Duration = date("c", time() + 3600);
$order -> Text = "test order from my script";

$api -> ChangeOrder($order);

?>

Sample – Visual Basic: The following code changes an order.

Dim api As StreamsterApi = New StreamsterApi

Dim o As Order = New Order

o.OrderID = "K82LVC9DR"
o.Price = 8756.24
o.PriceSpecified = True
o.PriceType = "LIMIT"
o.ExitTarget = 8765
o.ExitTargetSpecified = True
o.Quantity = 10
o.QuantitySpecified = True
o.DurationType = "GTD"
o.Duration = DateAdd("d", 1, Now())
o.DurationSpecified = True
o.Text = "test order from my script"

api.ChangeOrder(o)
3.3. CancelOrder

CancelOrder cancels an order with a given Order ID. The CancelOrder method has one parameter, an “OrderID” string which specifies the order to be canceled. The CancelOrder method has no return value.

Sample – PHP: The following code cancels an order.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$api -> CancelOrder("Z4AEVG7Z0");

?>

Sample – Visual Basic: The following code cancels an order.

Dim api As StreamsterApi = New StreamsterApi

api.CancelOrder("Z4AEVG7Z0")
3.4. ChangePosition

ChangePosition changes certain parameters of an open position. The ChangePosition method has one parameter, a “Position” structure, which specifies the ID of the position to be changed and the new parameters of the position.

The following fields in the Position structure are valid and used when calling the ChangePosition method:

PositionID: Contains the ID of the position to be changed
ExitStopLoss: Sets the Exit Stop Loss parameter; when empty, Exit Stop Loss parameter will be reset for the position
ExitTarget: Sets the Exit Target parameter; when empty, Exit Target parameter will be reset for the position
Text: Sets the Text parameter of the position

All other fields in the Position structure are ignored when the ChangePosition method is called.

NOTE: If any of the above fields are left empty, a default value will be assumed, not the previous value associated with the order. For example, if ChangePosition is invoked with ExitStopLoss field left empty, the Exit Stop Loss value will be reset – it will not have the value as it was before the call.

Sample – PHP: The following code changes a position.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$position -> PositionID = "B2HN72VL3";
$position -> ExitStopLoss = 3.20;
$position -> ExitTarget = 3.50;
$position -> Text = "hello world";

$api -> ChangePosition($position);

?>

Sample – Visual Basic: The following code changes a position.

Dim api As StreamsterApi = New StreamsterApi

Dim p As Position = New Position

p.PositionID = "B2HN72VL3"
p.ExitStopLoss = 3.20
p.ExitStopLossSpecified = True
p.ExitTarget = 3.50
p.ExitTargetSpecified = True
p.Text = "hello world"

api.ChangePosition(p)
3.5. ClosePosition

ClosePosition closes a position with a given Position ID. The ClosePosition method has one parameter, a “PositionID” string which specifies the position to be closed. The ClosePosition method has no return value.

Sample – PHP: The following code closes a position.

<?php

$api = new SoapClient ("http://127.0.0.1:8018/service.wsdl",
    array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));

$api -> ClosePosition("B2HN72VL3");

?>

Sample – Visual Basic: The following code closes a position.

Dim api As StreamsterApi = New StreamsterApi

api.ClosePosition("B2HN72VL3")

Send us your comments and any suggestions you might have about the Streamster API.

We look forward to receiving your input and improving content on this page to help you utilize the API to its full extent.

Join the knowledgeable community of traders

It only takes 30 seconds.

Risk disclosure

Financial instruments trading involves substantial risks, including complete possible loss of principal plus other losses and is not suitable for all members of the public.

You should make an independent judgment as to whether trading is appropriate for you in light of your financial condition, investment experience, risk tolerance, and other relevant factors.


© 2018 AGEA JINRONG DOO. ALL RIGHTS RESERVED.

Pin It on Pinterest