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

const char *

The command. Must be UpdateMarginRequirements.

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

Example: Update margin requirements [hide]

void updateMargin(const char* instrument, IO2GSession *session, ResponseListener *responseListener)
{
    O2G2Ptr<IO2GLoginRules> loginRules = session->getLoginRules();
    O2G2Ptr<IO2GTradingSettingsProvider> tradingSetting  = loginRules->getTradingSettingsProvider();
    // Gets account
    O2G2Ptr<IO2GResponse> accountsResponse = loginRules->getTableRefreshResponse(::Accounts);
    O2G2Ptr<IO2GResponseReaderFactory> responseFactory = session->getResponseReaderFactory();
    O2G2Ptr<IO2GAccountsTableResponseReader> accounts = responseFactory->createAccountsTableReader(accountsResponse);
    O2G2Ptr<IO2GAccountRow> account = accounts->getRow(0);
    double mmr,emr,lmr;
    tradingSetting->getMargins(instrument, account, mmr, emr, lmr);
    printf("Margin requirements: after subscription %f %f %f\n", mmr, emr, lmr);
 
    // Create update request
    O2G2Ptr<IO2GRequestFactory> requestFactory = session->getRequestFactory();
    O2G2Ptr<IO2GValueMap> valueMap = requestFactory->createValueMap();
    valueMap->setString(::Command, O2G2::Commands::UpdateMarginRequirements);
 
    O2G2Ptr<IO2GRequest> updateMarginRequest = requestFactory->createOrderRequest(valueMap);
    responseListener->setRequest(updateMarginRequest->getRequestID());
    session->sendRequest(updateMarginRequest);
    // Wait for response
    HANDLE phEvents[2];
    phEvents[0] = responseListener->getReponseEvent();
    phEvents[1] = responseListener->getFailureEvent();
    int index = uni::WaitForMultipleObjects(2, phEvents, FALSE, 10000); // wait 10 seconds for response
    // Successfully
    if (index == 0)
    {
        O2G2Ptr<IO2GResponse> marginRequirementsResponse = responseListener->getLastRespnonse();
        responseFactory->proccessMarginRequirementsResponse(marginRequirementsResponse);
        tradingSetting->getMargins(instrument, account, mmr, emr, lmr);
        printf("Margin requirements: after margin requirements has been updated %f %f %f\n", mmr, emr, lmr);
    }
    else
        printf("The update margin requirements request failed\n");
 
 
}

back