Skip to content

Commit b097d46

Browse files
committed
version 1.0.1
global update of rusquant version
1 parent aacac48 commit b097d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+3339
-1813
lines changed

.DS_Store

2 KB
Binary file not shown.

.Rbuildignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^cran-comments\.md$

NEWS.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# rusquant 1.0.1
2+
3+
* add trading API from Tinkoff, Alor, Finam
4+
* add source Tinkoff to getDividends
5+
* add source Moex - getSymbols.Moex
6+
* add source MarketWatch - getSymbols.MarketWatch
7+
* fix problems with getFinam
8+
* add new source to getSymbolList
9+
* add getSymbols from brokers Alor,Tinkoff
10+
* clean code functions and optimize
11+
12+
13+
# rusquant 0.4.2
14+
15+
* loadSymbolList renamed to getSymbolList
16+
* all datasources now from big letter (Mfd,Alor,Investing,Finam,Poloniex)
17+
* getSymbolList function added "Investing" instruments
18+
* fix getOptionChain for download option desk
19+
* delete old datasources without access (rogovindex, dividends from troika)
20+
21+
# rusquant 0.4.1
22+
23+
* loadSymbolList function added "Finam" instruments
24+
* Add "market"" parameter to getSymbols function
25+
* More flexible version of downloading from "Finam"
26+
* getDividends changed type of downloading for long history
27+
* getInvesting from investing.com
28+
29+
30+
# rusquant 0.4.0
31+
32+
* Add function Connect for connection to exchanges
33+
* Add function checkConnection
34+
* Add function getBalance
35+
* Add function getOrders for downloading account orders
36+
* Add function Order for for creation object Order
37+
* Add function openOrder
38+
* Add function cancelOrder
39+
40+
# rusquant 0.3.9
41+
42+
* Add function loadSymbolList for downloading availible symbols
43+
* Add help for function loadSymbolList
44+
* Add additional exchanges to function getOrderbook
45+
* Add additional exchanges to function getTradelog
46+
47+
# rusquant 0.3.8
48+
49+
* Add function getOrderbook for downloading order book snapshots from Poloniex
50+
* Add function getTradelog for downloading trades from Poloniex
51+
* Poloniex output of data now in standart format OHLCV
52+
* Change help of function getSymbols
53+

R/Connect.r

Lines changed: 0 additions & 4 deletions
This file was deleted.

R/Order.R

Lines changed: 0 additions & 9 deletions
This file was deleted.

R/cancelOrder.R

Lines changed: 80 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,82 @@
1-
cancelOrder <- function(Connection, OrderID)
1+
#' @title Cancel an order on a broker/exchange platform
2+
#'
3+
#' @description This function cancels an existing order on a specified broker or exchange platform
4+
#'
5+
#' @param src character string, the name of the broker/exchange platform, e.g. "tinkoff", "finam", "alor"
6+
#' @param api.key character string, the API key required for authentication
7+
#' @param orderId character string, the ID of the order to be cancelled
8+
#' @param clientId character string, the ID of the client account
9+
#' @param board character string, the name of the exchange board, required for some platforms
10+
#' @param live logical, whether to execute the order in a live environment, default is TRUE
11+
#' @param verbose logical, whether to print the HTTP response message, default is TRUE
12+
#' @return character string, the response message from the HTTP request
13+
#' @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.
14+
#' @examples
15+
#' cancelOrder(src = 'Finam',api.key = 'finam_token',orderId = 'otderID',clientId = 'your cliend id')
16+
#' @export
17+
18+
cancelOrder = function(src = '',api.key = '',orderId = '',clientId = '',board = '', live = TRUE,verbose=TRUE)
219
{
3-
url <- paste0("https://hft-api.lykke.com/api/Orders/",OrderID, "/Cancel")
4-
resp <- httr::POST(url,
5-
httr::add_headers(`api-key` = conn$key),
6-
encode = "json")
7-
return(resp)
20+
## choose broker/exchange
21+
if(src == 'tinkoff')
22+
{
23+
url <- "https://invest-public-api.tinkoff.ru/rest/"
24+
endpoint <- "tinkoff.public.invest.api.contract.v1.OrdersService/CancelOrder"
25+
full_url <- paste0(url, endpoint)
26+
body <- list(accountId=clientId,
27+
orderId = orderId)
28+
headers <- c("Authorization" = paste("Bearer", api.key))
29+
response <- POST(full_url, body = body, encode = "json", add_headers(headers))
30+
31+
if(response$status_code==200)
32+
{
33+
json_response <- content(response, "text", encoding = "UTF-8")
34+
data_result <- fromJSON(json_response)[[1]]
35+
return(data_result)
36+
}
37+
if(response$status_code!=200)
38+
if(verbose) return(content(response, as = "parsed"))
39+
}
40+
41+
if(src == 'finam')
42+
{
43+
url = 'https://trade-api.finam.ru'
44+
endpoint = '/api/v1/orders/'
45+
full_url <- paste0(url, endpoint)
46+
47+
body = list(
48+
clientId = clientId,
49+
transactionId = as.integer(orderId))
50+
51+
52+
headers = c('X-Api-Key' = api.key)
53+
response <- DELETE(full_url, query = body, add_headers(headers))
54+
if(response$status_code==200)
55+
{
56+
json_response <- content(response, "text", encoding = "UTF-8")
57+
data_result <- fromJSON(json_response)[[1]]
58+
return(data_result)
59+
}
60+
if(response$status_code!=200)
61+
if(verbose) return(content(response, as = "parsed"))
62+
}
63+
if(src == 'alor')
64+
{
65+
jwt_token = POST(paste0('https://oauth.alor.ru/refresh?token=',api.key))
66+
jwt_token <- fromJSON(content(jwt_token, "text"))$AccessToken
67+
headers <- c("Authorization" = paste0("Bearer ", jwt_token))
68+
69+
full_url = paste0('https://api.alor.ru/commandapi/warptrans/TRADE/v2/client/orders/',orderId,'?portfolio=',clientId,'&exchange=',board)
70+
response <- DELETE(full_url, encode = "json", add_headers(headers))
71+
72+
if(response$status_code==200)
73+
{
74+
data_result <- content(response, "text", encoding = "UTF-8")
75+
return(data_result)
76+
}
77+
if(response$status_code!=200)
78+
if(verbose) return(content(response, as = "parsed"))
79+
}
880
}
81+
82+

R/checkConnection.r

Lines changed: 0 additions & 8 deletions
This file was deleted.

R/convert.time.series.R

Lines changed: 0 additions & 49 deletions
This file was deleted.

R/getAccounts.R

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#' @title Get account information from a brokerage or exchange
2+
#'
3+
#' @description This function retrieves account information from a brokerage or exchange.
4+
#'
5+
#' @param src a character string specifying the brokerage or exchange. Can be one of "tinkoff" or "alor". Default is "tinkoff".
6+
#' @param api.key a character string representing the authorization key for the API.
7+
#' @param verbose a logical value indicating whether to print detailed information about the request/response. Default is FALSE.
8+
#'
9+
#' @return A list object with account information, or an error message if the request fails.
10+
#' @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.
11+
#' @author Vyacheslav Arbuzov
12+
#'
13+
#' @examples
14+
#' # get account information from tinkoff
15+
#' account_info <- getAccounts(src = "Tinkoff", api.key = "your_api_key")
16+
#'
17+
#' # get account information from alor
18+
#' account_info <- getAccounts(src = "Alor", api.key = "your_api_key")
19+
#'
20+
#' @export
21+
22+
getAccounts = function(src='tinkoff',api.key = '', verbose = FALSE)
23+
{
24+
src <- tolower(src)
25+
if(src == 'tinkoff')
26+
{
27+
url <- "https://invest-public-api.tinkoff.ru/rest/"
28+
endpoint <- "tinkoff.public.invest.api.contract.v1.UsersService/GetAccounts"
29+
full_url <- paste0(url, endpoint)
30+
body <- list(instrumentStatus= "INSTRUMENT_STATUS_UNSPECIFIED")
31+
headers <- c("Authorization" = paste("Bearer", api.key))
32+
response <- POST(full_url, body = body, encode = "json", add_headers(headers))
33+
34+
if(response$status_code==200)
35+
{
36+
json_response <- content(response, "text", encoding = "UTF-8")
37+
data_result <- fromJSON(json_response)[[1]]
38+
return(data_result)
39+
}
40+
if(response$status_code!=200)
41+
if(verbose) return(content(response, as = "parsed"))
42+
}
43+
if(src == 'alor')
44+
{
45+
jwt_token = POST(paste0('https://oauth.alor.ru/refresh?token=',api.key))
46+
if(jwt_token$status_code==200)
47+
{
48+
jwt_token <- fromJSON(content(jwt_token, "text"))$AccessToken
49+
jwt_info = jwt_split(jwt_token)
50+
data_result = strsplit(jwt_info$payload$portfolios,' ')[[1]]
51+
return(data_result)
52+
}
53+
if(jwt_token$status_code!=200)
54+
if(verbose) return(content(jwt_token, as = "parsed"))
55+
}
56+
}
57+
58+
59+

R/getBalance.R

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)