This is a continuation of Last time.
LESSON 5 The data Object
The data
object provides various methods [^ 1] to get stock price information.
You can get information on the latest or past stock prices and trading volumes.
The data
object can be used in the following functions.
data.current()
You can get the latest information with the current ()
method.
The code below gets the latest stock price of APPL.
data.current(sid(24), 'price')
In addition to'price', the following can be specified as the argument.
Arguments | Description |
---|---|
price | current price |
open | opening price |
high | high price |
low | low price |
close | closing price |
volume | Volume |
You can also specify multiple stocks as shown below. In this case, the return value is the Series type of pandas.
data.current([sid(24), sid(8554)], 'price')
If there are multiple return values for multiple stocks as shown below, the DataFrame type of pandas will be returned.
data.current([sid(24), sid(8554)], ['low', 'high'])
data.can_trade()
The can_trade ()
method returns whether the stock in question is tradeable on the exchange. Returns True
if it is tradable. It's quite difficult to implement this function by yourself, so it's a simple but convenient function.
data.history() It will be explained in LESSON 6.
[^ 1]: Although it is described as'functions' in the original text, it is easy for Python users to understand. [^ 2] :: I will explain in LESSON 7.
Recommended Posts