Update Margin Requirements

This command is useful in case the instrument was not subscribed at the time of login but was subscribed later.
It is used to get margin requirements for an instrument after subscribing to it.
To get updated margin requirements for instruments, please fill the following value in the value map:

Parameter name

Datatype

Description

COMMAND

String

The command. Must be UpdateMarginRequirements.

Create a request and sent it to the server. Important: in order to get updated margin requirements you have to process a response in processMarginRequirementsResponse.

Example: Update margin requirements [hide]

 System.out.println("Please unsubscribe from " + mInstrument);
 // ...
 mSession.login(mUserID, mPassword, mURL, mConnection);
 // ...
 offerInstrument = getOfferID(mInstrument);
 if (!offerInstrument.isEmpty()) {
    subscribeInstrument(offerInstrument, mInstrument, responseListener);
    showMarginRequirements(mInstrument, "After subscription:");
    updateMarginRequirements(responseListener);
    showMarginRequirements(mInstrument, "After updating margin requirements:");
 }
 
 
 public static void subscribeInstrument (String offerInstrument, String instrument, ResponseListener responseListener) {
    O2GRequestFactory requestFactory = mSession.getRequestFactory();
    if (requestFactory != null) {
        O2GValueMap valueMap = requestFactory.createValueMap();
        valueMap.setString(O2GRequestParamsEnum.COMMAND, com.fxcore2.Constants.Commands.SetSubscriptionStatus);
        valueMap.setString(O2GRequestParamsEnum.SUBSCRIPTION_STATUS, "T");
        valueMap.setString(O2GRequestParamsEnum.OFFER_ID, offerInstrument);
        O2GRequest request = requestFactory.createOrderRequest(valueMap);
        mSession.sendRequest(request);
        // ...
    }
 }
 
public static void updateMarginRequirements(ResponseListener responseListener) {
    O2GRequestFactory requestFactory = mSession.getRequestFactory();
    if (requestFactory != null) {
        valueMap.setString(O2GRequestParamsEnum.COMMAND, com.fxcore2.Constants.Commands.UpdateMarginRequirements);
        O2GRequest request = requestFactory.createOrderRequest(valueMap);
        mSession.sendRequest(request);
        //...
    }
 }
 
public static void showMarginRequirements(String instrument, String text) {
        O2GLoginRules loginRules = mSession.getLoginRules();
        O2GTradingSettingsProvider tradingSetting = loginRules.getTradingSettingsProvider();
        O2GResponse accountsResponse = loginRules.getTableRefreshResponse(O2GTableType.ACCOUNTS);
        O2GResponseReaderFactory responseReaderFactory = mSession.getResponseReaderFactory();
        if (responseReaderFactory == null) {
            return;
        }
        O2GAccountsTableResponseReader accounts = responseReaderFactory.createAccountsTableReader(accountsResponse);
        O2GAccountRow accountRow = accounts.getRow(0);
        O2GMargin margin = tradingSetting.getMargins(instrument, accountRow);
        System.out.println(text + " mmr=" + margin.getMMR() + "; emr=" + margin.getEMR() + "; lmr=" + margin.getLMR());
 }
 
 
 // Implementation of IO2GResponseListener interface public method onRequestCompleted
 public void onRequestCompleted(String requestID, O2GResponse response) {
        System.out.println("Request completed.\nrequestID= " + requestID);
        mError = false;
        O2GResponseType responseType = response.getType();
        if (responseType == O2GResponseType.MARGIN_REQUIREMENTS_RESPONSE){
              O2GResponseReaderFactory responseFactory = mSession.getResponseReaderFactory();
              if (responseFactory != null) {
                  responseFactory.processMarginRequirementsResponse(response);
              }
        }
 }

back