Cancel an existing market data subscription.

cancel_mkt_data(req_names)

Arguments

req_names

Character vector containing the names of the subscriptions you wish to cancel. May contain any or all existing market data subsription names. If left blank or set to value "**all**", then `cancel_mkt_data`() will cancel every active market data subscription.

Value

TRUE upon success (invisible), FALSE or error otherwise.

See also

Other market data: req_market_data_type(), req_mkt_data()

Examples

# --> This example may be run on a paper trading account with no market data # feed. This will be the case if you start up a new IB account without # purchasing a subscription. In that case, you'll see a "Market Data not # subscribed..." message, which means everything is operating normally. If you # purchase a data subscription, this message will not appear. # Create a connection to IB create_new_connections() #### Snapshot Example: Exxon stock ################################################################################ # Fetch a delayed market data snapshot for Exxon (XOM) req_mkt_data( contract = c( symbol = "XOM", secType = "STK", currency = "USD", exchange = "SMART" ), snapshot = TRUE, data_name = "Exxon_delayed", mktDataType = "DELAYED" ) # Note that a "mkt_data" subscription now appears: subscriptions$mkt_data
#> # A tibble: 1 x 8 #> req_name contract mktDataType snapshot regulatorySnaps… req_id conn_row #> <chr> <list> <dbl> <lgl> <lgl> <dbl> <dbl> #> 1 Exxon_d… <chr [4… 3 TRUE FALSE 0 4 #> # … with 1 more variable: client_id <int>
# For the sake of this example, wait 3 seconds or so to be sure that the data # has time to arrive. Sys.sleep(3) # Read the data off the sock and update "mkt_data" read_sock_drawer() # Now you have a market data snapshot in your mkt_data slate! You can access it # with the "$" operator, like this: mkt_data$Exxon_delayed$TICK_PRICE
#> # A tibble: 7 x 3 #> tick price size #> <chr> <dbl> <dbl> #> 1 Delayed Last 33.3 1 #> 2 Delayed High Price 36.7 0 #> 3 Delayed Low Price 33.3 0 #> 4 Delayed Close 36.8 0 #> 5 Delayed Open 0 0 #> 6 Delayed Bid 33.3 4 #> 7 Delayed Ask 33.3 8
mkt_data$Exxon_delayed$TICK_SIZE
#> # A tibble: 1 x 2 #> tick size #> <chr> <dbl> #> 1 Delayed Volume 237409
mkt_data$Exxon_delayed$`Delayed Last Timestamp`
#> [1] "2020-03-18 12:48:49 EDT"
mkt_data$Exxon_delayed$TICK_REQ_PARAMS
#> # A tibble: 1 x 3 #> minTick bboExchange snapshotPermissions #> <dbl> <chr> <dbl> #> 1 0.01 a60001 1
# ...etc # Note that the mkt_data subscription has been destroyed. This is because you # set snapshot to TRUE -- when read_sock_drawer() finds a completed snapshot, # it automatically updates the subscription. subscriptions$mkt_data
#> NULL
#### Subscription Example: Five stocks ################################################################################ # Snapshots are great if you just want to quickly fetch market data for a # contract and move on. Often, however, you'll want to stay up-to-date on market # data by creating a persistent subscription, causing the data in the mkt_data # slate to update every time read_sock_drawer() is called. # To do this, first create a sock for yourself (if you didn't already): create_new_connections() # Now, set up market data subscriptions to Tesla, Apple, Facebook, 3M, # Interactive Brokers and whatever else you want to follow. Below, the walk() # function from package "purrr" is used to call req_mkt_data on each stock. c("TSLA", "AAPL", "FB", "MMM", "IBKR") %>% purrr::walk( function(stock_symbol){ req_mkt_data( contract = c( symbol = stock_symbol, secType = "STK", currency = "USD", exchange = "SMART" ), mktDataType = "DELAYED", snapshot = FALSE, channel = "async" ) } ) # Note that the mkt_data subscriptions you just created appear in the # subscriptions variable: subscriptions$mkt_data
#> # A tibble: 5 x 8 #> req_name contract mktDataType snapshot regulatorySnaps… req_id conn_row #> <chr> <list> <dbl> <lgl> <lgl> <dbl> <dbl> #> 1 1_TSLA <chr [4… 3 FALSE FALSE 1 4 #> 2 2_AAPL <chr [4… 3 FALSE FALSE 2 5 #> 3 3_FB <chr [4… 3 FALSE FALSE 3 4 #> 4 4_MMM <chr [4… 3 FALSE FALSE 4 4 #> 5 5_IBKR <chr [4… 3 FALSE FALSE 5 5 #> # … with 1 more variable: client_id <int>
# Wait a bit for the data to come through for example's sake... Sys.sleep(3) # Read the sock drawer as many times as you want read_sock_drawer() # Access your data: mkt_data$`1_TSLA`$TICK_PRICE
#> # A tibble: 7 x 3 #> tick price size #> <chr> <dbl> <dbl> #> 1 Delayed Bid 380. 3 #> 2 Delayed Ask 380. 6 #> 3 Delayed Last 380. 1 #> 4 Delayed High Price 405. 0 #> 5 Delayed Low Price 378. 0 #> 6 Delayed Close 430. 0 #> 7 Delayed Open 0 0
mkt_data$`4_MMM`$TICK_PRICE
#> # A tibble: 7 x 3 #> tick price size #> <chr> <dbl> <dbl> #> 1 Delayed Last 133. 1 #> 2 Delayed High Price 139. 0 #> 3 Delayed Low Price 128. 0 #> 4 Delayed Close 134. 0 #> 5 Delayed Open 0 0 #> 6 Delayed Bid 132. 1 #> 7 Delayed Ask 133. 3
# ...etc # Because these subscriptions aren't for snapshots, they'll stay active until # cancelled. When you're ready, cancel any/all of your subscriptions: cancel_mkt_data() # Subscriptions are gone! subscriptions$mkt_data
#> NULL