-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathR-TWS-java
More file actions
106 lines (104 loc) · 4.61 KB
/
Copy pathR-TWS-java
File metadata and controls
106 lines (104 loc) · 4.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
https://github.com/rlktradewright/ib-controller/tree/master/resources
http://ibcontroller.sourceforge.net/
http://www.amibroker.com/at/
https://github.com/ib-controller/ib-controller/releases
https://github.com/ib-controller
https://github.com/ib-controller/ib-controller/blob/master/userguide.md
https://groups.yahoo.com/neo/groups/TWSAPI/info
https://github.com/parthasen/ibconnect.go
#http://cran.r-project.org/web/packages/IBrokers/IBrokers.pdf
#http://cran.r-project.org/web/packages/IBrokers/vignettes/RealTime.pdf
#http://cran.r-project.org/web/packages/IBrokers/vignettes/IBrokers.pdf
#http://artax.karlin.mff.cuni.cz/r-help/library/IBrokers/html/00Index.html
#https://www.rmetrics.org/files/Meielisalp2009/Presentations/Ryan.pdf
#http://interactivebrokers.github.io/#
#install.packages("twsInstrument", repos="http://R-Forge.R-project.org")
#install.packages("qmao", repos="http://R-Forge.R-project.org")
#TTR,quantmod,FinancialInstrument
http://rpackages.ianhowson.com/rforge/twsInstrument/man/twsInstrument-package.html
***JAVA-IB API
jar xf unicmacosx_latest.jar
## octo@octo:~$ sudo jar xf /home/octo/IBJts/unixmacosx_latest.jar
cd IBJts
##octo@octo:~$ cd IBJts
java -cp jts.jar:total.2013.jar -Dsun.java2d.noddraw=true -Xmx512M ibgateway.GWClient
##octo@octo:~/IBJts$ sudo java -cp jts.jar:total.2013.jar -Dsun.java2d.noddraw=true -Xmx512M ibgateway.GWClient
***login and PWD to IB
download API http://interactivebrokers.github.io/#
## keep in IBJts folder /home/octo/IBJts
octo@octo:~/IBJts$ sudo jar xf /home/octo/IBJts/twsapi_macunix.971.01.jar
same instruction: https://www.interactivebrokers.com/en/?f=%2Fen%2Fcontrol%2Fstandalone_api.php%3Fbeta%3D1%26amp%3Bos%3Dunix%26amp%3Bib_entity%3D
same instruction: http://ibkb.interactivebrokers.com/video/2222
***
Netbeans:
->new project in NetBeans
->In the Projects area, select Java Application and click Next.
->In the New Java Application window, name your project, choose a location, and uncheck the check box for Create Main Class.
Click Finish.
->To set up Java to use the API, right-click the project you just created, then select Properties.
->From the source category click Add Folder.
->home/octo/IBJts Navigate to the folder where the TWS API is installed.
source\JavaClient\com
samples\Java\apidemo. Click OK.
->Press F6 to run the sample java project.
->When the message says "Project Samplejavacode does not have main class set" select apidemo and click OK.
***R-IB
#https://www.interactivebrokers.com/en/index.php?f=16042
install.packages("IBrokers")
tws <- twsConnect()
id <- reqIds(tws)
reqCurrentTime(tws)# Request The Current TWS Time
isConnected(tws)
serverVersion(tws)
twsConnectionTime(tws)
contract <- twsEquity('RARE')
reqContractDetails(tws,contract)
# retrieve all QQQQ contracts as a list
reqContractDetails(tws, twsOption(local="", right="", symbol="RARE"))
# retrieve only calls
reqContractDetails(tws, twsOption(local="", right="C", symbol="RARE"))
# retrieve only puts
reqContractDetails(tws, twsOption(local="", right="P", symbol="RARE"))
reqMktData(tws,contract)
reqHistory(tws,contract,"1 min")
reqHistoricalData(tws,twsEquity('AAPL'))
reqHistoricalData(tws,twsIndex('NDX',"NASDAQ"))
mean(reqHistoricalData(tws,twsEquity('AAPL'))[,1])
reqRealTimeBars(tws,twsEquity('AAPL'))
reqRealTimeBars(tws,contract)
fh <- file('d://out.dat',open='a')
reqMktData(tws, contract, file=fh)
Sys.sleep(10)
reqHistory(tws, Contract=contract)
reqHistoricalData(tws,contract)
reqMktDepth(tws,contract)
twsSTK(contract)
twsDisconnect(tws)
reqMktData(tws, twsFUT("NDM5","GLOBEX","201505"))
reqMktData(tws, twsFuture("NDM5","GLOBEX","201505"))
reqMktData(tws,
Contract = twsSTK("RARE"),
eventWrapper = eWrapper(TRUE),
timeStamp=NULL)
reqMktData(tws, twsEquity("SBUX"), CALLBACK=NULL, file="D://SBUX.dat")
twsp <- twsConnect(filename="SBUX.dat")
To playback the saved data, call reqMktData again:
reqMktData(twsp)
reqMktData(twsp, playback=0)
twsPortfolioValue(reqAccountUpdates(tws))
reqMktDepth(tws, twsEquity("SBUX"), CALLBACK=NULL, file="D://SBUX.dat")
reqRealTimeBars(tws, twsEquity("SBUX"), C ALLBACK=NULL, file="D://SBUX.dat")
#NDX150508P04240000-SMART-OPT-USD
opt <- twsOption("NDX",expiry="150508", strike="4240", right="P")
reqContractDetails(tws, twsOption(local="", right="P", symbol="INTU"))
twsOption("BFR","150717","16","P")
reqMktData(tws,twsOption("BFR","150717","16","P"))
reqHistoricalData(tws,twsOption("BFR","150717","16","P"))
reqHistoricalData(tws,twsOption("INTU","150717","105","P"))
id <- reqIds(tws)//85
twsConnectionTime(tws)
reqCurrentTime(tws)
isConnected(tws)
serverVersion(tws)//76
contract <- twsEquity('RARE')
reqContractDetails(tws,contract)[[1]]$category