### Configure API Provider Settings in StackTrakr Source: https://context7.com/lbruton/stacktrackr/llms.txt This snippet demonstrates how to interact with StackTrakr's API provider configuration. It shows how to list available providers, retrieve and set provider priority order, configure synchronization modes ('always' or 'backup'), set per-provider cache timeouts, and check cache durations. It also includes examples for calculating historical data pull costs and initiating a synchronized data pull across providers. ```javascript // Available API providers const providers = Object.keys(API_PROVIDERS); // Output: ['METALS_DEV', 'METALS_API', 'METAL_PRICE_API', 'CUSTOM'] // Get provider priority order const order = getProviderOrder(); // Output: ['METALS_DEV', 'METALS_API', ...] (based on tab drag order) // Set provider sync mode const config = loadApiConfig(); config.syncMode['METALS_DEV'] = 'always'; // or 'backup' config.syncMode['METALS_API'] = 'backup'; saveApiConfig(config); // Configure per-provider cache timeout (hours) config.cacheTimeouts['METALS_DEV'] = 12; saveApiConfig(config); // Check cache duration const cacheDuration = getCacheDurationMs('METALS_DEV'); // Output: 43200000 (12 hours in milliseconds) // Pull historical data with cost calculation updateHistoryPullCost('METALS_DEV'); // Output: Updates UI with "30d = 1 API call" cost indicator // Handle provider sync chain (respects priority and modes) const result = await syncProviderChain({ showProgress: true, forceSync: false }); // Output: { results: { METALS_DEV: 'success', METALS_API: 'skipped' }, updatedCount: 4, anySucceeded: true } ``` -------------------------------- ### Custom Spot API Source: https://github.com/lbruton/stacktrackr/blob/main/index.html Allows configuration of a custom API endpoint for fetching spot metal prices. Requires Base URL, Endpoint, Metal Format, and API Key. ```APIDOC ## Custom Spot API ### Description Configure a connection to a custom API endpoint for retrieving spot metal prices. You need to provide the Base URL, the specific Endpoint, the desired Metal Format (Symbol or Word), and an API Key if required by the custom API. ### Method GET (Typically) ### Endpoint [User-defined Base URL] + [User-defined Endpoint] ### Parameters #### Query Parameters (User-defined based on custom API requirements) - **apiKey** (string) - Optional - API key for authentication if required. - **format** (string) - Optional - Specifies the metal format (e.g., 'Symbol', 'Word'). ### Request Example (This will vary greatly depending on the custom API being used. Example structure): ``` https://custom-api.example.com/spot?apiKey=YOUR_CUSTOM_KEY&format=Symbol&metals=XAU,XAG ``` ### Response #### Success Response (200) - **rates** (object) - Contains the spot prices for the metals, formatted as specified. #### Response Example (Example based on 'Symbol' format): ```json { "timestamp": 1678886400, "base": "USD", "rates": { "XAU": 1985.50, "XAG": 23.10 } } ``` ``` -------------------------------- ### Fetch Spot Prices from Multiple APIs (JavaScript) Source: https://context7.com/lbruton/stacktrackr/llms.txt Integrates with various API providers (Metals.dev, Metals-API, MetalPriceAPI) to fetch live precious metal spot prices. It supports API key configuration, caching, provider failover, and fetching historical data in batches. Dependencies include utility functions for loading/saving configurations and fetching data. ```javascript // Configure API provider with your API key const config = loadApiConfig(); config.keys['METALS_DEV'] = 'your-api-key-here'; config.provider = 'METALS_DEV'; saveApiConfig(config); // Sync spot prices from configured providers await syncSpotPricesFromApi(true, false); // Output: Updates spotPrices object and localStorage // spotPrices = { silver: 29.50, gold: 2650.00, platinum: 980.00, palladium: 1050.00 } // Fetch latest prices for specific metals const prices = await fetchLatestPrices('METALS_DEV', 'your-api-key', ['silver', 'gold']); // Output: { silver: 29.50, gold: 2650.00 } // Fetch historical price data in batches const history = await fetchHistoryBatched('METALS_DEV', 'your-api-key', ['silver', 'gold', 'platinum', 'palladium'], 30); // Output: { totalEntries: 120, callsMade: 1 } // Test API connection before saving const isConnected = await testApiConnection('METALS_DEV', 'your-api-key'); // Output: true/false ``` -------------------------------- ### Create Encrypted Vault Backups in JavaScript Source: https://context7.com/lbruton/stacktrackr/llms.txt Facilitates the creation and restoration of AES-256-GCM encrypted backup files for secure data portability. This system utilizes the Web Crypto API with PBKDF2 for key derivation, ensuring robust security for inventory, settings, and price history. The backup file includes a header with metadata and an encrypted JSON payload. ```javascript // Export encrypted backup (triggers password prompt modal) // Uses Web Crypto API with PBKDF2 key derivation document.getElementById('exportVaultBtn').click(); // Output: Downloads "staktrakr_backup_TIMESTAMP.stvault" file // Import encrypted backup // User selects .stvault file and enters password document.getElementById('importVaultBtn').click(); // Output: Decrypts and restores all inventory, settings, and price history // Vault file structure (56-byte header + encrypted payload): // - Magic bytes: "STVAULT1" // - Version: 1 byte // - PBKDF2 iterations: 4 bytes // - Salt: 16 bytes // - IV: 12 bytes // - Ciphertext: AES-256-GCM encrypted JSON ``` -------------------------------- ### Metals.dev API Source: https://github.com/lbruton/stacktrackr/blob/main/index.html Fetches real-time precious metal prices from Metals.dev. Supports API key authentication and configurable cache settings. ```APIDOC ## Metals.dev API ### Description Integrates with Metals.dev to retrieve current prices for precious metals like Gold, Silver, Platinum, and Palladium. You can configure caching and specify which metals to track. ### Method GET ### Endpoint `https://metals-api.com/api/latest` (Example endpoint, refer to Metals.dev documentation) ### Parameters #### Query Parameters - **access_key** (string) - Required - Your Metals.dev API key. - **base** (string) - Optional - The base currency for prices (e.g., 'USD'). Defaults to USD. - **symbols** (string) - Optional - Comma-separated list of symbols to retrieve (e.g., 'XAU,XAG'). ### Request Example ``` https://metals-api.com/api/latest?access_key=YOUR_API_KEY&base=USD&symbols=XAU,XAG ``` ### Response #### Success Response (200) - **rates** (object) - Contains the latest prices for the requested metals. #### Response Example ```json { "date": "2023-10-27", "base": "USD", "rates": { "XAU": 1985.50, "XAG": 23.10 } } ``` ``` -------------------------------- ### Import and Export Inventory Data (JavaScript) Source: https://context7.com/lbruton/stacktrackr/llms.txt Handles importing inventory data from CSV, JSON, and Numista CSV formats, with options for merging or overriding existing data. It also supports exporting inventory to CSV, JSON, PDF, and creating comprehensive ZIP backups. Restoration from ZIP archives is also provided. ```javascript // Import from CSV file (merge mode) const csvFile = document.getElementById('csvInput').files[0]; importCsv(csvFile, false); // Output: Adds imported items to inventory, shows progress bar // Import from Numista CSV export importNumistaCsv(numistaExportFile, false); // Output: Maps Numista fields to StakTrakr schema, handles composition/metal detection // Import from JSON file (override mode - replaces existing) importJson(jsonFile, true); // Output: Replaces entire inventory with imported data // Export to CSV exportCsv(); // Output: Downloads "metal_inventory_YYYYMMDD.csv" with all portfolio columns // Export to JSON exportJson(); // Output: Downloads "metal_inventory_YYYYMMDD.json" with full item data // Export to PDF exportPdf(); // Output: Downloads formatted PDF with portfolio summary and totals // Create comprehensive ZIP backup await createBackupZip(); // Output: Downloads ZIP with inventory_data.json, settings.json, // spot_price_history.json, CSV, HTML report, and README // Restore from ZIP backup await restoreBackupZip(zipFile); // Output: Restores inventory, settings, spot history, and chip configurations ``` -------------------------------- ### Manage Spot Price History and Sparklines in JavaScript Source: https://context7.com/lbruton/stacktrackr/llms.txt Handles loading, recording, and displaying historical spot price data. It includes functions for generating sparkline data, updating charts, and visually indicating price movements. Dependencies include localStorage and a charting library (likely Chart.js). ```javascript // Load spot history from localStorage loadSpotHistory(); // Output: Populates global `spotHistory` array // Record a new spot price entry recordSpot(29.75, 'api', 'Silver', 'Metals.dev', '2024-06-15 10:30:00'); // Output: Adds entry to spotHistory with deduplication, saves to localStorage // Get sparkline data for chart rendering const data = getSparklineData('Silver', 30); // 30-day range // Output: { labels: ['2024-05-15', '2024-05-16', ...], data: [28.50, 28.75, ...] } // Update sparkline chart for a specific metal updateSparkline('silver'); // Output: Renders Chart.js sparkline with gradient fill // Update all metal sparklines updateAllSparklines(); // Output: Refreshes charts for silver, gold, platinum, palladium // Update spot card color indicator based on price movement updateSpotCardColor('silver', 29.75); // Output: Adds spot-up/spot-down/spot-unchanged class, displays arrow indicator // Manual spot price entry via shift+click startSpotInlineEdit(document.querySelector('.spot-card-value'), 'silver'); // Output: Shows inline input for manual price entry ``` -------------------------------- ### Numista Catalog API Source: https://github.com/lbruton/stacktrackr/blob/main/index.html Integrates with the Numista Catalog API to fetch coin and medal data. Requires an API key obtained from numista.com. ```APIDOC ## Numista Catalog API ### Description Connect to the Numista Catalog API to enrich your inventory with detailed information about coins and medals. An API key is required for authentication. ### Method GET (Implicit for data retrieval) ### Endpoint `https://en.numista.com/api/v1/` (Base URL, specific endpoints vary) ### Parameters #### Query Parameters - **key** (string) - Required - Your Numista API key. ### Request Example (No direct request example as it's typically handled by the application's sync functionality) ### Response #### Success Response (200) - **data** (object) - Contains catalog information for requested items. #### Response Example ```json { "item_id": 12345, "name": "American Silver Eagle", "country": "United States", "year": 2023, "metal": "Silver", "weight": 31.1, "diameter": 40.6 } ``` ``` -------------------------------- ### Metals-API.com API Source: https://github.com/lbruton/stacktrackr/blob/main/index.html Fetches real-time precious metal prices from Metals-API.com. Supports API key authentication and configurable cache and history settings. ```APIDOC ## Metals-API.com API ### Description Connects to Metals-API.com to obtain up-to-date pricing for precious metals. This API allows for flexible configuration of cache timeouts, historical data retrieval, and metal selection. ### Method GET ### Endpoint `https://metals-api.com/api/latest` (Example endpoint, refer to Metals-API.com documentation) ### Parameters #### Query Parameters - **access_key** (string) - Required - Your Metals-API.com API key. - **base** (string) - Optional - The base currency (e.g., 'USD'). Defaults to USD. - **symbols** (string) - Optional - Comma-separated list of metal symbols (e.g., 'XAU,XAG'). ### Request Example ``` https://metals-api.com/api/latest?access_key=YOUR_API_KEY&base=USD&symbols=XAU,XAG ``` ### Response #### Success Response (200) - **rates** (object) - An object containing the latest prices for the specified metals. #### Response Example ```json { "date": "2023-10-27", "base": "USD", "rates": { "XAU": 1985.50, "XAG": 23.10 } } ``` ``` -------------------------------- ### Implement Dynamic Filter Chips in JavaScript Source: https://context7.com/lbruton/stacktrackr/llms.txt Enables the creation and application of dynamic filter chips for inventory data. These chips allow users to quickly filter items by various attributes like metal, type, name, year, grade, location, and custom groupings. The system supports applying filters, rendering active chips, configuring categories, and saving custom grouping rules. ```javascript // Apply a quick filter from chip click applyColumnFilter('metal', 'Silver'); // Output: Filters table to show only Silver items // Apply grouped name filter (e.g., "American Silver Eagle" matches all years) applyQuickFilter('name', 'American Silver Eagle'); // Output: Filters to all ASE items regardless of year // Render active filter chips renderActiveFilters(); // Output: Updates chip bar with counts, respects minCount threshold // Get filter chip category configuration const chipConfig = getFilterChipCategoryConfig(); // Output: Array of category configs with enabled/disabled status and order // Save custom chip grouping rules const rules = [{ label: 'Washington Quarters', patterns: ['Washington Quarter', 'America The Beautiful'] }]; saveDataSync('chipCustomGroups', rules); // Output: Stored for use in chip rendering ``` -------------------------------- ### Manage Precious Metal Inventory (JavaScript) Source: https://context7.com/lbruton/stacktrackr/llms.txt Provides full CRUD operations for managing precious metal inventory items. It includes functions to load, add, edit, delete, and save inventory data to localStorage. Items can contain detailed metadata such as weight, purity, purchase price, and grading information. Melt value calculations are also supported. ```javascript // Load inventory from localStorage loadInventory(); // Output: Populates global `inventory` array with migrated items // Add a new inventory item const newItem = { metal: 'Silver', composition: 'Silver', name: '2024 American Silver Eagle', qty: 10, type: 'Coin', weight: 1.0, weightUnit: 'oz', purity: 0.999, price: 32.50, marketValue: 35.00, date: '2024-06-15', purchaseLocation: 'APMEX', storageLocation: 'Home Safe', notes: 'BU condition', year: '2024', grade: 'MS-70', gradingAuthority: 'PCGS', certNumber: '12345678', numistaId: '298883', uuid: generateUUID(), serial: getNextSerial() }; inventory.push(newItem); saveInventory(); // Compute melt value for an item const spotPrice = spotPrices.silver; // e.g., 29.50 const meltValue = computeMeltValue(newItem, spotPrice); // Output: 294.705 (1.0 oz × 10 qty × 29.50 × 0.999 purity) // Edit an existing item editItem(0); // Opens edit modal pre-filled with item at index 0 // Delete an item with confirmation deleteItem(0); // Prompts confirmation, removes item, updates UI // Render the inventory table renderTable(); // Output: Updates DOM with filtered, sorted inventory display ``` -------------------------------- ### MetalPriceAPI.com API Source: https://github.com/lbruton/stacktrackr/blob/main/index.html Retrieves current precious metal prices from MetalPriceAPI.com. Supports API key authentication and configurable cache and history settings. ```APIDOC ## MetalPriceAPI.com API ### Description Fetches the latest precious metal prices using the MetalPriceAPI.com service. This integration allows for API key authentication and customization of cache duration and historical data pull. ### Method GET ### Endpoint `https://metalpriceapi.com/api/latest` (Example endpoint, refer to MetalPriceAPI.com documentation) ### Parameters #### Query Parameters - **apikey** (string) - Required - Your MetalPriceAPI.com API key. - **base** (string) - Optional - The base currency (e.g., 'USD'). Defaults to USD. - **units** (string) - Optional - Units for the prices (e.g., 'oz', 'g'). ### Request Example ``` https://metalpriceapi.com/api/latest?apikey=YOUR_API_KEY&base=USD&units=oz ``` ### Response #### Success Response (200) - **rates** (object) - Contains the current prices for the requested metals. #### Response Example ```json { "date": "2023-10-27", "base": "USD", "rates": { "XAU": 1985.50, "XAG": 23.10 } } ``` ``` -------------------------------- ### Perform Data Manipulation and Formatting in JavaScript Source: https://context7.com/lbruton/stacktrackr/llms.txt Provides essential utility functions for data management, including generating unique identifiers, formatting currency and weight, parsing dates and fractions, validating data, sanitizing inputs, and managing localStorage with compression. These functions are crucial for maintaining data integrity and efficiency. ```javascript // Generate stable UUID for inventory items const uuid = generateUUID(); // Output: "550e8400-e29b-41d4-a716-446655440000" // Format currency values const formatted = formatCurrency(1234.56); // Output: "$1,234.56" // Format weight (auto-converts small weights to grams) const weight = formatWeight(0.5, 'oz'); // Output: "15.55 g" (auto-converted from oz) const gbWeight = formatWeight(5, 'gb'); // Output: "5 gb" (Goldback denomination) // Parse date strings from various formats const date = parseDate('06/15/2024'); // Output: "2024-06-15" (handles US/EU formats intelligently) // Parse fraction strings for weight input const value = parseFraction('1/10'); // Output: 0.1 // Validate inventory item data const validation = validateInventoryItem(newItem); // Output: { isValid: true, errors: [] } or { isValid: false, errors: ['Name is required'] } // Sanitize imported item data with defaults const cleaned = sanitizeImportedItem(rawItem); // Output: Item with normalized fields, purity defaulted to 1.0, UUID assigned // Save/load data with compression for large datasets saveDataSync('myKey', largeArray); const data = loadDataSync('myKey', []); // Cleanup unknown localStorage keys cleanupStorage(); // Output: Removes keys not in ALLOWED_STORAGE_KEYS whitelist ``` -------------------------------- ### PCGS Cert Verification API Source: https://github.com/lbruton/stacktrackr/blob/main/index.html Utilizes the PCGS Certificate Verification API to authenticate the grading of coins. Requires a Bearer Token obtained from PCGS. ```APIDOC ## PCGS Cert Verification API ### Description Verify the authenticity and grading details of coins using the PCGS Certificate Verification API. This integration requires a Bearer Token obtained after creating a PCGS API account. ### Method POST (Typically for verification requests) ### Endpoint `https://api.pcgs.com/v1/cert/verify` (Example endpoint, refer to PCGS API docs) ### Parameters #### Request Body - **certificate_number** (string) - Required - The PCGS certificate number to verify. - **serial_number** (string) - Required - The serial number associated with the certificate. ### Request Example ```json { "certificate_number": "12345678", "serial_number": "987654321" } ``` ### Response #### Success Response (200) - **is_valid** (boolean) - Indicates if the certificate is valid. - **grade** (string) - The assigned grade of the coin. - **details** (object) - Additional verification details. #### Response Example ```json { "is_valid": true, "grade": "MS70", "details": { "coin_name": "American Silver Eagle", "year": 2023 } } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.