|
1 | 1 | # MarketWatch API
|
2 |
| - |
3 |
| -A Python wrapper for interacting with the Games section of MarketWatch. This is a work in progress and things will break. |
| 2 | +A Python wrapper for interacting with the Games section of MarketWatch. |
4 | 3 |
|
5 | 4 | This wrapper works by reverse engineering how the MarketWatch website works. Consequently, this wrapper is very fragile and depends on MarketWatch not changing their website.
|
6 | 5 |
|
| 6 | +# Usage |
| 7 | +Use this API by putting `from MarketWatch import *` into your implementation. See `driver.py` as an example usage for this wrapper. |
| 8 | + |
| 9 | +## Helper Classes |
| 10 | +* `Term`: enum for order validity. Options are `DAY` and `INDEFINITE`. |
| 11 | +* `PriceType`: enum for order price type. Options are `MARKET`, `LIMIT`, and `STOP`. |
| 12 | +* `OrderType`: enum for order type. Options are `BUY`, `SELL`, `SHORT`, and `COVER`. |
| 13 | +* `Order`: holder for order information. |
| 14 | + * `id`: the id of the order, used for canceling orders. |
| 15 | + * `ticker`: the normal ticker of the order (such as `AAPL` for Apple). |
| 16 | + * `quantity`: number of shares the order is for. |
| 17 | + * `orderType`: a way to store the `OrderType` enum. |
| 18 | + * `priceType`: a way to store the `PriceType` enum. |
| 19 | + * `price`: the price of the order, if applicable. |
| 20 | + |
| 21 | +## Main Class (`MarketWatch`) |
| 22 | +### Constructor |
| 23 | +Call with `MarketWatch(email, password, game, debugMode = False)`. |
| 24 | + |
| 25 | +* `email`: the email of your account. |
| 26 | +* `password`: the password of your account. |
| 27 | +* `game`: the ID of the game you're in. |
| 28 | +* `debugMode`: if `True`, orders will not submitted. Optional parameter; default is to not be in debug mode. |
| 29 | + |
| 30 | +### Methods |
| 31 | +* `getPrice(ticker)`: gets the price of the security with the inputted ticker. `ticker` would be something like `AAPL`. |
| 32 | +* `<order>(ticker, shares, term = Term.INDEFINITE, priceType = PriceType.MARKET, price = None)` |
| 33 | + * `ticker` and `shares` are mandatory. You may omit parameters if desired. However, you must include all parameters prior to the one you want to use (i.e. to use `priceType`, you must specify `term`). You must specify `price` for certain `priceType`s (`LIMIT` and `STOP`). If the optional parameters are not specified, the default (as shown above) will be used. |
| 34 | + * `order` can be `buy`, `sell`, `short`, and `cover`. |
| 35 | + * `ticker`: the normal ticker of the order (such as `AAPL` for Apple). |
| 36 | + * `shares`: the number of shares the order is for. |
| 37 | + * `term`: enum for order validity. Options are `DAY` and `INDEFINITE`. |
| 38 | + * `priceType`: enum for order price type. Options are `MARKET`, `LIMIT`, and `STOP`. |
| 39 | + * `price`: the price of the order, if applicable. Otherwise, feel free to omit or pass in `None`. |
| 40 | +* `cancelOrder(id)`: cancels the order with the inputted `id`. This value is found in the `Order` class. |
| 41 | +* `cancelAllOrders()`: cancels all currently pending orders. |
| 42 | +* `getOrders()`: returns a list of `Order` objects. Each of which stands for one pending order you currently have, as displayed on MarketWatch. Only grabs orders on the first page (should be 10). |
| 43 | +* `getBuyingPower()`: gets buying power. |
| 44 | +* `getCashRemaining()`: gets cash remaining. |
| 45 | +* `getCashBorrowed()`: gets cash borrowed. |
| 46 | +* `getExecutionPrice()`: gets the price at which the most recently processed order executed at. |
| 47 | + |
| 48 | +The following methods are not intended for use by you. |
| 49 | + |
| 50 | +* `orderDriver(ticker, shares, term, priceType, price, orderType)`: all the `<order>` methods internally call this. |
| 51 | +* `submit(payload)`: Receives the order to be submitted to MarketWatch for processing from orderDriver. |
| 52 | +* `validateTicker(ticker)`: converts normal tickers (`AAPL`) to how it's referred to on MarketWatch internally (`STOCK-XNAS-AAPL`). |
| 53 | +* `cleanText(text)`: strips out whitespace and junk characters from text. |
| 54 | +* `getOrderType(order)`: used in `getOrders()` to determine order type (buy, sell, short, or cover). |
| 55 | +* `getPriceOfOrder(order)`: used in `getOrders()` to determine the price of the order. |
| 56 | + |
| 57 | +# Version History |
| 58 | +## 1.0.0 |
| 59 | +Initial release. |
| 60 | + |
7 | 61 | # License
|
8 | 62 | Apache License, Version 2.0
|
9 | 63 |
|
|
0 commit comments