Skip to content
This repository was archived by the owner on Apr 20, 2019. It is now read-only.

Commit b453ee7

Browse files
committed
Add documentation and fix LICENSE file
1 parent 52b96e4 commit b453ee7

File tree

3 files changed

+61
-5
lines changed

3 files changed

+61
-5
lines changed

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
same "printed page" as the copyright notice for easier
188188
identification within third-party archives.
189189

190-
Copyright 2017 Kevin Dong
190+
Copyright [yyyy] [name of copyright owner]
191191

192192
Licensed under the Apache License, Version 2.0 (the "License");
193193
you may not use this file except in compliance with the License.

MarketWatch.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'''
22
MarketWatch API
33
April 19, 2017
4+
v1.0.0
45
5-
Probably ready for use.
6+
Apache License 2.0
7+
https://github.com/kevindong/marketwatch_api
68
'''
79

810
import json
@@ -211,4 +213,4 @@ def getCashBorrowed(self):
211213
def getExecutionPrice(self):
212214
tree = html.fromstring(self.session.get("http://www.marketwatch.com/game/" + self.game + "/portfolio/transactionhistory").content)
213215
price = self.cleanText(tree.xpath("//*[@id=\"maincontent\"]/section[2]/div[1]/table/tbody/tr[1]/td[6]/text()")[0]).replace("$", "")
214-
return float(price)
216+
return float(price)

README.md

+56-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,63 @@
11
# 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.
43

54
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.
65

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+
761
# License
862
Apache License, Version 2.0
963

0 commit comments

Comments
 (0)