Sections:

1. Connection

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("", "", "")
## [1] 0

2. Configuration

Get symbol and currency data

ttDisconnect()
## NULL
ttConnect("", "", "")
## [1] 0
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

3. Feed history

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 21:00:00
## 2 1.30600 1.30560 1.30596 1.30570    560 2012-05-07 21:01:00
## 3 1.30573 1.30534 1.30570 1.30554    583 2012-05-07 21:02:00
## 4 1.30560 1.30546 1.30554 1.30546    204 2012-05-07 21:03:00
## 5 1.30551 1.30546 1.30546 1.30550    124 2012-05-07 21:04:00
## 6 1.30572 1.30548 1.30550 1.30563    338 2012-05-07 21:05:00
##                    to
## 1 2012-05-07 21:01:00
## 2 2012-05-07 21:02:00
## 3 2012-05-07 21:03:00
## 4 2012-05-07 21:04:00
## 5 2012-05-07 21:05:00
## 6 2012-05-07 21:06:00

Get 10000 bar pairs of EURUSD symbol:

bars = ttBarsQuotes(“EURUSD”)

head(ttBarsQuotes("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 21:01:00 2012-05-07 21:01:00
## 2  1.30570       560 2012-05-07 21:02:00 2012-05-07 21:02:00
## 3  1.30554       583 2012-05-07 21:03:00 2012-05-07 21:03:00
## 4  1.30546       204 2012-05-07 21:04:00 2012-05-07 21:04:00
## 5  1.30550       124 2012-05-07 21:05:00 2012-05-07 21:05:00
## 6  1.30563       338 2012-05-07 21:06:00 2012-05-07 21:06:00

Get quotes

now <-as.POSIXct(Sys.time())
# 300 seconds from present
prevNow <-as.POSIXct(now-(300))

head(ttQuotes("EURUSD", startTime = prevNow, endTime=now))
##       ask     bid          createTime
## 1 1.10601 1.10599 2015-07-08 12:04:47
## 2 1.10601 1.10599 2015-07-08 12:04:47
## 3 1.10601 1.10599 2015-07-08 12:04:47
## 4 1.10600 1.10599 2015-07-08 12:04:47
## 5 1.10600 1.10599 2015-07-08 12:04:48
## 6 1.10600 1.10599 2015-07-08 12:04:48

Get quotes L2

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)
now <-as.POSIXct(Sys.time())
# 1000 seconds from present
prevNow <-as.POSIXct(now-1000)

qt2= ttQuotesLevel2('EURUSD', prevNow, now)
head(qt2)
##   volumeBid volumeAsk priceBid priceAsk          createTime   quoteIndex
## 1   2178000     1e+06  1.10549  1.10550 2015-07-08 11:53:10 1.436367e+12
## 2   4500000     1e+06  1.10548  1.10551 2015-07-08 11:53:10 1.436367e+12
## 3   2678000     1e+06  1.10549  1.10550 2015-07-08 11:53:10 1.436367e+12
## 4   5500000     1e+06  1.10548  1.10551 2015-07-08 11:53:10 1.436367e+12
## 5   2178000     1e+06  1.10549  1.10550 2015-07-08 11:53:10 1.436367e+12
## 6   5000000     1e+06  1.10548  1.10551 2015-07-08 11:53:10 1.436367e+12
##   level
## 1     1
## 2     2
## 3     1
## 4     2
## 5     1
## 6     2

4. Trades/Trade Reports

Get trades of current account

now <-as.POSIXct(Sys.time())
#120 hours = 5 x 24 x 3600 seconds before now
prevNow <-as.POSIXct(now-(5 * 24*3600))


head(ttTradeRecords(prevNow, now))
##  [1] AgentCommission             ClientId                   
##  [3] CloseConversionRate         InitialVolume              
##  [5] Comment                     Commission                 
##  [7] Id                          LeavesQuantity             
##  [9] OpenConversionRate          OrderCreated               
## [11] OrderFillPrice              OrderLastFillAmount        
## [13] OrderModified               PosOpenPrice               
## [15] PositionClosePrice          PositionCloseRequestedPrice
## [17] PositionClosed              PositionLastQuantity       
## [19] PositionLeavesQuantity      PositionModified           
## [21] PositionOpened              PositionQuantity           
## [23] Price                       Quantity                   
## [25] StopLoss                    Swap                       
## [27] Symbol                      TakeProfit                 
## [29] TradeRecordSide             TradeRecordType            
## [31] TradeTransactionReason      TradeTransactionReportType 
## [33] TransactionAmount           TransactionCurrency        
## [35] TransactionTime            
## <0 rows> (or 0-length row.names)

Trades in account:

# head(ttTrades())

All trades

ttConnect("tp.st.soft-fx.eu", "100000", "123321")
## [1] 0
head(ttTradeRecordAll())
##   AgentCommission                                          ClientId
## 1               0                                                  
## 2               0 ManagerOrder-f3e2dfd3-527c-402b-8a6e-fc8f4a1198a0
## 3               0 ManagerOrder-7e0dca55-c44b-44e2-af86-6c329934fe78
## 4               0 ManagerOrder-7f5be08e-01a7-40a2-a494-ee64de8a7d3d
## 5               0 ManagerOrder-6bf551f9-442f-4079-828a-9f05b42236dc
## 6               0 ManagerOrder-050e0848-d4cb-47cd-a8fe-fee4cd5d1d1e
##   CloseConversionRate InitialVolume Comment Commission     Id
## 1                  -1                             0.00 329002
## 2                   1           USD              -5.64 329003
## 3                   1                             0.00 329004
## 4                   1           USD             -22.54 329006
## 5                   1                             0.00 329005
## 6                  -1                             0.00 329008
##   LeavesQuantity OpenConversionRate        OrderCreated OrderFillPrice
## 1          0e+00           -1.00000 2015-06-10 11:20:45             -1
## 2          0e+00            1.12689 2015-06-10 11:22:54             -1
## 3          0e+00            1.12689 2015-06-10 11:22:58             -1
## 4          0e+00            1.12689 2015-06-10 11:28:16             -1
## 5          0e+00            1.12689 2015-06-10 11:28:14             -1
## 6          1e+05            1.12689 2015-06-10 11:34:34             -1
##   OrderLastFillAmount       OrderModified PosOpenPrice PositionClosePrice
## 1                  -1 1970-01-01 00:00:00      0.00000            0.00000
## 2                  -1 1970-01-01 00:00:00      1.12684            1.12689
## 3                  -1 1970-01-01 00:00:00      1.12689            1.12689
## 4                  -1 1970-01-01 00:00:00      1.12689            1.12684
## 5                  -1 1970-01-01 00:00:00      1.12684            1.12684
## 6                  -1 2015-06-10 11:44:22      0.00000            0.00000
##   PositionCloseRequestedPrice      PositionClosed PositionLastQuantity
## 1                           0 1970-01-01 00:00:00                0e+00
## 2                           0 2015-06-10 11:25:23                1e+05
## 3                           0 2015-06-10 11:25:23                0e+00
## 4                           0 2015-06-10 11:28:55                1e+05
## 5                           0 2015-06-10 11:28:55                0e+00
## 6                           0 1970-01-01 00:00:00                0e+00
##   PositionLeavesQuantity PositionModified      PositionOpened
## 1                      0       1970-01-01 1970-01-01 00:00:00
## 2                      0       1970-01-01 2015-06-10 11:22:56
## 3                      0       1970-01-01 2015-06-10 11:22:59
## 4                      0       1970-01-01 2015-06-10 11:28:17
## 5                      0       1970-01-01 2015-06-10 11:28:14
## 6                      0       1970-01-01 1970-01-01 00:00:00
##   PositionQuantity   Price Quantity StopLoss Swap Symbol TakeProfit
## 1            0e+00 0.00000    0e+00        0    0                 0
## 2            1e+05 0.00000    0e+00        0    0 EURUSD          0
## 3            1e+05 0.00000    0e+00        0    0 EURUSD          0
## 4            1e+05 0.00000    0e+00        0    0 EURUSD          0
## 5            1e+05 0.00000    0e+00        0    0 EURUSD          0
## 6            0e+00 1.12689    1e+05        0    0 EURUSD          0
##   TradeRecordSide TradeRecordType TradeTransactionReason
## 1              -1              -1         DealerDecision
## 2            Sell        Position         DealerDecision
## 3             Buy        Position         DealerDecision
## 4             Buy        Position         DealerDecision
## 5            Sell        Position         DealerDecision
## 6             Buy        Position         DealerDecision
##   TradeTransactionReportType TransactionAmount TransactionCurrency
## 1         BalanceTransaction                 0                 USD
## 2             PositionClosed                -5                 USD
## 3             PositionClosed                 0                 USD
## 4             PositionClosed                -5                 USD
## 5             PositionClosed                 0                 USD
## 6              OrderCanceled                 0                 USD
##       TransactionTime
## 1 2015-06-10 11:20:45
## 2 2015-06-10 11:25:23
## 3 2015-06-10 11:25:23
## 4 2015-06-10 11:28:55
## 5 2015-06-10 11:28:55
## 6 2015-06-10 11:44:22