R/cancel_account_updates_multi.R
cancel_account_updates_multi.RdStop receiving 3-minute updated Account Update Multi data for an account or model for which a subscription has been started using req_account_updates_multi().
cancel_account_updates_multi(requests = NULL)
| requests | Either a character or a numeric vector containing the names (req_names) or the IDs (req_id`s), respectively, of the requests that you wish to cancel. Valid req_names and req_ids may be be viewed or retrieved using the subscriptions environment. |
|---|
TRUE upon success (invisible), FALSE or error otherwise.
If requests is not supplied, then
cancel_account_updates_multi() will cancel all Account
Updates Multi subscriptions.
Other treasury:
cancel_account_summary(),
req_account_summary(),
req_account_updates_multi(),
req_account_updates()
################################################################################ #### Effect of ledgerAndNLV #################################################### ################################################################################ # Let's look at the difference between calling req_account_updates_multi with # ledgerAndNLV = TRUE vs. setting it to FALSE. #1) Fetch an update using req_account_updates_multi()'s default values for # for account and ledgerAndNLV ("ALL" and TRUE, respectively). req_account_updates_multi()#> # A tibble: 166 x 4 #> account tag tag_value currency #> * <chr> <chr> <chr> <chr> #> 1 DF1267859A AccountCode DF1267859A "" #> 2 DF1267859A AccountReady TRUE "" #> 3 DF1267859A AccountType UNIVERSAL "" #> 4 DF1267859A AccruedCash 1350.39 "USD" #> 5 DF1267859A AccruedCash-C 0.00 "USD" #> 6 DF1267859A AccruedCash-S 1350.39 "USD" #> 7 DF1267859A AccruedDividend 0.00 "USD" #> 8 DF1267859A AccruedDividend-C 0.00 "USD" #> 9 DF1267859A AccruedDividend-S 0.00 "USD" #> 10 DF1267859A AvailableFunds 5007628.56 "USD" #> # … with 156 more rows# The update printed to screen but it's not lost -- it's in the treasury. # 2) Save the treasury object in a variable to use for comparing later: aum_true <- treasury$ACCOUNTS # 3) Clear out the treasury. Without this step, InteractiveTradeR would update # the new ACCOUNTS object when we call req_account_updates_multi() again with # ledgerAndNLV = FALSE, making it hard to tell exactly what effect our changing # of the value of ledgerAndNLV had. clean_slate() # Call req_account_updates_multi() again, but with ledgerAndNLV = FALSE: req_account_updates_multi(ledgerAndNLV = FALSE)#> # A tibble: 166 x 4 #> account tag tag_value currency #> * <chr> <chr> <chr> <chr> #> 1 DF1267859A AccountCode DF1267859A "" #> 2 DF1267859A AccountReady TRUE "" #> 3 DF1267859A AccountType UNIVERSAL "" #> 4 DF1267859A AccruedCash 1350.39 "USD" #> 5 DF1267859A AccruedCash-C 0.00 "USD" #> 6 DF1267859A AccruedCash-S 1350.39 "USD" #> 7 DF1267859A AccruedDividend 0.00 "USD" #> 8 DF1267859A AccruedDividend-C 0.00 "USD" #> 9 DF1267859A AccruedDividend-S 0.00 "USD" #> 10 DF1267859A AvailableFunds 5007628.56 "USD" #> # … with 156 more rows#> [1] "DF1267859A"#> [1] "DF1267859A"# 3.2) See that ledger_and_NLV = FALSE includes more parameters: setdiff(unique(aum_false$tag), unique(aum_true$tag))#> character(0)################################################################################ #### Subscriptions ############################################################# ################################################################################ # Clean slate clean_slate() # Open a socket create_new_connections() # Fetch the account IDs of your six paper trading accounts and use walk() from # the purrr package to subscribe to each one req_managed_accts() %>% purrr::walk( req_account_updates_multi, channel = "async" ) # Verify that you're now subscribed to the six paper trading accounts: subscriptions$account_updates_multi#> # A tibble: 6 x 6 #> req_name account ledgerAndNLV req_id conn_row client_id #> <chr> <chr> <lgl> <dbl> <dbl> <int> #> 1 DF1267859 DF1267859 FALSE 2 4 1 #> 2 DU1267860 DU1267860 FALSE 3 4 1 #> 3 DU1267861 DU1267861 FALSE 4 4 1 #> 4 DU1267862 DU1267862 FALSE 5 4 1 #> 5 DU1267863 DU1267863 FALSE 6 4 1 #> 6 DU1267864 DU1267864 FALSE 7 4 1# Access the retrieved updates: treasury$ACCOUNTS#> # A tibble: 925 x 4 #> account tag tag_value currency #> * <chr> <chr> <chr> <chr> #> 1 DU1267864 AccountType INDIVIDUAL "" #> 2 DU1267864 AccountCode DU1267864 "" #> 3 DU1267864 AccountReady TRUE "" #> 4 DU1267864 Cushion 0.992283 "" #> 5 DU1267864 DayTradesRemaining -1 "" #> 6 DU1267864 DayTradesRemainingT+1 -1 "" #> 7 DU1267864 DayTradesRemainingT+2 -1 "" #> 8 DU1267864 DayTradesRemainingT+3 -1 "" #> 9 DU1267864 DayTradesRemainingT+4 -1 "" #> 10 DU1267864 Leverage-S 0.03 "" #> # … with 915 more rows# You should have all six paper account codes represented in the "account" # column of the ACCOUNTS treasury object. # This information will update every 3 minutes -- and probably more frequently # than that in practice -- for those accounts that have positions in financial # instruments. You can wait for at least one cycle and call read_sock_drawer() # again to see this for yourself. # Save the treasury object to use for comparing later before_cancel <- treasury$ACCOUNTS # When you're ready, cancel a subscription or two: how about the 1st and 3rd? cancel_accounts <- subscriptions$account_updates_multi$req_name[c(1,3)] cancel_account_updates_multi(cancel_accounts)#> [1] "DF1267859" "DU1267861"# Check that the two accounts are indeed removed from subscriptions: subscriptions$account_updates_multi#> # A tibble: 4 x 6 #> req_name account ledgerAndNLV req_id conn_row client_id #> <chr> <chr> <lgl> <dbl> <dbl> <int> #> 1 DU1267860 DU1267860 FALSE 3 4 1 #> 2 DU1267862 DU1267862 FALSE 5 4 1 #> 3 DU1267863 DU1267863 FALSE 6 4 1 #> 4 DU1267864 DU1267864 FALSE 7 4 1#> [1] FALSE# From this point on, the sock drawer will no longer get updated data for the # two accounts that were unsubscribed. # To convince yourself, first read off any data that might have gotten sent # in the time between the last read and the call to cancel: read_sock_drawer() # From this point on, the canceled accounts' treasury data -- which can be # selected using the following code: treasury$ACCOUNTS %>% dplyr::filter(account %in% cancel_accounts)#> # A tibble: 313 x 4 #> account tag tag_value currency #> <chr> <chr> <chr> <chr> #> 1 DU1267861 AccountType INDIVIDUAL "" #> 2 DU1267861 AccountCode DU1267861 "" #> 3 DU1267861 AccountReady TRUE "" #> 4 DU1267861 Cushion 0.956605 "" #> 5 DU1267861 DayTradesRemaining -1 "" #> 6 DU1267861 DayTradesRemainingT+1 -1 "" #> 7 DU1267861 DayTradesRemainingT+2 -1 "" #> 8 DU1267861 DayTradesRemainingT+3 -1 "" #> 9 DU1267861 DayTradesRemainingT+4 -1 "" #> 10 DU1267861 Leverage-S 0.17 "" #> # … with 303 more rows# -- will not update, no matter how many times you call read_sock_drawer(), # unless you subscribe to them again. ################################################################################ #### CANCELLING Subscriptions ################################################## ################################################################################ # Clear out the treasury & subscriptions for this example clean_slate(c("treasury", "subscriptions")) # Open a socket create_new_connections() # Fetch the account IDs of your six paper trading accounts and use walk() from # the purrr package to subscribe to each one req_managed_accts() %>% purrr::walk( req_account_updates_multi, channel = "async" ) # Verify that you're now subscribed to the six paper trading accounts: subscriptions$account_updates_multi#> # A tibble: 6 x 6 #> req_name account ledgerAndNLV req_id conn_row client_id #> <chr> <chr> <lgl> <dbl> <dbl> <int> #> 1 DF1267859 DF1267859 FALSE 8 4 1 #> 2 DU1267860 DU1267860 FALSE 9 4 1 #> 3 DU1267861 DU1267861 FALSE 10 4 1 #> 4 DU1267862 DU1267862 FALSE 11 5 2 #> 5 DU1267863 DU1267863 FALSE 12 5 2 #> 6 DU1267864 DU1267864 FALSE 13 4 1# Access the retrieved updates: treasury$ACCOUNTS#> # A tibble: 489 x 4 #> account tag tag_value currency #> * <chr> <chr> <chr> <chr> #> 1 DU1267861 AccountType INDIVIDUAL "" #> 2 DU1267861 AccountCode DU1267861 "" #> 3 DU1267861 AccountReady TRUE "" #> 4 DU1267861 Cushion 0.956605 "" #> 5 DU1267861 DayTradesRemaining -1 "" #> 6 DU1267861 DayTradesRemainingT+1 -1 "" #> 7 DU1267861 DayTradesRemainingT+2 -1 "" #> 8 DU1267861 DayTradesRemainingT+3 -1 "" #> 9 DU1267861 DayTradesRemainingT+4 -1 "" #> 10 DU1267861 Leverage-S 0.17 "" #> # … with 479 more rows# You should have all six paper account codes represented in the "account" # column of the ACCOUNTS treasury object. # This information will become available every 3 minutes -- and probably more # frequently than that in practice -- for those accounts that have positions in # financial instruments. # You can wait for at least one cycle and see this for yourself; just call # read_sock_drawer() as many times as you'd like to refresh the data. # Save the treasury object to use for comparing later before_cancel <- treasury$ACCOUNTS # When you're ready, cancel a subscription or two: how about the 1st and 3rd? cancel_accounts <- subscriptions$account_updates_multi$req_name[c(1,3)] cancel_account_updates_multi(cancel_accounts)#> [1] "DF1267859" "DU1267861"# Check that the two accounts are indeed removed from subscriptions: subscriptions$account_updates_multi#> # A tibble: 4 x 6 #> req_name account ledgerAndNLV req_id conn_row client_id #> <chr> <chr> <lgl> <dbl> <dbl> <int> #> 1 DU1267860 DU1267860 FALSE 9 4 1 #> 2 DU1267862 DU1267862 FALSE 11 5 2 #> 3 DU1267863 DU1267863 FALSE 12 5 2 #> 4 DU1267864 DU1267864 FALSE 13 4 1#> [1] FALSE# From this point on, the sock drawer will no longer get updated data for the # two accounts that were unsubscribed. # To convince yourself, first read off any data that might have gotten sent # in the time between the last read and the call to cancel: read_sock_drawer() # From this point on, the canceled accounts' treasury data -- which can be # selected using the following code: treasury$ACCOUNTS %>% dplyr::filter(account %in% cancel_accounts)#> # A tibble: 171 x 4 #> account tag tag_value currency #> <chr> <chr> <chr> <chr> #> 1 DU1267861 AccountType INDIVIDUAL "" #> 2 DU1267861 AccountCode DU1267861 "" #> 3 DU1267861 AccountReady TRUE "" #> 4 DU1267861 Cushion 0.956605 "" #> 5 DU1267861 DayTradesRemaining -1 "" #> 6 DU1267861 DayTradesRemainingT+1 -1 "" #> 7 DU1267861 DayTradesRemainingT+2 -1 "" #> 8 DU1267861 DayTradesRemainingT+3 -1 "" #> 9 DU1267861 DayTradesRemainingT+4 -1 "" #> 10 DU1267861 Leverage-S 0.17 "" #> # … with 161 more rows# -- will not update, no matter how many times you call read_sock_drawer(), # unless you subscribe to them again.