Building a Webgame – How We Made a Stock Market Simulator Out of Nothing and php – part 1

40
6623

Developing a web-based game such as a stock simulator starts with an idea. Not only 'I want to do a stock market simulation' but the idea “ I want to create a different and new, better and more unique stock market simulation than anything that already exists ''

Next is research – seeing what other market simulations are already available and working and seeing how they work from an end user perspective. There are stock market simulations that work using Java and server engines such as The Hollywood Stock Exchange, sims that work using SSI and ASP modules, and open source stock market simulations such as Futures Exchange. . We have looked at them all and determined where the openness is relative to the market and where the demand should be.

We determined that there is a big void when it comes to prediction markets and futures exchanges for stock games and simulators when it comes to TV. There were plenty of websites where you could vote for your show's popularity, and other websites where you could even vote for reality shows and try your hand at predicting who was next to go. But there was no site that treated television like a stock exchange. so we decided this would be our niche game.

TV is a growing industry – Each year they sell more TVs than the year before. Television studios work tirelessly to produce new and different shows to be broadcast on airwaves and cable networks to entertain hundreds of millions of people in North America alone. All of these viewers have an opinion on what they like and what they don't – this is a market unlike any other.

We sat down and put together a checklist of what a TV scholarship might do …

  • Buy and sell stocks in TV shows, TV channels, studios and stars
  • Sell ​​short and hedge the same stocks (Short selling and hedging is the opposite of buying or selling, if you sell a stock short, you hope that the price will drop so that you can make money from it. # 39; autumn.)
  • Rate or vote for popular TV shows
  • offer easy-to-use and transparent registration
  • design the market system for extreme modularity so that we can add new features as we develop them without disrupting the market itself.

This was our original list of features. At the end of the article series – I will show a list of current features and show how the Marketplace system has gained in complexity while retaining all of the basic modularity that we have developed into it.

The most important thing to start with was to create a method to buy and sell stocks, to follow the actual buying and selling process, and to allow the market itself to adjust prices as it goes. as the product is bought and sold.

We decided to use mysql for the database, and also to implement a cron job to do the background calculations and market balancing.

Using the php language we could more easily implement mysql access and also allow more flexibility in the goal of keeping the Stocks Online application as modular as possible.

MySql and php were changed during their lifecycle to work as closely as possible together, so it made sense to use both components to create our stock system as this would allow for easier maintenance and future development. .

From a basic math code of

</p> <p>Buy price = Share price x (Number of shares + commission)<br />

We have developed a simple buy and sell process that would allow the player to buy or sell stocks. the system automatically calculates the commission and adds it to the transaction.

We realized that we needed to limit the shares that can be bought by a single player, so we set a cap of 25,000 shares per share. This would ensure that no actor could have a monopoly on the shares. and also limited the effect of a single purchase or wholesale.

What started out as a simple formula and tracking system quickly turned into a complex math function algorithm that now looked like this:


Number of shares available
= (maximum number of shares available - number of shares owned by the player)
IF
player shares are below the maximum allowed
THEN
process the purchase transaction
Buy
current price * number of shares available + commission (1.5%)
Transaction completed - do market calculations
The share price is adjusted by (+0.01 x 5000 shares or fraction thereof)
cron runs, verifies the transaction and adjusts 0.01 for every 10,000 actions moved
cron also checks if more than 50,000 actions have been moved
then the stock adjusts to idle at 0.01 per cron cycle to ensure that a break-in stock does not occur.

To ensure this goes smoothly, we had to add multiple mysql table entries for the cron and the system to track stock trades in order not only to get a history of transactions and stock movements but also the system could overlap to maintain balance in the event of data corruption or bad stock trading.

The sales transaction was pretty much the same process but with negatives instead of positives.

We've also implemented a voting system that allows players to vote for their favorite TV shows – thus adjusting the value of that show up or down based on their vote. If you liked the show, vote yes, if you don't like it, vote no. We set up a random generator to pull 10 show names from the database every time the voting page loaded so that no show got more weight than any other show. . thus ensuring a uniform distribution of votes. The voting system also rewarded the player by adding play money to their account for each vote clicked. If you voted for all 10 options, you won $ 10,000. So greed has become a factor – earning more dollars to play by voting.

Building the player's wallet page was just a matter of setting up an if / then loop to pull each stock held one by one and display them on the page with their buy price, their current price, their price difference, etc.

The Nest article will explain how we created the stock ticker and other features, as well as future directions for the Stock Online app.


40 COMMENTS

  1. I simply want to mention I am new to blogs and actually loved this web site. Very likely I’m going to bookmark your blog . You definitely have outstanding articles and reviews. Thanks for sharing your web-site.

LEAVE A REPLY

Please enter your comment!
Please enter your name here