Skip to main content

Custom data sources

You can influence stock prices from your own scripts by returning a numeric factor from a function per stock id:
config.lua
Custom data sources should only be used if you understand how they affect stock pricing. Incorrect implementation can lead to unstable market behavior.

Database table structure

The stock market system uses a database table called stocks to store all stock configurations. Each stock is defined by a single row in this table with the following fields:

Stock table fields

  • id (string): Unique stock identifier (e.g., “VCC”, “AMCO”)
  • label (string): Display name shown to players (e.g., “Valentine Coal Co.”)
  • description (string): Detailed description of the company/stock
  • base_price (integer): Initial stock price when first created
  • volatility (float): Price volatility multiplier (1.0 = normal, 2.0 = double volatility)
  • enabled (boolean): Whether the stock is active and tradeable
  • type (string): Stock calculation method - “realtime”, “random”, “custom”, or “mixed”
  • realtime_source (string): API provider name for real-time data (e.g., “api_provider”)
  • realtime_symbol (string): Stock symbol for real-time data (e.g., “AAPL”, “TSLA”)
  • realtime_weight (float): Influence of real-time data on price (0.0 to 1.0)
  • random_enabled (boolean): Enable random price fluctuations
  • random_weight (float): Influence of random fluctuations on price (0.0 to 1.0)
  • random_max_change (float): Maximum percentage change per update cycle
  • custom_weight (float): Influence of custom data sources on price (0.0 to 1.0)
  • Currently disabled
  • dividends_enabled (boolean): Enable dividend payouts for this stock
  • dividends_mode (string): “fixed” for set amount or “percent” for percentage
  • dividends_amount (float): Fixed dividend amount (used when mode is “fixed”)
  • dividends_percent (float): Dividend percentage (used when mode is “percent”)
  • rp_events_enabled (boolean): Enable RP events to affect this stock’s price

Stock type examples

Database usage examples

Creating a real-time stock

Creating a randomized stock

Creating a mixed mode stock

Updating stock settings