jonesdy / StockSim

A stock simulator website
https://www.openstocksim.com
MIT License
1 stars 0 forks source link

Allow users to buy/sell stocks in their games #28

Closed jonesdy closed 8 years ago

jonesdy commented 9 years ago

This can be split into 2 issues, one for buying and one for selling, if needed.

This is a big part of the stock simulator: buying and selling stocks. The easiest way to get stock prices is probably by using Yahoo's finance API (see: https://stackoverflow.com/questions/10040954/alternative-to-google-finance-api). Getting the CSV by the API call should be the easiest way to do it.

jonesdy commented 9 years ago

Another problem I just thought of: will the users be forced to know the ticker symbol, or can we implement some kind of search? I think for now, it would be easiest to just force the user to know the ticker symbol and we can try some kind of search later.

jonesdy commented 9 years ago

Just messing around with the API, it looks like we want the last trade (price only), as that is what is usually prominently displayed when you click on a stock. This means the format specifiers should be f=sl1. This gives you a CSV with the ticker symbol and last traded price, in that order. This should be rounded up to the nearest penny and then displayed to the user before confirming the price and quantity.

jonesdy commented 9 years ago

It seems that Yahoo's financial API is not supposed to be used. They don't seem to do anything if you are using it, but they aren't a big fan and it seems like I should try and find somewhere else to go. One alternative that seems alright to use would be Quandl (https://www.quandl.com/help/api). The only problem is that you need an API key, which would need to be provided in a file outside of the repository. This shouldn't be a huge problem, as long as I can use that API key here.

jonesdy commented 9 years ago

Quandl doesn't provide enough information (the last traded price), but it seems pretty hard to find anything that will work.

jonesdy commented 9 years ago

It might turn out that Yahoo works fine (see https://stackoverflow.com/questions/14795726/getting-data-from-yahoo-finance) by using YQL. Also see: https://developer.yahoo.com/yql/

jonesdy commented 9 years ago

I found this: "Data available on the Yahoo! network (e.g., Finance, Weather) is not approved for commercial usage via YQL, unless mentioned otherwise in the Terms of Service.", but I do not believe that this counts as commercial usage?

jonesdy commented 9 years ago

A good query would be something like "select * from yahoo.finance.quote where symbol in ("YHOO","AAPL","GOOG","MSFT")". We would want the LastTradePriceOnly and possibly the Name fields. Apparently the REST call for that would be "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22YHOO%22%2C%22AAPL%22%2C%22GOOG%22%2C%22MSFT%22)&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys". This doesn't appear to use any kind of API key, unless using private user or account data (which we don't need, see https://developer.yahoo.com/forum/YQL/Is-YQL-need-a-api-key/1294585146000-eb20d399-8d81-3999-9b89-25be9ddea2d2/).

jonesdy commented 9 years ago

Here's some good stuff on how to call a REST API and consume the XML: https://stackoverflow.com/questions/7177628/calling-restful-service-from-java.

jonesdy commented 9 years ago

When a user goes to the buying stock screen, they should be warned that the price may change before confirming their purchase. If the final price (calculated after confirming the purchase) is too much, the purchase should obviously fail.

jonesdy commented 9 years ago

The process for buying/selling stocks needs to be different. When you select a game, you should be able to buy/sell stocks from there.