NOTE: Requests without authorization will be met with a HTTP 401 Unauthorized message. Web browsers will generally intercept this message and prompt the user for credentials. The browser will then properly build the Authentication header and send it with the request.
When the user agent wants to send the server authentication credentials it may use the Authorization header. The Authorization header is constructed as follows:Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
Java php jsp R MATLAB Pythonx <- getURL("https://key:secret@tickapi.tickdata.com//stream?COLLECTION_TYPE=COLLECTION_TYPE.FUTURES...");Where key:secret is to be replaced with your username and password. However, if you are have an @ sign in your user id, and cannot use the syntax
getURL("https://tickapi.tickdata.com/....", userpwd="key:secret")where key:secret would be replaced with your user id, password:
getURL("https://tickapi.tickdata.com/....", userpwd="user@domain:my$pecia1Passw0rd")
import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.URL; public class HttpBasicAuth { public static long downloadFileWithAuth(String urlStr, String user, String pass, String outFilePath) { long fileSize = 0l; try { // URL url = new URL ("http://ip:port/download_url"); URL url = new URL(urlStr); String authStr = user + ":" + pass; System.out.println(authStr); byte[] apacheBytes = org.apache.commons.codec.binary.Base64.encodeBase64(authStr.getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setRequestProperty("Authorization", "Basic " + new String(apacheBytes)); File file = new File(outFilePath + "/" + Long.toString(System.currentTimeMillis()) + ".gz"); InputStream in = (InputStream) connection.getInputStream(); OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); for (int b; (b = in.read()) != -1;) { fileSize++; out.write(b); } out.close(); in.close(); } catch (Exception e) { e.printStackTrace(); } return fileSize; } }
<%@page import="java.io.BufferedOutputStream"%> <%@page import="java.io.File"%> <%@page import="java.io.FileOutputStream"%> <%@page import="java.io.InputStream"%> <%@page import="java.io.InputStreamReader"%> <%@page import="java.io.OutputStream"%> <%@page import="java.net.HttpURLConnection"%> <%@page import="java.net.URL"%> <%@page import="java.io.BufferedReader"%> <%@page import="java.util.zip.GZIPInputStream"%> <%@page import="java.util.*,java.text.SimpleDateFormat" %> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8"/> <title> TickAPI® API Visualization Sample </title> <script type="text/javascript" src="https://www.google.com/jsapi"></script> <script type="text/javascript"> google.load('visualization', '1', {packages: ['corechart']}); </script> <% /** USER CREDENTIALS **/ String user = "YOUR_VALUE"; String pass = "YOUR_VALUE"; /** USER CREDENTIALS **/ // Min, Open, Close, Max String symbol = "PG"; String daysBack = "25"; int resultCode =0; String inputSymbol = request.getParameter("symbol"); String inputDays = request.getParameter("daysBack"); String message = ""; if ((inputSymbol != null) && (inputSymbol.length() > 0)) symbol = inputSymbol; if ((inputDays != null) && (inputDays.length() > 0)) daysBack = inputDays; StringBuffer urlStr = new StringBuffer(); Properties prop = new Properties(); urlStr.append("https://tickapi.tickdata.com/stream?"); prop.put("COLLECTION_TYPE" , "COLLECTION_TYPE.US_TED"); prop.put("EXTRACT_TYPE" , "COLLECTOR_SUBTYPE_US_DAILYBAR"); prop.put("SELECTED_FIELDS" , "DATE_FIELD|LOW_PRICE_FIELD|OPEN_PRICE_FIELD|CLOSE_PRICE_FIELD|HIGH_PRICE_FIELD"); prop.put("INCLUDE_HEADER_ROW" , "FALSE"); prop.put("DAYS_BACK" , daysBack); prop.put("REQUESTED_DATA" , symbol); int count=0; for(String key : prop.stringPropertyNames()) { if (count>0) { urlStr.append("&").append(key).append("=").append(prop.getProperty(key)); } else { urlStr.append(key).append("=").append(prop.getProperty(key)); } count++; } out.println("Built request: <p/>"); out.println(urlStr.toString()); %> <h3>Drawing graph for <%=symbol%> for <%=daysBack%> days back.</h3> <script type="text/javascript"> function drawVisualization() { var data = google.visualization.arrayToDataTable([ <% Properties errorProp = new Properties(); try { String errorURLString = "https://tickapi.tickdata.com/help?with=ERROR"; URL errorUrl = new URL(errorURLString); HttpURLConnection errorConnection = (HttpURLConnection) errorUrl.openConnection(); errorConnection.setRequestMethod("GET"); errorConnection.setDoOutput(true); String errorContent = ""; InputStream errorIn = (InputStream) errorConnection.getInputStream(); for (int b; (b = errorIn.read()) != -1;) { errorContent += (char)b; } errorIn.close(); String[] lines = errorContent.split("\n"); for (String current : lines) { String[] values = current.split(","); errorProp.put(values[1],values[0] + " : " + values[2]); } } catch (Exception e) { // Your exception here. } try { // URL url = new URL ("http://ip:port/download_url"); URL url = new URL(urlStr.toString()); String authStr = user + ":" + pass; byte[] apacheBytes = org.apache.commons.codec.binary.Base64.encodeBase64(authStr.getBytes()); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setRequestProperty("Authorization", "Basic " + new String(apacheBytes)); //out.println( connection.getResponseCode()); resultCode = connection.getResponseCode(); if (resultCode == HttpURLConnection.HTTP_OK) { //InputStream in = (InputStream) connection.getInputStream(); BufferedReader in = new BufferedReader(new InputStreamReader( new GZIPInputStream( (InputStream) connection.getInputStream() ))); String content; StringBuffer outstring = new StringBuffer(); while ((content = in.readLine()) != null) { outstring.append("["); String[] values = content.split(","); boolean first = true; for (String value : values) { if (first) outstring.append("'"); outstring.append(value); if (first) outstring.append("'"); outstring.append(","); first = false; } outstring.setLength(outstring.length() -1); outstring.append("],"); } outstring.setLength(outstring.length() -1); out.println(outstring); in.close(); } else { message = (String)errorProp.get(Integer.toString(resultCode)); } } catch (Exception e) { e.printStackTrace(); } // Treat first row as data as well. %> ], true); var options = { legend:'none' }; var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div')); chart.draw(data, options); } google.setOnLoadCallback(drawVisualization); </script> </head> <body> <%=message%> <div id="chart_div" style="width: 900px; height: 500px;"></div> <form action="fun.jsp" method="post"> Single Symbol: <input type=text id=symbol name=symbol><br/> Days Back: <input type=integer id=daysBack name=daysBack> <input type=submit value=refresh> </form> </body> </html>
<?php // Set sandbox (test mode) to true/false. $sandbox = TRUE; $stream = TRUE; // Set TickData API version and credentials. $api_version = '89.0'; $api_endpoint = $sandbox ? 'https://sandbox-tickapi.tickdata.com' : 'https://tickapi.tickdata.com'; $api_method = $stream ? '/stream' : '/download'; $api_username = $sandbox ? 'APIdemo01' : 'LIVE USER NAME'; $api_password = $sandbox ? 'Tickwriteapi2014' : 'LIVE USER PASS'; $request_params = array ( 'COLLECTION_TYPE' => 'COLLECTION_TYPE.US_TED', 'START_DATE' => '12/01/2013', 'END_DATE' => '12/31/2013', 'EXTRACT_TYPE' => 'COLLECTOR_SUBTYPE_US_TICK_WEEKLYBAR', 'REQUESTED_DATA' => '1335|C', 'INCLUDE_HEADER_ROW' => 'true', 'COMPRESSION_TYPE' => 'NONE', 'INCLUDE_EXCLUDED_RECORDS' => 'true', 'NOTIFICATION_EMAIL' => 'user@mail.com' ); // Loop through $request_params array to generate the NVP string. $nvp_string = ''; foreach($request_params as $var=>$val) { $nvp_string .= '&'.$var.'='.$val; } //echo $nvp_string echo '<pre>' ; // Send NVP string to tickdata and store response $curl = curl_init(); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_USERPWD, $api_username . ":" . $api_password); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($curl, CURLOPT_TIMEOUT, 30); curl_setopt($curl, CURLOPT_URL, $api_endpoint . $api_method . "?SRC=PHP" . $nvp_string); //curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); //curl_setopt($curl, CURLOPT_POSTFIELDS, $nvp_string); $result = curl_exec($curl); curl_close($curl); //echo $result ; echo '</pre>' ; ?>
%% TickData API access via MatLab for FUTURES requests request = textscan(... urlread( ... 'https://sandbox-tickapi.tickdata.com/stream', 'Authentication', 'Basic', ... 'Username', '', ... 'password', ' ', ... 'Get', ... [ {'COLLECTION_TYPE','COLLECTION_TYPE.FUTURES'}, ... {'START_DATE','12/01/2013'}, ... {'END_DATE','12/31/2013'}, ... {'OUTPUT_NAMING_CONVENTION','0'}, ... {'DATE_FORMAT','MM/dd/yyyy'}, ... {'EXTRACT_TYPE','COLLECTOR_SUBTYPE_FUT_TICK_TIMEBAR'}, ... {'TIME_FORMAT','HH:mm:ss'}, ... {'REQUESTED_DATA','ES'}, ... {'SELECTED_FIELDS','TICKER_FIELD|DATE_FIELD|TICK_TIME_FIELD|OPEN_PRICE_FIELD|HIGH_PRICE_FIELD|LOW_PRICE_FIELD|CLOSE_PRICE_FIELD|VOLUME_FIELD|VWAP_FIELD'}, ... {'ROLL_METHOD','AUTO_ROLL'}, ... {'OUTPUT_CONTRACT','0'}, ... {'GRANULARITY','10'}, ... {'TIME_UNIT','MINUTES'}, ... {'INCLUDE_HEADER_ROW','TRUE'}, ... {'OUTPUT_TIME_ZONE','America/Chicago'}, ... {'INCLUDE_PIT','FALSE'}, ... {'COMPRESSION_TYPE','NONE'}]), ... ' %s%s%s%f%f%f%f%f%f', ... 'delimiter',',', ... 'HeaderLines',1);