Skip to content

arbuzovv/rusquant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

!!! warning!!! in version 1.1.1 new method of auth to algopack, see ?auth method

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.1.1) is available on CRAN, which you can install via:

install.packages("rusquant")

To install the development version (1.1.1), 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

auth(src = "Moex",login = "[email protected]",password = "mypass")
getSymbols.Algopack('SBER',from = '2023-10-24',to='2023-11-04')
getSymbols.Algopack('ROSN',from = '2023-10-24',to='2023-11-04',type = 'obstats')

# open interest for available futures
getSymbols.Algopack(date = '2024-05-10',type = 'oi')

# open interest for Si futures
getSymbols.Algopack(Symbols = 'Si',type = 'oi')

# market concentration for available stocks
#getSymbols.Algopack(date = '2024-05-10',type = 'hi2')

# market concentration for available fx
getSymbols.Algopack(date = '2024-05-10',type = 'hi2',market='fx')

# market concentration for available futures
getSymbols.Algopack(date = '2024-05-10',type = 'hi2',market='fo')

# market concentration for CNYRUB_TOM
getSymbols.Algopack(Symbols = 'CNYRUB_TOM',type = 'hi2',market='fx')

# orderbook data
getOrderbook('SBER', src = 'moex')
getOrderbook('SiH5', src = 'moex',market='forts')

# orderbook data
getOrderbook('SBER', src = 'moex')
getOrderbook('SiH5', src = 'moex',market='forts')

# tradelog data
getTradelog('SBER', src = 'moex')
getTradelog('SiH5', src = 'moex',market='forts')

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