馃攳
Fetching Real Time Data using Python | Interactive Brokers | Quantra Free Course - YouTube
Channel: Quantra
[0]
In this video,
[1]
we will learn how to fetch real-time
[3]
data for the given securities
[5]
from the Interactive Brokers server.
[8]
Fetching Real-time Data
[10]
The IBridgePy package contains two
[13]
methods namely data.current and
[15]
show_real_time_price method
[17]
to fetch real-time data.
[20]
Let us see how to
[21]
use each of these methods.
[24]
data.current method
[26]
The data.current method returns
[28]
the real-time data for the
[30]
given securities for
[31]
the specified fields.
[34]
The slide shows the syntax
[35]
of the data.current method.
[38]
The security argument in the
[40]
data.current method signifies
[42]
the security object, created by
[44]
either using the symbol, symbols
[47]
or the superSymbol functions.
[50]
The fields argument can take
[51]
values like the ask price,
[53]
bid price, ask size, bid
[56]
size, last traded price etc.
[59]
Let us take some examples
[61]
and see how the method in used.
[63]
Let us see how to
[64]
pull real-time data for a
[65]
single security with a single
[67]
field passed to it.
[69]
First, we create a security
[71]
object using the AAPL stock.
[74]
This security object is used
[76]
as the argument to the
[77]
data.current method.
[80]
We specify the field for
[81]
which we want to pull
[82]
the data as the second
[83]
argument to the
[84]
data.current method.
[89]
The method will return a
[90]
scalar value of the selected
[92]
field which can be seen
[93]
in the Python console.
[96]
Let us now see how
[97]
to pull data for a
[98]
single security with a list of fields.
[102]
In this case, we specify
[104]
a list of fields instead
[105]
of a single field as
[106]
the second argument to the
[108]
data.current method.
[113]
A pandas series is returned
[114]
whose indices are the fields,
[116]
and whose values are scalar
[118]
values for this asset for each field.
[124]
In the third example,
[125]
let us pass a list of
[126]
securities and a list of fields.
[130]
First, we create a security
[132]
object which contains a list of securities.
[137]
This security object is passed
[139]
to the data.current
[140]
method along with the list
[141]
of fields for which we
[143]
want to pull the data.
[146]
In this case, a pandas
[148]
data frame is returned, which
[150]
is indexed by securities.
[153]
The columns represent the requested
[155]
fields, filled with the scalar
[157]
values for each security for
[159]
each field.
[161]
To pull real-time data for
[162]
a futures contract we use
[164]
the superSymbol function and
[166]
specify the relevant fields of
[168]
the futures contract as arguments
[170]
to the function.
[172]
This security object is passed
[174]
to the data.current
[175]
method to fetch the
[177]
real-time data.
[181]
We can use the same
[182]
superSymbol function to fetch
[184]
data for an options contract
[186]
as illustrated in this example.
[192]
Another way to fetch
[193]
real-time data is using
[194]
show_real_time_price method.
[196]
show_real_time_price method
[200]
The show_real_time_price
[202]
method is used to request
[203]
real-time quotes of the
[205]
specified security from Interactive
[207]
Brokers server.
[209]
The real-time prices are received
[211]
automatically until the request is cancelled.
[214]
In case the user has not subscribed to
[216]
the real-time quotes of the
[218]
requested security, an error
[220]
message is thrown.
[222]
The slide shows the syntax
[223]
of the show_real_time_price method.
[226]
The method takes a security
[228]
object which is created using
[230]
the symbol function.
[232]
The version argument takes valid
[233]
values like bid price, ask
[236]
price and last price.
[238]
Let us
[239]
see how this is done in Python.
[246]
As can be seen, the
[247]
method pulls real-time values for
[250]
the specified field.
[253]
That is all for this video lecture.
[257]
In this video, we saw
[258]
how to fetch real-time data
[260]
from Interactive Brokers server.
[263]
In the next video, we
[264]
will learn how to fetch
[265]
historical data using IBridgePy.
Most Recent Videos:
You can go back to the homepage right here: Homepage





