SymbolInfoMarginRate HOW
Example from file: examples/demos/lowlevel/01_general_operations.goΒΆ
The
SymbolInfoMarginRate()method is used to retrieve margin requirements for a symbol β that is, how much funds are needed to open and maintain a position for a specific instrument.It allows you to find out two key parameters:
- InitialMarginRate β coefficient for opening a position;
- MaintenanceMarginRate β coefficient for maintaining a position.
π§© Code exampleΒΆ
marginRateReq := &pb.SymbolInfoMarginRateRequest{
Symbol: cfg.TestSymbol,
OrderType: pb.ENUM_ORDER_TYPE_ORDER_TYPE_BUY, // Direct protobuf enum
}
marginRateData, err := account.SymbolInfoMarginRate(ctx, marginRateReq)
if err != nil {
helpers.PrintShortError(err, "SymbolInfoMarginRate failed")
} else {
fmt.Printf(" Initial margin rate (BUY): %.2f\n", marginRateData.InitialMarginRate)
fmt.Printf(" Maintenance margin rate (BUY): %.2f\n", marginRateData.MaintenanceMarginRate)
}
π’ Detailed Code ExplanationΒΆ
marginRateReq := &pb.SymbolInfoMarginRateRequest{
Symbol: cfg.TestSymbol,
OrderType: pb.ENUM_ORDER_TYPE_ORDER_TYPE_BUY,
}
A SymbolInfoMarginRateRequest request is created with parameters:
Symbolβ trading instrument (e.g.,EURUSD);OrderTypeβ order type (BUY,SELL,BUY_LIMIT, etc.). Different order types can have different margin coefficients.
The SymbolInfoMarginRate() method is called via gRPC.
The result is stored in marginRateData.
if err != nil {
helpers.PrintShortError(err, "SymbolInfoMarginRate failed")
} else {
fmt.Printf(" Initial margin rate (BUY): %.2f\n", marginRateData.InitialMarginRate)
fmt.Printf(" Maintenance margin rate (BUY): %.2f\n", marginRateData.MaintenanceMarginRate)
}
If there are no errors, both values are displayed:
InitialMarginRateβ initial margin coefficient (e.g., 0.02 β 2%);MaintenanceMarginRateβ maintenance margin coefficient (e.g., 0.01 β 1%).
π¦ What the Server ReturnsΒΆ
After the call, the method returns a protobuf structure:
message SymbolInfoMarginRateData {
double InitialMarginRate = 1; // Initial margin for opening a position
double MaintenanceMarginRate = 2; // Maintenance margin for holding a position
}
π‘ Example of Value InterpretationΒΆ
| Field | Value | Meaning |
|---|---|---|
InitialMarginRate = 0.02 |
2% | For a trade volume of 100,000 EURUSD, 2,000 EUR collateral is needed |
MaintenanceMarginRate = 0.01 |
1% | To hold the position, 1,000 EUR is required |
π§ What It's Used ForΒΆ
The SymbolInfoMarginRate() method is used:
- to calculate required margin before opening a position;
- to check risks and available funds in trading algorithms;
- when modeling trades to assess the impact of leverage;
- in demo examples where you need to show real trading parameters of a symbol.
π¬ In Simple TermsΒΆ
SymbolInfoMarginRate()tells you how much collateral is needed to open and hold a trade for a symbol. It's used for risk calculations, limit checks, and choosing the optimal position size.