Create an Open Order

An open order opens a position at the specified market rate in case such rate is available on the market.

Please note that if hedging is disabled for the account, the command, first, closes existing opposite positions for the same account and instrument and only then opens a new position in the remaining amount.

Parameter name

Datatype

Description

Command

string

The command. Must be CreateOrder.

OrderType

string

The type of the order. Must be O.

OfferID

or

Symbol

string

OfferID: The identifier of the instrument the order should be placed for. The value must be obtained from the Offers table, the OfferID column.

or

Symbol: The name of the currency pair. For example: "EUR/USD".

AccountID

string

The identifier of the account the order should be placed for. The value must be obtained from the Accounts table, the AccountID column.

Please note that the account identifier may not necessarily be equal to the account name which is shown in the Trading Station application.

BuySell

string

The order direction.

The value must be B - for buy orders and S - for sell orders.

Amount

int

The amount of the order. In the case of FX instruments, the amount is expressed in the base currency of an instrument. In the case of CFD instruments, the amount is expressed in contracts. Must be divisible by the value of the lot size.

Rate

double

The rate at which the order must be filled.

TimeInForce

string

The Time In Force value.

Can be IOC (Immediate Or Cancel) or FOK (Fill Or Kill).

The value is optional.

Open orders are IOC orders by default.

ClientRate

double

The current price of the order instrument.

The value is optional. It is used for logging purposes.

CustomID

string

The custom identifier of the order. This value will be populated into these columns of the trading tables:

Table

Column for opening order

Column for closing order

Orders

RequestTXT

RequestTXT

Trades

OpenOrderRequestTXT

N/A

Closed Trades

OpenOrderRequestTXT

CloseOrderRequestTXT

The value is optional.

You can also create a pair of stop and limit orders for the trade using the same command. Please refer to Attach Stop and/or Limit Orders to the Command for details.

Example: Create an Open order [hide]

   public void PrepareParamsFromLoginRules(O2GLoginRules loginRules)
   {
       mParams = new OrderCreationParameters();
 
       O2GResponseReaderFactory factory = mSession.getResponseReaderFactory();
       if (factory == null)
           return;
       // Gets first account from login.
       O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTable.Accounts);
       O2GAccountsTableResponseReader accountsReader = factory.createAccountsTableReader(accountsResponse);
       O2GAccountRow account = accountsReader.getRow(0);
       // Store account id
       mParams.AccountID = account.AccountID;
       // Store base iAmount
          mParams.BaseAmount = account.BaseUnitSize;
       // Get offers for eur/usd
       O2GResponse offerResponse = loginRules.getTableRefreshResponse(O2GTable.Offers);
       O2GOffersTableResponseReader offersReader = factory.createOffersTableReader(offerResponse);
       for (int i = 0; i < offersReader.Count; i++)
       {
           O2GOfferRow offer = offersReader.getRow(i);
           if (string.Compare(offer.Instrument, "EUR/USD", true) == 0)
           {
               mParams.OfferID = offer.OfferID;
               mParams.Ask = offer.Ask;
               mParams.Bid = offer.Bid;
               mParams.PointSize = offer.PointSize;
               break;
           }
       }
 
   }
 
   public void CreateMarketOrder(string sOfferID, string sAccountID, int iAmount, double dRate, string sBuySell)
   {
 
       O2GRequestFactory factory = mSession.getRequestFactory();
       if (factory == null)
           return;
       O2GValueMap valuemap = factory.createValueMap();
       valuemap.setString(O2GRequestParamsEnum.Command, Constants.Commands.CreateOrder);
       valuemap.setString(O2GRequestParamsEnum.OrderType, Constants.Orders.MarketOpen);
       valuemap.setString(O2GRequestParamsEnum.AccountID, sAccountID);                // The identifier of the account the order should be placed for.
       valuemap.setString(O2GRequestParamsEnum.OfferID, sOfferID);                    // The identifier of the instrument the order should be placed for.
       valuemap.setString(O2GRequestParamsEnum.BuySell, sBuySell);                    // The order direction (use Constants.Buy for Buy, Constants.Sell for Sell)
       valuemap.setDouble(O2GRequestParamsEnum.Rate, dRate);                          // The dRate at which the order must be filled.
       valuemap.setInt(O2GRequestParamsEnum.Amount, iAmount);                         // The quantity of the instrument to be bought or sold.
       valuemap.setString(O2GRequestParamsEnum.CustomID, "OpenMarketOrder");         // The custom identifier of the order.
 
       O2GRequest request = factory.createOrderRequest(valuemap);
       mSession.sendRequest(request);
   }

back