Connect to TT Demo server: ttConnect()

options(warn=-1)
require(rClr)
## Loading required package: rClr
## Loading the dynamic library for Microsoft .NET runtime...
## Loaded Common Language Runtime version 4.0.30319.34209
require(FdkRLib)
## Loading required package: FdkRLib
ttConnect()
## Loading required package: jsonlite
## 
## Attaching package: 'jsonlite'
## 
## The following object is masked from 'package:utils':
## 
##     View
## [1] 0

Get 10000 bars of EURUSD symbol:

head(ttBars(“EURUSD”))

head(ttBars("EURUSD"))
##      high     low    open   close volume                from
## 1 1.30601 1.30568 1.30591 1.30597    936 2012-05-07 23:00:00
## 2 1.30600 1.30560 1.30596 1.30570    560 2012-05-07 23:01:00
## 3 1.30573 1.30534 1.30570 1.30554    583 2012-05-07 23:02:00
## 4 1.30560 1.30546 1.30554 1.30546    204 2012-05-07 23:03:00
## 5 1.30551 1.30546 1.30546 1.30550    124 2012-05-07 23:04:00
## 6 1.30572 1.30548 1.30550 1.30563    338 2012-05-07 23:05:00
##                    to
## 1 2012-05-07 23:01:00
## 2 2012-05-07 23:02:00
## 3 2012-05-07 23:03:00
## 4 2012-05-07 23:04:00
## 5 2012-05-07 23:05:00
## 6 2012-05-07 23:06:00

Get 10000 bar pairs of EURUSD symbol:

bars = ttBarPairs(“EURUSD”)

head(ttBarPairs("EURUSD"))
##   askHigh  askLow askopen askClose askVolume bidHigh  bidLow bidOpen
## 1 1.30602 1.30573 1.30593  1.30599       936 1.30601 1.30568 1.30591
## 2 1.30603 1.30566 1.30598  1.30575       560 1.30600 1.30560 1.30596
## 3 1.30578 1.30540 1.30575  1.30558       583 1.30573 1.30534 1.30570
## 4 1.30565 1.30550 1.30558  1.30550       204 1.30560 1.30546 1.30554
## 5 1.30556 1.30550 1.30550  1.30555       124 1.30551 1.30546 1.30546
## 6 1.30574 1.30554 1.30555  1.30567       338 1.30572 1.30548 1.30550
##   bidClose bidVolume                from                  to
## 1  1.30597       936 2012-05-07 23:01:00 2012-05-07 23:01:00
## 2  1.30570       560 2012-05-07 23:02:00 2012-05-07 23:02:00
## 3  1.30554       583 2012-05-07 23:03:00 2012-05-07 23:03:00
## 4  1.30546       204 2012-05-07 23:04:00 2012-05-07 23:04:00
## 5  1.30550       124 2012-05-07 23:05:00 2012-05-07 23:05:00
## 6  1.30563       338 2012-05-07 23:06:00 2012-05-07 23:06:00

Get quotes

now <-as.POSIXct(Sys.time())
prevNow <-as.POSIXct(Sys.time()-1000)
head(ttQuotes("EURUSD", startTime= prevNow, endTime = now))
##       ask     bid          createTime
## 1 1.14066 1.14062 2015-06-18 10:27:41
## 2 1.14066 1.14062 2015-06-18 10:27:42
## 3 1.14066 1.14062 2015-06-18 10:27:42
## 4 1.14064 1.14062 2015-06-18 10:27:42
## 5 1.14064 1.14062 2015-06-18 10:27:42
## 6 1.14063 1.14061 2015-06-18 10:27:42

Get trades of current account

head(ttTrades())
##  [1] agentComission     tradeClientOrderId tradeComment      
##  [4] created            expiration         initialVolume     
##  [7] isLimitOrder       isPendingOrder     isPosition        
## [10] isStopOrder        modified           orderId           
## [13] price              profit             side              
## [16] stopLoss           swap               takeProfit        
## [19] type               volume            
## <0 rows> (or 0-length row.names)

Get quotes L2

now <-as.POSIXct(Sys.time())
prevNow <-as.POSIXct(Sys.time()-1000)

qt2= ttQuotesLevel2('EURUSD', prevNow, now)
head(qt2)
##   volumeBid volumeAsk priceBid priceAsk          createTime quoteIndex
## 1      1000   2000000  1.13831  1.14054 2015-06-18 10:27:47        217
## 2      7000   4302000  1.13822  1.14055 2015-06-18 10:27:47        217
## 3      1000   2000000  1.13831  1.14054 2015-06-18 10:27:47        432
## 4      7000   4302000  1.13822  1.14055 2015-06-18 10:27:47        432
## 5      1000   2500000  1.13831  1.14054 2015-06-18 10:27:47        701
## 6      7000   4302000  1.13822  1.14055 2015-06-18 10:27:47        701

Get symbol and currency data

head(ttGetSymbolData())
##   comission contractMultiplier currency limitsComission maxTradeVolume
## 1     0.005              1e+05      EUR           0.005          1e+08
## 2     0.005              1e+05      EUR           0.005          1e+08
## 3     0.005              1e+05      USD           0.005          1e+08
## 4     0.005              1e+05      USD           0.005          1e+08
## 5     0.005              1e+05      EUR           0.005          1e+08
## 6     0.005              1e+03      CAD           0.005          1e+08
##   minTradeVolume   name precision roundLog settlementCurrency swapSizeLong
## 1           1000 EURUSD         5    1e+05                USD     -1.96000
## 2           1000 EURAUD         5    1e+05                AUD    -13.84416
## 3           1000 USDCAD         5    1e+05                CAD     -3.81481
## 4           1000 USDCHF         5    1e+05                CHF      0.98148
## 5           1000 EURCAD         5    1e+05                CAD     -6.02469
## 6           1000 CADJPY         3    1e+05                JPY      0.79012
##   swapSizeShort
## 1       0.27000
## 2       3.97403
## 3       0.83951
## 4      -3.88889
## 5       1.53086
## 6      -3.43210
head(ttGetCurrencyData())
##   currency description precision sortOrder
## 1      ASX                     5        25
## 2      AUD                     5         1
## 3      CAC                     5        26
## 4      CAD                     5         2
## 5      CHF                     5         3
## 6      CNH                     5         4

Get trade records data

now <-as.POSIXct(Sys.time())
prevNow <-as.POSIXct(Sys.time()-(120*3600)) 

head(ttTradeRecords(prevNow, now))
##   AgentCommission                                  ClientId
## 1               0 ES3{627A4C0A-1209-40C7-AED9-37370055A9CE}
## 2               0 ES3{0A278256-C29B-4176-B39F-65889A8263BD}
##   CloseConversionRate InitialVolume Comment Commission       Id
## 1                   1           USD              -0.56 38212022
## 2                   1           USD              -0.56 38212023
##   LeavesQuantity OpenConversionRate        OrderCreated OrderFillPrice
## 1              0            1.11670 2015-05-22 09:14:14             -1
## 2              0            1.11723 2015-05-22 09:32:42             -1
##   OrderLastFillAmount OrderModified PosOpenPrice PositionClosePrice
## 1                  -1    1970-01-01      1.11670            1.12484
## 2                  -1    1970-01-01      1.11723            1.12481
##   PositionCloseRequestedPrice      PositionClosed PositionLastQuantity
## 1                           0 2015-06-15 14:53:00                10000
## 2                           0 2015-06-15 14:53:07                10000
##   PositionLeavesQuantity PositionModified      PositionOpened
## 1                      0       1970-01-01 2015-05-22 11:39:22
## 2                      0       1970-01-01 2015-05-22 09:33:13
##   PositionQuantity Price Quantity StopLoss  Swap Symbol TakeProfit
## 1            10000     0        0        0 -4.56 EURUSD          0
## 2            10000     0        0        0 -4.56 EURUSD          0
##   TradeRecordSide TradeRecordType TradeTransactionReason
## 1             Buy        Position          ClientRequest
## 2             Buy        Position          ClientRequest
##   TradeTransactionReportType TransactionAmount TransactionCurrency
## 1             PositionClosed             76.28                 USD
## 2             PositionClosed             70.68                 USD
##       TransactionTime
## 1 2015-06-15 14:53:00
## 2 2015-06-15 14:53:07
# Can take a long (very long) time to get all orders.
#head(ttTradeRecordAll())