Sunday, November 14, 2010

API Retrieval Methods - GetPositions

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.

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
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.

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


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.

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

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.

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)

No comments:

Post a Comment