Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.
Ka0rX edited this page Oct 17, 2022 · 8 revisions

Stocks are super important, these are real or virtual companies players can invest money into. Quotations are savd in the stocks.yml config file. Do NOT edit the stock//-data.yml config file as it contains temporary plugin data you don't wanna mess with.

Virtual Stocks

What Are Virtual Stocks?

Virtual stocks are not correlated with any real stock. The price fluctuation of these depends linearly on offer and demand but also with some randomness affecting the price. Stocks are caracterized by their price,initialSupply(number of shares created at the beginning) and their totalSupply(the shares in circulation). If the initial supply is 1000 shares and you buy 100 shares, the price will go up by 10% and the total supply will go to 1100. If you short them the price will go by 10% and the total supply will go to 900.

You must be be careful when setting up the inital supply. You must make it big enough so that players can't have a great impact on the price (e.g If a player has 100 you must at least put the initialSupply to 1000 if the price is 10 for each share so that the player will not impact the price by more than 1% by himself).

The price is calculated as priceMultiplier*totalSupply with the price Multiplier evolving randomly depending on the volatility you want, thus creating some random fluctuations for the price. A volatility of 1 means that the price can fluctuate by roughly 10% in 1 hour and 0 means it won't randomly fluctuate, you can change this value on the stocks.yml file depending on your needs.

How to setup virtual Stocks?

You can change the default-volatility in the config.yml or make each stock have its custom volatility in the stocks.yml file.

Real life stocks

If you don't want to rely on the Stonks virtual stock model you can bind any existing stock to a real life stock market using one of the following public stock API. These will allow you to perform HTTP requests and get the real life price of any quotation. Virtual and real stocks can be bought and traded in exactly the same way from the player point of view.

Of course this gives a more realistic feeling to your stock market unlike virtual stocks. However, a drawback is that these API calls are limited if you are not willing to spend money in premium API keys. Another drawback is that unlike virtual quotations, players have NO impact whatsoever on the stock price.

Creating a real stock

You can either create directly the stock in the yml or first use the command. You then have to change real-stock to true and make sur the id corresponds to a real stock.

#Example for a stock following the price of the Apple company (identifier of Apple is aapl).
#stock id is apple
aapl:
  #The name that will be displayed
  name: Apple
  #If set to true it will consider the stock as real and will check if it the id (apple)
  #really corresponds to a real stock
  real-stock: true
  #The stock price will be refreshed every 12s. The greater the refresh-period,
  #the more API call you make, make sure it doesn't overpass the API limit.
  refresh-period: 12
  #Dividends
  dividends:
    formula: 0.1 * {price} * {amount}
    period: 1
    last: 1658324165625

Supported stock data APIs

The numbers given correspond for the free versions

Name Max Call Frequency Max Calls Per Day Corresponding Call Period
Finnhub 60 calls/min None 15min
AlphaVantage 5 calls/min 500 calls 20min
TwelveData 8 calls/min 800 calls 15min

Sign in on one of these API (with a free or premium offer), get your API key and input in the main Stonks config file:

stock-api:
  enabled: true # Set this to true
  used: 'finnhub' # finnhub/twelvedata/alphavantage...
  key: '' # Put your API key here

Stock exchange type

Using the ``exchange-type`` option you can allow your players to buy and sell shares with real Minecraft items instead of cash.

aapl:
  ...
  exchange-type:
    material: COBBLESTONE
    model-data: 0