-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first commit * Moved variable definitions to appconfig, async connection, init unused in TorQ * Updated info files with torq and non torq differences, added init function * tidied code/iexfeed/iex.q * Defined new tables where iex data gets sent; trade_iex and quote_iex. Difference is that these tables have both a source and tickerplant timestamp. * Added empty iex tables to database. Updated documentation. Added timer error trap. Removed unnecessary time casting * Minor documentation changes * Minor documentation changes
- Loading branch information
1 parent
e82506d
commit bec9346
Showing
56 changed files
with
218 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
|
||
TorQ Finance Starter Pack v 1.4.0 | ||
TorQ Finance Starter Pack v 1.5.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
app,version,dependency | ||
TorQ Finance Starter Pack,1.4.0,TorQ 2.7.0;kdb 3.0.0.0000.00.00 | ||
TorQ Finance Starter Pack,1.5.0,TorQ 2.7.0;kdb 3.4.2016.05.31 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
discovery:pass | ||
feed:pass | ||
iexfeed:pass | ||
gateway:pass | ||
hdb:pass | ||
housekeeping:pass | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
iexfeed:pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Bespoke Feed config : Finance Starter Pack | ||
|
||
\d .proc | ||
loadprocesscode:1b | ||
|
||
\d .servers | ||
enabled:1b | ||
CONNECTIONS:enlist `tickerplant // Feedhandler connects to the tickerplant | ||
HOPENTIMEOUT:30000 | ||
|
||
\d .iex | ||
main_url:"https://api.iextrading.com" | ||
convert_epoch:{"p"$1970.01.01D+1000000j*x} | ||
reqtype:`both | ||
syms:`CAT`DOG | ||
callback:".u.upd" | ||
quote_suffix:{[sym] "/1.0/stock/",sym,"/quote"} | ||
trade_suffix:{[sym]"/1.0/tops/last?symbols=",sym} | ||
upd:{[t;x] .iex.callbackhandle(.iex.callback;t; value flip delete time from x)} | ||
timerperiod:0D00:00:02.000 | ||
\d . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
\d .iex | ||
|
||
main_url:@[value;`main_url;"https://api.iextrading.com"]; | ||
convert_epoch:@[value;`convert_epoch;{{"p"$1970.01.01D+1000000j*x}}]; | ||
reqtype:@[value;`reqtype;`both]; | ||
syms:@[value;`syms;`CAT`DOG]; | ||
callback:@[value;`callback;".u.upd"]; | ||
callbackhandle:@[value;`callbackhandle;0i]; | ||
callbackconnection:@[value;`callbackconnection;`]; | ||
quote_suffix:@[value;`quote_suffix;{{[sym] "/1.0/stock/",sym,"/quote"}}]; | ||
trade_suffix:@[value;`trade_suffix;{{[sym]"/1.0/tops/last?symbols=",sym}}]; | ||
upd:@[value;`upd;{{[t;x].iex.callbackhandle(.iex.callback;t; value flip x)}}]; | ||
timerperiod:@[value;`timerperiod;0D00:00:02.000]; | ||
|
||
init:{[x] | ||
if[`main_url in key x;.iex.main_url:x `main_url]; | ||
if[`quote_suffix in key x;.iex.quote_suffix:x `quote_suffix]; | ||
if[`trade_suffix in key x;.iex.trade_suffix:x`trade_suffix]; | ||
if[`syms in key x;.iex.syms: upper x`syms]; | ||
if[`reqtype in key x;.iex.reqtype:x`reqtype]; | ||
if[`callbackconnection in key x;.iex.callbackhandle:neg hopen .iex.callbackconnection:x `callbackconnection]; | ||
if[`callbackhandle in key x;.iex.callbackhandle:x `callbackhandle]; | ||
if[`callback in key x;.iex.callback: $[.iex.callbackhandle=0; string @[value;x `callback;{[x;y]x set {[t;x]x}}[x`callback]]; x`callback]]; | ||
if[`upd in key x; .iex.upd:x[`upd]]; | ||
.iex.timer:$[not .iex.reqtype in key .iex.timer_dict;'`timer;.iex.timer_dict .iex.reqtype]; | ||
} | ||
|
||
get_data:{[main_url;suffix] | ||
.Q.hg `$main_url,suffix | ||
} | ||
|
||
get_last_trade:{tab:{[syms] | ||
/ This function can run for multiple securities. | ||
syms:$[1<count syms;"," sv string[upper syms];string[upper syms]]; | ||
/ Construct the GET request | ||
suffix:.iex.trade_suffix[syms]; | ||
/ Parse json response and put into table. Trade data from https://iextrading.com/developer/ | ||
data:.j.k .iex.get_data[.iex.main_url;suffix]; | ||
tab:select sym:`$symbol, price:`float$price, size:`int$size, stop:(count data)#0b, cond:(count data)#`char$(), ex:(count data)#`char$(), srctime:.iex.convert_epoch time from data | ||
}[.iex.syms]; .iex.upd[`trade_iex;tab] | ||
} | ||
|
||
get_quote:{tab:raze {[sym] | ||
sym:string[upper sym]; | ||
suffix:.iex.quote_suffix[sym]; | ||
/ Parse json response and put into table | ||
data: enlist .j.k .iex.get_data[.iex.main_url;suffix]; | ||
select sym:`$symbol, bid: `float$iexBidPrice, ask:`float$iexAskPrice, bsize:`long$iexBidSize, asize:`long$iexAskSize, mode:(count data)#`char$(), ex:(count data)#`char$(), srctime:.iex.convert_epoch latestUpdate from data | ||
}'[.iex.syms,()]; .iex.upd[`quote_iex;tab] | ||
} | ||
|
||
timer_both:{.iex.get_last_trade[];.iex.get_quote[]} | ||
timer_dict:`trade`quote`both!(.iex.get_last_trade;.iex.get_quote;timer_both) | ||
|
||
timer:{ @[$[not .iex.reqtype in key .iex.timer_dict; | ||
{'`$"timer request type not valid: ",string .iex.reqtype}; | ||
.iex.timer_dict[.iex.reqtype]]; | ||
[]; | ||
{.lg.e[`iextimer;"failed to run iex timer function: ",x]}]} | ||
|
||
|
||
\d . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.servers.startup[] | ||
.iex.callbackhandle:neg .servers.gethandlebytype[`tickerplant;`any] | ||
.timer.repeat[.proc.cp[];0Wp;.iex.timerperiod;(`.iex.timer;`);"Publish Feed"]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
quote:([]time:`timestamp$(); sym:`g#`symbol$(); bid:`float$(); ask:`float$(); bsize:`long$(); asize:`long$(); mode:`char$(); ex:`char$()) | ||
trade:([]time:`timestamp$(); sym:`g#`symbol$(); price:`float$(); size:`int$(); stop:`boolean$(); cond:`char$(); ex:`char$()) | ||
quote_iex:([]time:`timestamp$(); sym:`g#`symbol$(); bid:`float$(); ask:`float$(); bsize:`long$(); asize:`long$(); mode:`char$(); ex:`char$(); srctime:`timestamp$()) | ||
trade_iex:([]time:`timestamp$(); sym:`g#`symbol$(); price:`float$(); size:`int$(); stop:`boolean$(); cond:`char$(); ex:`char$(); srctime:`timestamp$()) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# TorQ-IEX | ||
|
||
An example production ready market data capture system, using randomly generated financial data along with live market data from the IEX. This is installed on top of the base TorQ package, and includes a version of [kdb+tick](http://code.kx.com/wsvn/code/kx/kdb+tick). The live market data from the IEX is sent to the ``trade_iex`` and ``quote_iex`` tables within the RDB. | ||
|
||
### Example-Usage | ||
|
||
When the IEX feed is launched in TorQ, ``appconfig/settings/iexfeed.q`` is ran, followed by ``code/iexfeed/iex.q`` and finally ``code/processes/iexfeed.q``. ``appconfig/settings/iexfeed.q`` can be used to change default variables within the ``.iex`` namespace. These default values are set in ``code/iexfeed/iex.q``, if no values have been assigned in ``appconfig/settings/iexfeed.q``. The .iex variables that can be changed are: | ||
|
||
* ``.iex.main_url`` | ||
* Used to decide which API to request data from | ||
* Default value is ``"https://api.iextrading.com"`` | ||
* ``.iex.quote_suffix`` | ||
* Default value is ``{[sym] "/1.0/stock/",sym,"/quote"}`` | ||
* ``.iex.trade_suffix`` | ||
* Default value is ``{[sym] "/1.0/tops/last?symbols=",sym}`` | ||
* ``.iex.syms`` | ||
* This decides the instruments to collect data for | ||
* Default value is `` `CAT`DOG`` | ||
* ``.iex.reqtype`` | ||
* This decides the request type to make. Trade data, quote data or both can be requested | ||
* Default value is `` `both`` | ||
* This can be changed to either `` `quote`` or `` `trade`` | ||
* ``.iex.upd`` | ||
* This is called when either a trade or quote request is made | ||
* It is called with two arguements. The first is the table name, either `` `trade`` or `` `quote``, and the second is the corresponding table | ||
* The default value is ``{[t;x] .iex.callbackhandle(.iex.callback;t; value flip x)}`` | ||
* ``.iex.callback`` | ||
* This is called within the default ``.iex.upd`` function | ||
* The default value is ``.u.upd`` | ||
* If the ``.iex.upd`` function is unchanged, the ``.iex.callback`` function is executed within a port decided by ``.iex.callbackhandle`` | ||
* ``.iex.callbackhandle`` is set in ``code/processes/iexfeed.q``. The discovery service is used to open an asynchronous connection to the tickerplant | ||
|
||
#### .iex.init | ||
|
||
If you wish to use the standalone ``code/iexfeed/iex.q`` script then the ``.iex.init`` function can be called to change the default vaariables described above. This should only be used if not using the TorQ framework. | ||
|
||
When using ``code/iexfeed/iex.q`` outside of the TorQ framework the port in which the ``.iex.callback`` function will be executed in is not set. Thus the ``.iex.init`` function can be used to set two further variables: | ||
|
||
* ``.iex.callbackconnection`` | ||
* These are the server details ``.iex.callback`` function will be executed in | ||
* If not supplied during the init call the message callback will be executed locally `` ` `` | ||
* If ``.iex.callbackconnection`` is supplied a connection handle will be opened and all updates will be sent asynchronously | ||
* ``.iex.callbackhandle`` | ||
* This can also be changed to decide which server the ``.iex.callback`` function will be executed in, using the handle to the server itself | ||
* Default value is ``0i`` | ||
* If both ``.iex.callbackconnection`` and ``.iex.callbackhandle`` are set using ``.iex.init``, ``.iex.callbackhandle`` has precidence | ||
* Messages should be sent asynchronously | ||
|
||
#### Example Function Call | ||
|
||
``.iex.init`` should be called with a dictionary. The keys of the dictionary should be the names of the variables or functions that are being set. The values associated with these keys should be the new variable values. An example of using ``.iex.init`` can be seen below. | ||
|
||
``` | ||
.iex.init (`syms`callbackhandle`callback`reqtype)!(`cat;5i;".u.upd";`both) | ||
``` | ||
|
||
### Raw JSON Data | ||
|
||
The following data is an example of trade and quote data that can be pulled down with the json requests inside the iex.q file. | ||
|
||
##### Raw Trade Data | ||
|
||
Taken from: [most recent Apple trade data](https://api.iextrading.com/1.0/tops/last?symbols=AAPL) | ||
|
||
` [{"symbol":"AAPL","price":178.675,"size":100,"time":1516723026747}] ` | ||
|
||
##### Raw Quote Data | ||
|
||
Taken from: [most recent Apple quote data](https://api.iextrading.com/1.0/stock/aapl/quote) | ||
|
||
` {"symbol":"AAPL","companyName":"Apple Inc.","primaryExchange":"Nasdaq Global Select","sector":"Technology","calculationPrice":"tops","open":177.28,"openTime":1516717800670,"close":177,"closeTime":1516654800146,"high":178.54,"low":176.83,"latestPrice":178.66,"latestSource":"IEX real time price","latestTime":"10:55:27 AM","latestUpdate":1516722927880,"latestVolume":8796961,"iexRealtimePrice":178.66,"iexRealtimeSize":100,"iexLastUpdated":1516722927880,"delayedPrice":178.15,"delayedPriceTime":1516722031057,"previousClose":177,"change":1.66,"changePercent":0.00938,"iexMarketPercent":0.02402,"iexVolume":211303,"avgTotalVolume":25616973,"iexBidPrice":173.39,"iexBidSize":100,"iexAskPrice":179.4,"iexAskSize":200,"marketCap":908853424960,"peRatio":19.42,"week52High":180.1,"week52Low":119.5,"ytdChange":0.027516544757924123} ` | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters