Skip to content

Instantly share code, notes, and snippets.

@moomoohk
Created August 4, 2014 04:17
Show Gist options
  • Save moomoohk/237c76ba19bff48c1cfc to your computer and use it in GitHub Desktop.
Save moomoohk/237c76ba19bff48c1cfc to your computer and use it in GitHub Desktop.
A little demo+docs of how the TradeOrder system will work in Market Maven
/**
*
* @author Meshulam Silk (moomoohk@ymail.com)
* @since Aug 4, 2014
*/
public class BrokerTest
{
public static void main(String[] args)
{
/*
* Profile loading/creation
*/
try
{
Game.profile = Profile.load("Broker test");
}
catch (Error | Exception e)
{
System.out.println("Problem loading profile. Defaulting.");
Game.profile = new Profile("Broker test");
}
/*
* Create people and company agents. People will trade in shares that come from companies.
*/
Person p1 = new Person("butthoolio", "mcgee", 20, 2000), p2 = new Person("jose", "nowhey", 20, 2000), p3 = new Person("mike", "hunt", 20, 2000);
Company c1 = new Company("company 1", new CompanyType("furniture", 1), 10, 100, 10000), c2 = new Company("company 1", new CompanyType("cars", 1), 10, 100, 10000);
/*
* Manual trading. Once the TradeOrder system is up to snuff this will be automated.
*
* Begin by creating an IPO state for company 1. In this case create 10 1 share sell TradeOrders, each for the current price of the share (which at the start is the initial price). Company 1 started with 100 shares (defined above) so this IPO makes up 10% of their total shares.
*/
for (int i = 1; i <= 10; i++)
Game.profile.getBroker().addTradeOrder(new TradeOrder(TradeOrderType.SELL, c1, c1, 1, c1.STOCK.getCurrentPrice()));
/*
* Create buy TradeOrders for people.
*
* In this case p1 (butthoolio mcgee) and p2 (jose nowhey) both submit a 1 share buy TradeOrder for shares in company 1 (which is in IPO stage) for the initial price.
* The system will match up company 1's IPO sell TradeOrders with these 2 people's buy TradeOrders and the trade will occur automatically.
*/
Game.profile.getBroker().addTradeOrder(new TradeOrder(TradeOrderType.BUY, p1, c1, 1, c1.STOCK.getCurrentPrice()));
Game.profile.getBroker().addTradeOrder(new TradeOrder(TradeOrderType.BUY, p2, c1, 1, c1.STOCK.getCurrentPrice()));
/*
* The broker/TradeOrder system is good because:
* - A lot of work mitigation happening behind the scenes (matching up trades automatically as soon as new ones are submitted as opposed to "manually" doing it every game clock tick for example) = shorter, cleaner code and efficiency/optimization (did anyone say buzzwords?)
* - Analyzing the system for characteristics like supply and demand becomes near trivial since all the data is stored in friendly packages (TradeOrder objects)
* - It closer emulates how stock trading works in real life. This is a solid guideline which will make complexifying the system simpler and more sensical in the future
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment