Sunday, November 21, 2010

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.

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)

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.

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)

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.

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")


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.

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)

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.

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")

No comments:

Post a Comment