Skip to content

Commit 59960bc

Browse files
committed
v111
1 parent b30a084 commit 59960bc

14 files changed

+75
-64
lines changed

DESCRIPTION

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: rusquant
22
Type: Package
33
Title: Quantitative Trading Framework
4-
Version: 1.1.0
5-
Date: 2024-05-12
4+
Version: 1.1.1
5+
Date: 2024-05-29
66
Author: Vyacheslav Arbuzov[cph, cre, aut], Sergey Edunov[aut]
77
Depends: quantmod,data.table,jsonlite,httr,xts
88
Imports: XML,stringr,jose,stats,rvest,base64enc
@@ -11,6 +11,6 @@ Description: Collection of functions to retrieve financial data from various sou
1111
LazyLoad: yes
1212
License: GPL-3
1313
Encoding: UTF-8
14-
URL: https://rusquant.ru,https://docs.rusquant.ru
14+
URL: https://rusquant.ru
1515
BugReports: https://github.com/arbuzovv/rusquant/issues
1616
RoxygenNote: 7.2.3

R/getEarnings.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' @note Not for the faint of heart. All profits and losses related are yours and yours alone. If you don't like it, write it yourself.
1010
#' @author Vyacheslav Arbuzov
1111
#' @examples
12-
#' getEarnings(from = Sys.Date(),to = Sys.Date()+3,country='Belgium')
12+
#' getEarnings(from = Sys.Date(),to = Sys.Date()+5,country='Belgium')
1313
#' @export
1414

1515
getEarnings <- function(from=Sys.Date()-5,to=Sys.Date()+5,country='United States')
@@ -134,7 +134,7 @@ getEarnings <- function(from=Sys.Date()-5,to=Sys.Date()+5,country='United States
134134
Records_result <- Records
135135
}
136136
}
137-
return(unique(Records_result))
137+
tryCatch(unique(Records_result), error = function(e) print('no current data'))
138138
}
139139

140140

R/getOrderbook.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
#' @examples
2121
#' getOrderbook('USDTGBP', src = 'kraken')
2222
#' getOrderbook('BTC_USDT', src = 'poloniex')
23-
#' getOrderbook('SBER', src = 'moex')
24-
#' getOrderbook('SiH5', src = 'moex',market='forts')
2523
#' @export
2624

2725
"getOrderbook" <- function #S3 function (Poloniex is a class of first argument)
@@ -46,9 +44,15 @@
4644
{
4745
engine = ifelse(market == 'shares','stock','futures')
4846
if(market == 'forts') board = 'rfud'
47+
login <- Sys.getenv('MOEX_DATASHOP_LOGIN')
48+
password <- Sys.getenv('MOEX_DATASHOP_PASSWORD')
49+
cookie_value <- Sys.getenv('MOEX_DATASHOP_COOKIE')
50+
if(login == '' & password=='')
51+
return('authenticate to ISS Moex using login/password ')
52+
headers = c('Cookie' = paste0('MicexPassportCert=',cookie_value))
4953
full_url <- sprintf('https://iss.moex.com/iss/engines/%s/markets/%s/boards/%s/securities/%s/orderbook.json',
5054
engine,market, board, Symbols)
51-
response <- GET(full_url, encode = "json")
55+
response <- GET(full_url, encode = "json",add_headers(headers))
5256
if(response$status_code==200)
5357
{
5458
json_response <- content(response, "text", encoding = "UTF-8")

R/getSymbols.Algopack.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#' getSymbols.Algopack(Symbols = 'Si',type = 'oi')
2424
#' # market concentration for available stocks
2525
#' #getSymbols.Algopack(date = '2024-05-10',type = 'hi2')
26+
#' # market concentration for current stock
27+
#' #devgetSymbols.Algopack('SBER',from = '2023-10-24',to='2023-11-04',type = 'hi2')
2628
#' # market concentration for available fx
2729
#' #getSymbols.Algopack(date = '2024-05-10',type = 'hi2',market='fx')
2830
#' # market concentration for available futures

R/getSymbols.Gigapack.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@ getSymbols.Gigapack <- function(Symbols,
4444
if(fake == FALSE)
4545
{
4646
if(field == '') field = 'close'
47-
gigapack.downloadUrl = paste0('https://api.rusquant.io/gigacandles?symbol=',Symbols.name,'&field=',field,'&orient=table&date=',date)
47+
gigapack.downloadUrl = paste0('https://api.rusquant.ru/gigacandles?symbol=',Symbols.name,'&field=',field,'&orient=table&date=',date)
4848
data_result = data.table(fromJSON(gigapack.downloadUrl))
4949
data_result = data_result[order(date)]
5050
}
5151
if(fake == TRUE)
5252
{
5353
if(field == '') field = 'close'
54-
gigapack.downloadUrl = paste0('https://api.rusquant.io/altergiga?symbol=',Symbols.name,'&field=',field,'&trim=',trim,'&reps=',reps,'&orient=table')
54+
gigapack.downloadUrl = paste0('https://api.rusquant.ru/altergiga?symbol=',Symbols.name,'&field=',field,'&trim=',trim,'&reps=',reps,'&orient=table')
5555
data_result = data.table(fromJSON(gigapack.downloadUrl))
5656
data_result = data_result[order(date)]
5757
}
@@ -62,13 +62,13 @@ getSymbols.Gigapack <- function(Symbols,
6262
if(field!='') field_q = paste0('&field=',field)
6363
if(fake == FALSE)
6464
{
65-
gigapack.downloadUrl = paste0('https://api.rusquant.io/gigatech?symbol=',Symbols.name,'&orient=table',field_q)
65+
gigapack.downloadUrl = paste0('https://api.rusquant.ru/gigatech?symbol=',Symbols.name,'&orient=table',field_q)
6666
data_result = data.table(fromJSON(gigapack.downloadUrl))
6767
data_result = data_result[order(date)]
6868
}
6969
if(fake == TRUE)
7070
{
71-
gigapack.downloadUrl = paste0('https://api.rusquant.io/altertech?symbol=',Symbols.name,'&orient=table',field_q,'&trim=',trim,'&reps=',reps)
71+
gigapack.downloadUrl = paste0('https://api.rusquant.ru/altertech?symbol=',Symbols.name,'&orient=table',field_q,'&trim=',trim,'&reps=',reps)
7272
data_result = data.table(fromJSON(gigapack.downloadUrl))
7373
data_result = data_result[order(date)]
7474
}

R/getSymbols.MarketWatch.R

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
#' @title MarketWatch Alor data
1+
#' @title MarketWatch data
22
#'
33
#' @description This function retrieves historical financial data for a given symbol from the MarketWatch website and returns it as a data frame or assigns it to an R object.
44
#'
55
#' @param Symbols A character vector specifying the name of the financial instrument(s) to retrieve.
6-
#' @param env An environment where the data should be loaded.
76
#' @param from A character string specifying the starting date for the historical data in the format "YYYY-MM-DD".
87
#' @param to A character string specifying the ending date for the historical data in the format "YYYY-MM-DD".
98
#' @param adjust A logical value indicating whether to adjust the prices for splits and dividends. The default value is FALSE.
@@ -18,12 +17,12 @@
1817
#' @note Not for the faint of heart. All profits and losses related are yours and yours alone. If you don't like it, write it yourself.
1918
#' @author Vyacheslav Arbuzov
2019
#' @examples
21-
#' getSymbols.MarketWatch(Symbols = 'liborusd3m',market = 'interestrate',countrycode = 'mr')
22-
#' getSymbols.MarketWatch(Symbols = 'tmubmusd03m',market = 'bond',countrycode = 'bx')
20+
#' getSymbols.MarketWatch(Symbols = 'liborusd3m',market = 'interestrate',countrycode = 'mx')
21+
#' #getSymbols.MarketWatch(Symbols = 'tmubmusd03m',market = 'bond',countrycode = 'bx')
2322
#' @export
2423

2524
"getSymbols.MarketWatch" <-
26-
function(Symbols,env=globalenv(),
25+
function(Symbols,
2726
from='2007-01-01',
2827
to=Sys.Date(),
2928
adjust=FALSE,
@@ -39,7 +38,7 @@
3938
mw.from = format(as.Date(from),'%m/%d/%Y')
4039
mw.to = format(as.Date(to),'%m/%d/%Y')
4140
full_url <- paste0(endpoint,market,'/' ,Symbol.name,'/downloaddatapartial?startdate=',mw.from,'%2000:00:00&enddate=',mw.to,'%2023:59:59&frequency=p1d&csvdownload=true&countrycode=',countrycode)
42-
if(verbose==T) print(full_url)
41+
if(verbose==TRUE) print(full_url)
4342
headers = add_headers('Accept' = 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
4443
'Accept-Language' = 'en-US,en;q=0.9,fr;q=0.8,ja;q=0.7,es;q=0.6',
4544
'Accept-Encoding' = 'gzip, deflate, br',
@@ -50,11 +49,20 @@
5049
'Sec-Fetch-Site' = 'none',
5150
'User-Agent'= 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4.1 Safari/605.1.15')
5251
r <- GET(full_url,headers)
53-
df = data.table(content(r))
54-
Symbol.name <-toupper(gsub('\\^','',Symbol.name))
55-
if(auto.assign)
56-
assign(Symbol.name,df,env)
57-
58-
if(auto.assign) return(Symbol.name)
59-
return(df)
52+
if(r$status_code==200)
53+
{
54+
df = data.table(content(r, encoding = "UTF-8"))
55+
if(ncol(df)==0) print('set correct symbols,market,countrycode')
56+
Symbol.name <-toupper(gsub('\\^','',Symbol.name))
57+
if(auto.assign)
58+
assign(Symbol.name,df)
59+
if(auto.assign) return(Symbol.name)
60+
return(df)
61+
}
62+
if(r$status_code!=200)
63+
{
64+
status = 'set correct symbols,market,countrycode'
65+
print(status)
66+
return(status)
67+
}
6068
}

R/getSymbols.Moex.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
auto.assign=FALSE,
3434
...)
3535
{
36+
old <- options()
37+
on.exit(options(old))
38+
options(timeout=7)
3639
V2 <- V14 <- V15 <- begin <- high <- low <- volume <- NULL
3740
for(Symbol.name in Symbols)
3841
{
@@ -95,11 +98,6 @@
9598
message('Server of MOEX not response - try later')
9699
return(NULL)
97100
#print(e)
98-
},
99-
#if a warning occurs, tell me the warning
100-
warning=function(w) {
101-
message('Check your internet connection')
102-
return(NULL)
103101
}
104102
)
105103

R/getTradelog.R

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
#' @param depth Numeric scalar, specifying the number of trades to retrieve (default = 500).
77
#' @param src Character scalar, specifying the exchange to retrieve trade logs from. The supported exchanges are: "tinkoff", "alor", "poloniex", "kraken", "binance", "bttrex", "cex", "gate", "gatecoin", "gdax", "gemini", "hitbtc", "liqui", and "lykke".
88
#' @param api.key Character scalar, specifying the API key (if required by the exchange).
9-
#' @param tradeno First number of trade
109
#' @param adjust Logical scalar, specifying whether to adjust timestamps for time zones (default = FALSE).
1110
#' @param return.class Character scalar, specifying the class of the returned object. The supported classes are: "data.table", "data.frame", and "xts" (default = "data.table").
1211
#' @param index.class Character scalar, specifying the class of the index column. The supported classes are: "Date" and "POSIXct" (default = "Date").
@@ -28,7 +27,6 @@
2827
"getTradelog" <- function
2928
(Symbols,depth=500,src='poloniex',api.key = '',
3029
adjust=FALSE,return.class='data.table',index.class='Date',
31-
tradeno=1,
3230
market = 'shares',
3331
board = 'tqbr',
3432
verbose=FALSE,
@@ -39,29 +37,37 @@
3937
{
4038
engine = ifelse(market == 'shares','stock','futures')
4139
if(market == 'forts') board = 'rfud'
42-
full_url <- sprintf('https://iss.moex.com/iss/engines/%s/markets/%s/boards/%s/securities/%s/trades.json?tradeno=%s',
43-
engine,market, board, Symbols,tradeno)
44-
login <- Sys.getenv('MOEX_DATASHOP_LOGIN')
45-
password <- Sys.getenv('MOEX_DATASHOP_PASSWORD')
46-
cookie_value <- Sys.getenv('MOEX_DATASHOP_COOKIE')
47-
if(login == '' & password=='')
48-
return('authenticate to ISS Moex using login/password ')
49-
headers = c('Cookie' = paste0('MicexPassportCert=',cookie_value))
50-
if(full_url==T) print(full_url)
51-
response <- GET(full_url, encode = "json",add_headers(headers))
52-
if(response$status_code==200)
40+
paginate = TRUE
41+
data_pagainated = data.table()
42+
tradeno=0
43+
while(paginate)
5344
{
54-
json_response <- content(response, "text", encoding = "UTF-8")
55-
json_response <- fromJSON(json_response)
56-
data_result = data.table(json_response$trades$data)
57-
if(nrow(data_result)>0)
45+
full_url <- sprintf('https://iss.moex.com/iss/engines/%s/markets/%s/boards/%s/securities/%s/trades.json?tradeno=%s',
46+
engine,market, board, Symbols,tradeno)
47+
login <- Sys.getenv('MOEX_DATASHOP_LOGIN')
48+
password <- Sys.getenv('MOEX_DATASHOP_PASSWORD')
49+
cookie_value <- Sys.getenv('MOEX_DATASHOP_COOKIE')
50+
if(login == '' & password=='')
51+
return('authenticate to ISS Moex using login/password ')
52+
headers = c('Cookie' = paste0('MicexPassportCert=',cookie_value))
53+
response <- GET(full_url, encode = "json",add_headers(headers))
54+
if(response$status_code==200)
5855
{
59-
setnames(data_result,json_response$trades$columns)
60-
for(col in c('PRICE', 'QUANTITY','TRADENO','TRADINGSESSION','DECIMALS','VALUE','TRADETIME_GRP'))
61-
set(data_result, j = col, value = as.numeric(data_result[[col]]))
56+
json_response <- content(response, "text", encoding = "UTF-8")
57+
json_response <- fromJSON(json_response)
58+
data_result = data.table(json_response$trades$data)
59+
if(nrow(data_result)>0)
60+
{
61+
setnames(data_result,json_response$trades$columns)
62+
for(col in c('PRICE', 'QUANTITY','TRADENO','TRADINGSESSION','DECIMALS','VALUE','TRADETIME_GRP'))
63+
set(data_result, j = col, value = as.numeric(data_result[[col]]))
64+
data_pagainated = rbind(data_pagainated,data_result)
65+
if(nrow(data_result) != 5000) paginate = FALSE
66+
if(nrow(data_result) >= 5000) tradeno = max(data_pagainated[,1])
67+
}
6268
}
63-
return(data_result)
6469
}
70+
return(data_pagainated)
6571
if(response$status_code!=200)
6672
if(verbose) return(content(response, as = "parsed"))
6773
}

R/placeOrder.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#' @importFrom jose jwt_split
4242
#' @importFrom stats runif
4343
#' @importFrom xts xts
44-
#'
4544
#' @export
4645

4746
placeOrder = function(src = 'tinkoff',

man/getEarnings.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)