πŸ“ˆMarkets App

The Markets app allows players to buy, sell, and trade cryptocurrencies and stocks directly from their phone. This guide will help you set up the Markets app for your server.

Asset Link: https://teamsgg.dev/scripts/markets

What You Need

Before you start, make sure you have:

  • The yseries phone system installed

  • The tgg-markets resource installed after the yseries resource

  • A free Finnhub API key (we'll show you how to get one)

Step 1: Get Your Finnhub API Key

The Markets app uses Finnhub to get real-time prices for stocks and cryptocurrencies. You'll need a free API key to make it work.

Creating Your Account

  1. Go to https://finnhub.io in your web browser

  2. Click "Login" or "Register" (usually in the top right corner)

  3. Fill in your details:

  4. Click "Create Account"

Verifying Your Email

  1. Check your email inbox for a message from Finnhub

  2. Click the verification link in the email

  3. Your account will be activated

Getting Your API Key

  1. Log in to your Finnhub account

  2. Go to your Dashboard (you'll see it after logging in)

  3. Your API key will be displayed on the dashboard (it's a long string of letters and numbers)

  4. Copy the entire API key

Important: The free tier gives you 60 API calls per minute, which is perfect for the Markets app. No credit card is required!

Step 2: Add Your API Key to the Server

You need to add your API key to your server configuration. There are two ways to do this:

Add this line to your server.cfg file:

set marketsApiKey "your-api-key-here"

Replace your-api-key-here with the API key you copied from Finnhub.

Example:

set marketsApiKey "abc123xyz456def789"

Method 2: Direct File Edit

If you prefer to edit the file directly:

  1. Open the file: tgg-markets/server/apiKeys.lua

  2. Find the line that says:

    Config.ApiKeys.Finnhub = GetConvar('marketsApiKey', '')
  3. Change it to:

    Config.ApiKeys.Finnhub = 'your-api-key-here'
  4. Replace your-api-key-here with your actual API key

  5. Save the file

Note: Method 1 (server.cfg) is recommended because it keeps your API key separate from the resource files.

Step 3: Configure Cryptocurrencies and Stocks

The Markets app comes with some cryptocurrencies and stocks already configured. You can enable or disable them, or add your own.

Configuring Cryptocurrencies

  1. Open the file: tgg-markets/config/config.crypto.lua

  2. You'll see a list of cryptocurrencies like BTC, ETH, SOL, etc.

  3. To enable or disable a cryptocurrency, change enabled = true to enabled = false (or vice versa)

  4. You can adjust:

    • minPurchase - Minimum amount players can buy

    • maxPurchase - Maximum amount players can buy

    • transactionFee - Fee percentage (0.02 = 2%)

Important: You can have a maximum of 20 enabled cryptocurrencies. If you enable more than 20, the resource will continue running but won't fetch prices for the extra ones.

Configuring Stocks

  1. Open the file: tgg-markets/config/config.stocks.lua

  2. You'll see a list of stocks like AAPL (Apple), GOOGL (Google), MSFT (Microsoft), etc.

  3. To enable or disable a stock, change enabled = true to enabled = false (or vice versa)

  4. You can adjust:

    • minShares - Minimum number of shares players can buy

    • maxShares - Maximum number of shares players can buy

    • transactionFee - Fee percentage (0.015 = 1.5%)

Important: You can have a maximum of 20 enabled stocks. If you enable more than 20, the resource will continue running but won't fetch prices for the extra ones.

Step 4: Start the Resource

  1. Make sure your server is running

  2. In your server console, type:

    ensure tgg-markets
  3. The resource will start and automatically:

    • Create the necessary database tables

    • Begin fetching prices for enabled cryptocurrencies and stocks

    • Set up the Markets app in the phone

Step 5: Access the Markets App

Players can now access the Markets app from their phone:

  1. Open the phone

  2. Look for the Markets app icon

  3. Tap it to open

  4. Players will need to create an account the first time they open it

How It Works

  • Real-time Prices: The app fetches live prices from Finnhub every 5 minutes

  • Buying & Selling: Players can buy and sell cryptocurrencies and stocks

  • Portfolio: Players can see their holdings and portfolio value

  • Transfers: Players can transfer assets to other players

  • Transaction History: All trades are recorded and can be viewed

App Interface Overview

The Markets app provides a comprehensive interface for trading. Here's what players will see:

  • Dashboard: The main dashboard shows an overview of the player's portfolio, including total value and recent activity.

Markets App Dashboard
  • Cryptocurrencies Tab: Players can view all available cryptocurrencies, their current prices, and price changes. They can tap on any cryptocurrency to see more details and make trades.

Crypto Tab Overview
  • Stocks Tab: Similar to the crypto tab, players can browse available stocks, view prices, and access detailed information for each stock.

Stocks Tab Overview
  • Price Charts: When viewing a specific cryptocurrency or stock, players can see detailed price charts showing historical performance and trends.

Overview Chart
  • Buying Assets: Players can easily buy cryptocurrencies or stocks by entering the amount they want to purchase. The app shows the current price and calculates the total cost including fees.

Buy Screen
  • Transferring Assets: Players can transfer their holdings to other players by entering the recipient's information and the amount to transfer.

Transfer Screen
  • Transaction History: All trades, purchases, sales, and transfers are recorded in the transaction history, allowing players to track their trading activity.

Transaction History

Trading Fees

By default, the Markets app charges:

  • 0.1% fee on all trades (buying and selling)

  • 0.1% fee on transfers between players

You can adjust these fees in tgg-markets/config/config.lua:

Config.Trading = {
    TradingFee = 0.001,      -- 0.1% fee on trades
    TransferFee = 0.001,     -- 0.1% fee on transfers
}

Troubleshooting

"Invalid API key" Error

  • Make sure you copied the entire API key correctly

  • Check for any extra spaces before or after the key

  • Verify the key is correct in your server.cfg or apiKeys.lua file

  • Restart the resource after adding the key

"Rate limit exceeded" Error

  • You have too many enabled cryptocurrencies or stocks (max 20 of each)

  • Disable some cryptocurrencies or stocks in the config files

  • Restart the resource

Prices Not Updating

  • Check your server console for error messages

  • Verify your API key is correct

  • Make sure you haven't exceeded the 20 symbol limit per type

  • Check your internet connection

Markets App Not Showing in Phone

  • Make sure tgg-markets resource is started

  • Verify yseries phone system is installed and running

  • Check server console for any error messages

  • Restart both resources

Important Notes

  • Keep Your API Key Secret: Never share your API key publicly or commit it to public repositories

  • Free Tier Limits: The free Finnhub tier allows 60 API calls per minute, which is perfect for this app

  • Database: The resource automatically creates and manages its own database tables

  • No Credit Card Required: The free Finnhub tier doesn't require payment information

Need More Help?

If you encounter any issues:

  1. Check your server console for error messages

  2. Verify your API key is correct

  3. Make sure you've restarted the resource after making changes

  4. Open a ticket on our discord server


That's it! Your Markets app should now be working. Players can start trading cryptocurrencies and stocks from their phones.

Last updated