Repository: ccxt/ccxt
File: js/huobi.js (JavaScript)

Code before:
        //         "volume": 518018.000000000000000000,
        //         "amount": 2769.675777407074725180,
        //         "symbol": "BTC",
        //         "contract_code": "BTC-USD",
        //         "trade_amount": 9544.4032080046491323463688602729806842458,
        //         "trade_volume": 1848448,
        //         "trade_turnover": 184844800.000000000000000000
        //     }
        //
        // fetchOpenInterest: COIN-M Futures
        //
        //     {
        //         "volume": 118850.000000000000000000,
        //         "amount": 635.502025211544374189,
        //         "symbol": "BTC",
        //         "contract_type": "this_week",
        //         "contract_code": "BTC220930",
        //         "trade_amount": 1470.9400749347598691119206024033947897351,
        //         "trade_volume": 286286,
        //         "trade_turnover": 28628600.000000000000000000
        //     }
        //
        const timestamp = this.safeInteger (interest, 'ts');
        return {
            'symbol': this.safeString (market, 'symbol'),
            'baseVolume': this.safeNumber (interest, 'volume'),  // deprecated
            'quoteVolume': this.safeValue (interest, 'value'),  // deprecated
            'openInterestAmount': this.safeNumber (interest, 'volume'),
            'openInterestValue': this.safeNumber (interest, 'value'),
            'timestamp': timestamp,
            'datetime': this.iso8601 (timestamp),
            'info': interest,
        };
    }

    async borrowMargin (code, amount, symbol = undefined, params = {}) {
        /**
         * @method
         * @name huobi#borrowMargin
         * @description create a loan to borrow margin
         * @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
         * @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-cross
         * @param {string} code unified currency code of the currency to borrow
         * @param {float} amount the amount to borrow
         * @param {string|undefined} symbol unified market symbol, required for isolated margin
         * @param {object} params extra parameters specific to the huobi api endpoint
         * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/en/latest/manual.html#margin-loan-structure}
         */
        await this.loadMarkets ();
        const currency = this.currency (code);
        const request = {

Review comment (suggestion):
@Dan-krm Next time, let's avoid calling `this.safeNumber (interest, 'volume/'value)` multiple times, we can just memoize the value once and use it as many times as necessary. 

(I've fixed it now so nw)


Code after:
        //         "volume": 518018.000000000000000000,
        //         "amount": 2769.675777407074725180,
        //         "symbol": "BTC",
        //         "contract_code": "BTC-USD",
        //         "trade_amount": 9544.4032080046491323463688602729806842458,
        //         "trade_volume": 1848448,
        //         "trade_turnover": 184844800.000000000000000000
        //     }
        //
        // fetchOpenInterest: COIN-M Futures
        //
        //     {
        //         "volume": 118850.000000000000000000,
        //         "amount": 635.502025211544374189,
        //         "symbol": "BTC",
        //         "contract_type": "this_week",
        //         "contract_code": "BTC220930",
        //         "trade_amount": 1470.9400749347598691119206024033947897351,
        //         "trade_volume": 286286,
        //         "trade_turnover": 28628600.000000000000000000
        //     }
        //
        const timestamp = this.safeInteger (interest, 'ts');
        const amount = this.safeNumber (interest, 'volume');
        const value = this.safeValue (interest, 'value');
        return {
            'symbol': this.safeString (market, 'symbol'),
            'baseVolume': amount,  // deprecated
            'quoteVolume': value,  // deprecated
            'openInterestAmount': amount,
            'openInterestValue': value,
            'timestamp': timestamp,
            'datetime': this.iso8601 (timestamp),
            'info': interest,
        };
    }

    async borrowMargin (code, amount, symbol = undefined, params = {}) {
        /**
         * @method
         * @name huobi#borrowMargin
         * @description create a loan to borrow margin
         * @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-isolated
         * @see https://huobiapi.github.io/docs/spot/v1/en/#request-a-margin-loan-cross
         * @param {string} code unified currency code of the currency to borrow
         * @param {float} amount the amount to borrow
         * @param {string|undefined} symbol unified market symbol, required for isolated margin
         * @param {object} params extra parameters specific to the huobi api endpoint
         * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/en/latest/manual.html#margin-loan-structure}
         */
        await this.loadMarkets ();