Incorrect Basket Margin

Hi Team, I am using Python sdk v3
I am getting more margin requirement from firstock_BasketMargin API, whereas app showing margin correctly (which is less than API)

Please check and revert on the same, attaching code and logs for your reference (Client code: MJ2674)

Code:

logging.info(f"straddle_legs: {straddle_legs}")
straddle_one_lot_margin_required = firstock_util.firstock_calculate_basket_margin(straddle_legs,str(ticker_fut["LotSize"]))

if straddle_one_lot_margin_required is not None:

    logging.info(f"Margin required for one lot of straddlei is: {straddle_one_lot_margin_required}")

    net_margin = firstock_util.firstock_get_net_margin()

    logging.info(f"Net Margin: {net_margin}")

    lots = math.floor(((net_margin*SHORT_STRADDLE_PARAMS['margin_factor_to_use'])/straddle_one_lot_margin_required) % (int(ticker_fut["LotSize"])))

    logging.info(f"lots: {lots}")






def firstock_calculate_basket_margin(orders,lotsize):

    global FIRSTOCK_API_DATA_FETCH_MAX_ATTEMPTS

    cur_attempt = 0

    basket_margin = None

    basket = []

    while cur_attempt < FIRSTOCK_API_DATA_FETCH_MAX_ATTEMPTS:

        try:

            for i in range(len(orders)):

                order_i = {

                    "exchange": orders[i]['Exchange'],

                    "tradingSymbol":orders[i]['TradingSymbol'],

                    "quantity":lotsize,

                    "transactionType":"S",

                    "price":"0.05",

                    "product":"M",

                    "priceType":"LMT"

                }

                basket.append(order_i)

            basket_margin_res = thefirstock.firstock_BasketMargin(basket)

            logging.info(f"Basket_margin_res: {basket_margin_res}")

            if basket_margin_res is not None and basket_margin_res['status']=="Success":

                basket_margin = float(basket_margin_res['data']['marginused'])

                break

            else:

                logging.error(f"Failed to get Basket margin {basket_margin_res}")

                cur_attempt+=1

                time.sleep(1)

        except Exception as Exc:

            logging.exception(f"Exception occured while get Basket margin {Exc}")

            cur_attempt+=1

            time.sleep(1)

    return basket_margin

Logs:


12-Mar-24 10:47:35 : trade_banknifty_short_straddle() - straddle_legs: [Exchange                            NFO
Token                             66704
LotSize                              15
Symbol                        BANKNIFTY
TradingSymbol    BANKNIFTY27MAR24C47200
Expiry                      27-MAR-2024
Instrument                       OPTIDX
OptionType                           CE
StrikePrice                     47200.0
TickSize                           0.05
Name: 5432, dtype: object, Exchange                            NFO
Token                             66705
LotSize                              15
Symbol                        BANKNIFTY
TradingSymbol    BANKNIFTY27MAR24P47200
Expiry                      27-MAR-2024
Instrument                       OPTIDX
OptionType                           PE
StrikePrice                     47200.0
TickSize                           0.05
Name: 442, dtype: object]
12-Mar-24 10:47:35 : firstock_calculate_basket_margin() - Basket_margin_res: {'status': 'Success', 'data': {'request_time': '10:47:35 12-03-2024', 'stat': 'Ok', 'marginused': '298089.02', 'marginusedtrade': '298089.02', 'marginusedprev': '158772.68', 'remarks': ''}}
12-Mar-24 10:47:35 : trade_banknifty_short_straddle() - Margin required for one lot of straddlei is: 298089.02
12-Mar-24 10:47:35 : trade_banknifty_short_straddle() - Net Margin: 1759032.3099999998
12-Mar-24 10:47:35 : trade_banknifty_short_straddle() - lots: 5

Please check why Basket Margin API returning more margin?

@Firstock @firstockhq
Please someone help me with this issue
Asking since 1 month
This is not professional

Hi @tejas_ttid,

Apologies for the inconvenience, but we tried calling and weren’t able to reach you. Please let us know when we can get in touch with you.

can you please set up the meeting with me and tech team

Hi @tejas_ttid,

Apologies for the inconvenience, but we tried calling and weren’t able to reach you. Please let us know when we can get in touch with you or please call to the number where we tried reaching you, there has been a text message sent to you’re registered number.