curl -s https://api.coindesk.com/v1/bpi/currentprice/usd.json


SELECT 1 AS tbl, pc.pid, cg.longnm, pc.units, pc.basis, cg.price_now * pc.units AS markval 
	FROM Player_Crypto pc
	JOIN Crypto_Game cg ON cg.cd = pc.cd
UNION
SELECT 2 AS tbl, pc.pid, cg.longnm, pc.units, pc.basis, cg.price_now * pc.units AS markval 
	FROM Player_Crypto pc
	JOIN Crypto_Live cg ON cg.cd = pc.cd;
	
	
	SELECT SUM(units * cg.price_now) AS tot_val FROM Player_Crypto pc JOIN Crypto_Game cg ON pc.cd = cg.cd WHERE pid = 201
	UNION
	SELECT SUM(units * cl.price_now) AS tot_val FROM Player_Crypto pc JOIN Crypto_Live cl ON pc.cd = cl.cd 
	
	
	
	SELECT p.cash, c.* FROM Player JOIN (SELECT cd, units FROM Crypto)
	
	JOIN Player p ON p.pid = pc.pid 
	JOIN (SELECT * FROM Crypto_Game UNION SELECT * FROM Crypto_Live) ca ON pc.cd = ca.cd WHERE pc.pid = 201;

SELECT p.pid, p.cash, p.market, pc.cd, pc.units, pc.basis FROM Player p LEFT JOIN Player_Crypto pc ON p.pid = pc.pid AND pc.cd = 2 WHERE p.pid = 201;

SELECT cd, longnm, price_now FROM (SELECT * FROM Crypto_Game UNION SELECT * FROm Crypto_Live) WHERE cd = 1;

# Create a chance for the market to fluctuate randomly on top of volume fluctuation
	# ..RNG fluctuation can vary only up to +/- 10% of the delta_base
	qDb_do("UPDATE Crypto_Game SET delta_fluc = delta_fluc + rand() * (delta_base * 0.2) - (delta_base * 0.1) 
					WHERE delta_base <> 0 ORDER BY RAND() LIMIT 2");	
					
					
						# Check if we've bumped up against any limits	
	$force_wgt = qDb_sc("SELECT cd FROM Crypto_Game WHERE price_now <= price_min ORDER BY RAND() LIMIT 1");
	$force_wgt = -qDb_sc("SELECT cd FROM Crypto_Game WHERE price_now >= price_max ORDER BY RAND() LIMIT 1");
	$new_story = qDb_hr("SELECT * FROM Crypto_News WHERE wgt = $force_wgt ORDER BY RAND() LIMIT 1") if $force_wgt;	
	
	
	SELECT sr.rank, sr.value, sr.squadnm, (SELECT count(p.pid) FROM Player p WHERE p.sid = s.sid) AS members FROM Squad s JOIN Squad_Rank sr ON sr.sid = s.sid AND sr.loc = 0;
	
	