Repository: ccxt/ccxt
File: ts/src/base/Exchange.ts (TypeScript)

Code before:
            const result = this.extend (cleanStructure, market);
            // set undefined swap/future/etc
            if (result['spot']) {
                if (result['contract'] === undefined) {
                    result['contract'] = false;
                }
                if (result['swap'] === undefined) {
                    result['swap'] = false;
                }
                if (result['future'] === undefined) {
                    result['future'] = false;
                }
                if (result['option'] === undefined) {
                    result['option'] = false;
                }
                if (result['index'] === undefined) {
                    result['index'] = false;
                }
            }
            return result;
        }
        return cleanStructure;
    }

    isSpotMargin (market: MarketInterface, marketType: Str = undefined, marginMode: Str = undefined): boolean {
        return market['margin'] || (marketType === 'margin') || ((marketType === 'spot' && marginMode !== undefined))
    }

    setMarkets (markets, currencies = undefined) {
        const values = [];
        this.markets_by_id = {};
        // handle marketId conflicts
        // we insert spot markets first
        const marketValues = this.sortBy (this.toArray (markets), 'spot', true, true);
        for (let i = 0; i < marketValues.length; i++) {
            const value = marketValues[i];
            if (value['id'] in this.markets_by_id) {
                (this.markets_by_id[value['id']] as any).push (value);
            } else {
                this.markets_by_id[value['id']] = [ value ] as any;
            }
            const market = this.deepExtend (this.safeMarketStructure (), {
                'precision': this.precision,
                'limits': this.limits,
            }, this.fees['trading'], value);
            if (market['linear']) {
                market['subType'] = 'linear';
            } else if (market['inverse']) {
                market['subType'] = 'inverse';
            } else {
                market['subType'] = undefined;

Review comment (suggestion):
@ttodua we can't do this, `market['margin']` is a property that indicates if the market supports margin or not, it does not mean th euser wants to use it, 

Code after:
        }
        const extendsStr: Str = this.safeString (featuresObj, 'extends');
        if (extendsStr !== undefined) {
            featuresObj = this.omit (featuresObj, 'extends');
            const extendObj = this.featuresMapper (initialFeatures, extendsStr);
            featuresObj = this.deepExtend (extendObj, featuresObj);
        }
        //
        // corrections
        //
        if ('createOrder' in featuresObj) {
            const value = this.safeDict (featuresObj['createOrder'], 'attachedStopLossTakeProfit');
            if (value !== undefined) {
                featuresObj['createOrder']['stopLoss'] = value;
                featuresObj['createOrder']['takeProfit'] = value;
            }
            if (marketType === 'spot') {
                // default 'hedged': false
                featuresObj['createOrder']['hedged'] = false;
                // default 'leverage': false
                if (!('leverage' in featuresObj['createOrder'])) {
                    featuresObj['createOrder']['leverage'] = false;
                }
            }
            // default 'GTC' to true
            if (this.safeBool (featuresObj['createOrder']['timeInForce'], 'GTC') === undefined) {
                featuresObj['createOrder']['timeInForce']['GTC'] = true;
            }
        }
        return featuresObj;
    }

    orderbookChecksumMessage (symbol:Str) {
        return symbol + ' : ' + 'orderbook data checksum validation failed. You can reconnect by calling watchOrderBook again or you can mute the error by setting exchange.options["watchOrderBook"]["checksum"] = false';
    }

    createNetworksByIdObject () {
        // automatically generate network-id-to-code mappings
        const networkIdsToCodesGenerated = this.invertFlatStringDictionary (this.safeValue (this.options, 'networks', {})); // invert defined networks dictionary
        this.options['networksById'] = this.extend (networkIdsToCodesGenerated, this.safeValue (this.options, 'networksById', {})); // support manually overriden "networksById" dictionary too
    }

    getDefaultOptions () {
        return {
            'defaultNetworkCodeReplacements': {
                'ETH': { 'ERC20': 'ETH' },
                'TRX': { 'TRC20': 'TRX' },
                'CRO': { 'CRC20': 'CRONOS' },
                'BRC20': { 'BRC20': 'BTC' },
            },
        };