A Python wrapper for interacting with the Games section of MarketWatch.
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.
Use this API by putting from MarketWatch import *
into your implementation. See driver.py
as an example usage for this wrapper.
Term
: enum for order validity. Options areDAY
andINDEFINITE
.PriceType
: enum for order price type. Options areMARKET
,LIMIT
, andSTOP
.OrderType
: enum for order type. Options areBUY
,SELL
,SHORT
, andCOVER
.Order
: holder for order information.id
: the id of the order, used for canceling orders.ticker
: the normal ticker of the order (such asAAPL
for Apple).quantity
: number of shares the order is for.orderType
: a way to store theOrderType
enum.priceType
: a way to store thePriceType
enum.price
: the price of the order, if applicable.
Call with MarketWatch(email, password, game, debugMode = False)
.
email
: the email of your account.password
: the password of your account.game
: the ID of the game you're in.debugMode
: ifTrue
, orders will not submitted. Optional parameter; default is to not be in debug mode.
getPrice(ticker)
: gets the price of the security with the inputted ticker.ticker
would be something likeAAPL
.<order>(ticker, shares, term = Term.INDEFINITE, priceType = PriceType.MARKET, price = None)
ticker
andshares
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 usepriceType
, you must specifyterm
). You must specifyprice
for certainpriceType
s (LIMIT
andSTOP
). If the optional parameters are not specified, the default (as shown above) will be used.order
can bebuy
,sell
,short
, andcover
.ticker
: the normal ticker of the order (such asAAPL
for Apple).shares
: the number of shares the order is for.term
: enum for order validity. Options areDAY
andINDEFINITE
.priceType
: enum for order price type. Options areMARKET
,LIMIT
, andSTOP
.price
: the price of the order, if applicable. Otherwise, feel free to omit or pass inNone
.
cancelOrder(id)
: cancels the order with the inputtedid
. This value is found in theOrder
class.cancelAllOrders()
: cancels all currently pending orders.getOrders()
: returns a list ofOrder
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).getBuyingPower()
: gets buying power.getCashRemaining()
: gets cash remaining.getCashBorrowed()
: gets cash borrowed.getExecutionPrice()
: gets the price at which the most recently processed order executed at.
The following methods are not intended for use by you.
orderDriver(ticker, shares, term, priceType, price, orderType)
: all the<order>
methods internally call this.submit(payload)
: Receives the order to be submitted to MarketWatch for processing from orderDriver.validateTicker(ticker)
: converts normal tickers (AAPL
) to how it's referred to on MarketWatch internally (STOCK-XNAS-AAPL
).cleanText(text)
: strips out whitespace and junk characters from text.getOrderType(order)
: used ingetOrders()
to determine order type (buy, sell, short, or cover).getPriceOfOrder(order)
: used ingetOrders()
to determine the price of the order.
Initial release.
Apache License, Version 2.0
Copyright 2017 Kevin Dong
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.