README.md

Rusquant

CRAN_Status_Badge CRAN_Downloads CRAN_Ago

Intro

Rusquant is a package for interaction with alternative data, trading API of different exchanges and brokers. Package provides access to market data for storage, analysis, algorithmic trading, strategy backtesting. Also this is data downloader from different data sources starting from close price to order book and tradelog.

Current available brokers - tinkoff.ru, finam.ru, alorbroker.ru. Current available datasources - previous brokers + MOEX, MFD.RU, Poloniex, MarketWatch, Investing, AlgoPack

Supporting rusquant development

If you are interested in supporting the ongoing development and maintenance of rusquant, please consider becoming a sponsor.

Installation

The current release (1.0.5) is available on CRAN, which you can install via:

install.packages("rusquant")

To install the development version (1.0.5), you need to clone the repository and build from source, or run one of:

# lightweight
remotes::install_github("arbuzovv/rusquant")
# or
devtools::install_github("arbuzovv/rusquant")

Getting Started

It is possible to import data from a variety of sources with one rusquant function: getSymbols(). For example:

library(rusquant)
getSymbolList('Finam') # download all available symbols in finam.ru 
getSymbols('LKOH',src='Finam') # default = main market
getSymbols('LKOH',src = 'Finam') # main market
getSymbols.Moex('SBER')

# type period
getSymbols('LKOH',src='Finam',period='day') # day bars - default parameter
getSymbols('LKOH',src='Finam',period='5min') # 5 min bar 
getSymbols('LKOH',src='Finam',period='15min') # 15 min bar
getSymbols.Moex('SBER',period = '1min',from=Sys.Date()-20) # 1 min bar 

Get data from Mfd.ru

getSymbolList('Mfd') # see the availible assets
getSymbols('Сбербанк',src='Mfd')

Get fundamental data from Investing

getEarnings(from = Sys.Date(),to = Sys.Date()+3,country='Belgium')
getEconomic(from = Sys.Date() - 10, to = Sys.Date(), country = "United States")
getIPO(from='2023-01-23',to='2023-01-25')
getDividends(from = Sys.Date(),to = Sys.Date()+2,country = "Australia")
getDividends(from = '2023-08-01',to = '2023-08-05',country = 'United States')

Get microstructure data from AlgoPack

getSymbols.Algopack('SBER',from = '2023-10-24',to='2023-11-04')
getSymbols.Algopack('ROSN',from = '2023-10-24',to='2023-11-04',type = 'obstats')

Live trading using broker account Finam

finam_token = 'mytoken'
finam_account = 'accountid'

#get portfolio info
finam_portfolio = getPortfolio(src = 'Finam',api.key = finam_token,clientId = finam_account)
current_balance = finam_portfolio$equity
finam_universe = data.table(getSymbolList(src = 'Finam',api.key = finam_token))
#change positions
trade_symbol = 'SBER'
last_price = try(tail((getSymbols.Finam(trade_symbol,period = '1min',from=Sys.Date()-2))[,4],1),silent = T)
size_order = 1
trade_side = ifelse(size_order>0,'Buy','Sell')
board = 'TQBR'

myorder = placeOrder(src = 'finam',
                     symbol = trade_symbol,
                     board = board,
                     action = trade_side,
                     totalQuantity = size_order,
                     lmtPrice = as.numeric(last_price),
                     api.key = finam_token,
                     clientId = finam_account)
print(myorder)

my_orders_status = getOrders(src = 'finam',api.key = finam_token,clientId = finam_account)$orders
print(my_orders_status)

Author

Vyacheslav Arbuzov



arbuzovv/rusquant documentation built on Feb. 1, 2024, 6:39 p.m.