Tick-by-tick data corresponding to the data shown in the TWS Time & Sales Window is available starting with TWS v969 and API v973.04. The maximum number of simultaneous tick-by-tick subscriptions allowed for a user is determined by the same formula used to calculate maximum number of market depth subscriptions Limitations.
- The tick type field is case sensitive - it must be BidAsk, Last, AllLast, MidPoint. AllLast has additional trade types such as combos, derivatives, and average price trades which are not included in Last.
- Tick-by-tick data for options is currently only available historically and not in real time.
- Tick-by-tick data for indices is only provided for indices which are on CME.
- Tick-by-tick data is not available for combos.
- No more than 1 tick-by-tick request can be made for the same instrument within 15 seconds.
-
client.reqTickByTickData(19001, ContractSamples.USStockAtSmart(), "Last", 0, false);
client.reqTickByTickData(19002, ContractSamples.USStockAtSmart(), "AllLast", 0, false);
client.reqTickByTickData(19003, ContractSamples.USStockAtSmart(), "BidAsk", 0, true);
client.reqTickByTickData(19004, ContractSamples.EurGbpFx(), "MidPoint", 0, false);
-
client.reqTickByTickData(19001, ContractSamples.USStockAtSmart(), "Last", 0, false);
client.reqTickByTickData(19002, ContractSamples.USStockAtSmart(), "AllLast", 0, false);
client.reqTickByTickData(19003, ContractSamples.USStockAtSmart(), "BidAsk", 0, true);
client.reqTickByTickData(19004, ContractSamples.EurGbpFx(), "MidPoint", 0, false);
-
client.reqTickByTickData(19001, ContractSamples.EuropeanStock(), "Last", 0, False)
client.reqTickByTickData(19002, ContractSamples.EuropeanStock(), "AllLast", 0, False)
client.reqTickByTickData(19003, ContractSamples.EuropeanStock(), "BidAsk", 0, True)
client.reqTickByTickData(19004, ContractSamples.EurGbpFx(), "MidPoint", 0, False)
-
m_pClient->reqTickByTickData(20005, ContractSamples::EuropeanStock(), "Last", 10, false);
m_pClient->reqTickByTickData(20006, ContractSamples::EuropeanStock(), "AllLast", 10, false);
m_pClient->reqTickByTickData(20007, ContractSamples::EuropeanStock(), "BidAsk", 10, false);
m_pClient->reqTickByTickData(20008, ContractSamples::EurGbpFx(), "MidPoint", 10, true);
-
1 self.reqTickByTickData(19001, ContractSamples.EuropeanStock2(),
"Last", 0,
True)
2 self.reqTickByTickData(19002, ContractSamples.EuropeanStock2(),
"AllLast", 0,
False)
3 self.reqTickByTickData(19003, ContractSamples.EuropeanStock2(),
"BidAsk", 0,
True)
4 self.reqTickByTickData(19004, ContractSamples.EurGbpFx(),
"MidPoint", 0,
False)
Depending on the data type chosen in IBApi::EClient::reqTickByTickData, data will be returned to one of the functions IBApi::EWrapper::tickByTickAllLast, IBApi::EWrapper::tickByTickBidAsk, or IBApi::EWrapper::tickByTickMidPoint. Additionally, if a non-zero value is input for the argument numberOfTicks in IBApi::EClient::reqTickByTickData, historical tick data is first returned to one of the functions IBApi::EWrapper::historicalTicksLast, IBApi::EWrapper::historicalTicksBidAsk, or IBApi::EWrapper::historicalTicks, respectively.
-
public void tickByTickBidAsk(int reqId, long time, double bidPrice, double askPrice, decimal bidSize, decimal askSize, TickAttribBidAsk tickAttribBidAsk)
{
Console.WriteLine("Tick-By-Tick. Request Id: {0}, TickType: BidAsk, Time: {1}, BidPrice: {2}, AskPrice: {3}, BidSize: {4}, AskSize: {5}, BidPastLow: {6}, AskPastHigh: {7}",
reqId, Util.UnixSecondsToString(time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(bidPrice), Util.DoubleMaxString(askPrice), Util.DecimalMaxString(bidSize), Util.DecimalMaxString(askSize), tickAttribBidAsk.BidPastLow, tickAttribBidAsk.AskPastHigh);
}
-
@Override
public void tickByTickBidAsk(int reqId, long time, double bidPrice, double askPrice, Decimal bidSize, Decimal askSize,
TickAttribBidAsk tickAttribBidAsk) {
System.out.println(EWrapperMsgGenerator.tickByTickBidAsk(reqId, time, bidPrice, askPrice, bidSize, askSize, tickAttribBidAsk));
}
-
Public Sub tickByTickBidAsk(reqId As Integer, time As Long, bidPrice As Double, askPrice As Double, bidSize As Decimal, askSize As Decimal, tickAttribBidAsk As TickAttribBidAsk) Implements EWrapper.tickByTickBidAsk
Console.WriteLine("Tick-By-Tick. Request Id: {0}, TickType: BidAsk, Time: {1}, BidPrice: {2}, AskPrice: {3}, BidSize: {4}, AskSize: {5}, BidPastLow: {6}, AskPastHigh: {7}",
reqId, Util.UnixSecondsToString(time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(bidPrice), Util.DoubleMaxString(askPrice), Util.DecimalMaxString(bidSize), Util.DecimalMaxString(askSize),
tickAttribBidAsk.BidPastLow, tickAttribBidAsk.AskPastHigh)
End Sub
-
void TestCppClient::tickByTickBidAsk(int reqId, time_t time, double bidPrice, double askPrice, Decimal bidSize, Decimal askSize, const TickAttribBidAsk& tickAttribBidAsk) {
char timeStr[80];
ctime_s(timeStr, sizeof(timeStr), &time);
printf("Tick-By-Tick. ReqId: %d, TickType: BidAsk, Time: %s, BidPrice: %s, AskPrice: %s, BidSize: %s, AskSize: %s, BidPastLow: %d, AskPastHigh: %d\n",
reqId, timeStr, Utils::doubleMaxString(bidPrice).c_str(), Utils::doubleMaxString(askPrice).c_str(), DecimalFunctions::decimalStringToDisplay(bidSize).c_str(), DecimalFunctions::decimalStringToDisplay(askSize).c_str(), tickAttribBidAsk.bidPastLow, tickAttribBidAsk.askPastHigh);
}
-
1 def tickByTickBidAsk(self, reqId: int, time: int, bidPrice: float, askPrice: float,
2 bidSize: Decimal, askSize: Decimal, tickAttribBidAsk: TickAttribBidAsk):
3 super().tickByTickBidAsk(reqId, time, bidPrice, askPrice, bidSize,
4 askSize, tickAttribBidAsk)
5 print(
"BidAsk. ReqId:", reqId,
6 "Time:", datetime.datetime.fromtimestamp(time).strftime(
"%Y%m%d-%H:%M:%S"),
7 "BidPrice:", floatMaxString(bidPrice),
"AskPrice:", floatMaxString(askPrice),
"BidSize:", decimalMaxString(bidSize),
8 "AskSize:", decimalMaxString(askSize),
"BidPastLow:", tickAttribBidAsk.bidPastLow,
"AskPastHigh:", tickAttribBidAsk.askPastHigh)
-
public void tickByTickAllLast(int reqId, int tickType, long time, double price, decimal size, TickAttribLast tickAttribLast, string exchange, string specialConditions)
{
Console.WriteLine("Tick-By-Tick. Request Id: {0}, TickType: {1}, Time: {2}, Price: {3}, Size: {4}, Exchange: {5}, Special Conditions: {6}, PastLimit: {7}, Unreported: {8}",
reqId, tickType == 1 ? "Last" : "AllLast", Util.UnixSecondsToString(time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(price), Util.DecimalMaxString(size), exchange, specialConditions, tickAttribLast.PastLimit, tickAttribLast.Unreported);
}
-
@Override
public void tickByTickAllLast(int reqId, int tickType, long time, double price, Decimal size, TickAttribLast tickAttribLast,
String exchange, String specialConditions) {
System.out.println(EWrapperMsgGenerator.tickByTickAllLast(reqId, tickType, time, price, size, tickAttribLast, exchange, specialConditions));
}
-
Public Sub tickByTickAllLast(reqId As Integer, tickType As Integer, time As Long, price As Double, size As Decimal, tickAttribLast As TickAttribLast, exchange As String, specialConditions As String) Implements EWrapper.tickByTickAllLast
Dim tickTypeStr As String
If tickType = 1 Then
tickTypeStr = "Last"
Else
tickTypeStr = "AllLast"
End If
Console.WriteLine("Tick-By-Tick. Request Id: {0}, TickType: {1}, Time: {2}, Price: {3}, Size: {4}, Exchange: {5}, Special Conditions: {6}, PastLimit: {7}, Unreported: {8}",
reqId, tickTypeStr, Util.UnixSecondsToString(time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(price), Util.DecimalMaxString(size), exchange, specialConditions,
tickAttribLast.PastLimit, tickAttribLast.Unreported)
End Sub
-
void TestCppClient::tickByTickAllLast(int reqId, int tickType, time_t time, double price, Decimal size, const TickAttribLast& tickAttribLast, const std::string& exchange, const std::string& specialConditions) {
char timeStr[80];
ctime_s(timeStr, sizeof(timeStr), &time);
printf("Tick-By-Tick. ReqId: %d, TickType: %s, Time: %s, Price: %s, Size: %s, PastLimit: %d, Unreported: %d, Exchange: %s, SpecialConditions:%s\n",
reqId, (tickType == 1 ? "Last" : "AllLast"), timeStr, Utils::doubleMaxString(price).c_str(), DecimalFunctions::decimalStringToDisplay(size).c_str(), tickAttribLast.pastLimit, tickAttribLast.unreported, exchange.c_str(), specialConditions.c_str());
}
-
1 def tickByTickAllLast(self, reqId: int, tickType: int, time: int, price: float,
2 size: Decimal, tickAtrribLast: TickAttribLast, exchange: str,
3 specialConditions: str):
4 super().tickByTickAllLast(reqId, tickType, time, price, size, tickAtrribLast,
5 exchange, specialConditions)
9 print(
"AllLast.", end=
'')
10 print(
" ReqId:", reqId,
11 "Time:", datetime.datetime.fromtimestamp(time).strftime(
"%Y%m%d-%H:%M:%S"),
12 "Price:", floatMaxString(price),
"Size:", decimalMaxString(size),
"Exch:" , exchange,
13 "Spec Cond:", specialConditions,
"PastLimit:", tickAtrribLast.pastLimit,
"Unreported:", tickAtrribLast.unreported)
- Trade data for non-reportable trades, such as combos and block trades, are included in the 'AllLast' data type available with the real time data feed but are not recorded in the historical database.
-
public void tickByTickMidPoint(int reqId, long time, double midPoint)
{
Console.WriteLine("Tick-By-Tick. Request Id: {0}, TickType: MidPoint, Time: {1}, MidPoint: {2}",
reqId, Util.UnixSecondsToString(time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(midPoint));
}
-
@Override
public void tickByTickMidPoint(int reqId, long time, double midPoint) {
System.out.println(EWrapperMsgGenerator.tickByTickMidPoint(reqId, time, midPoint));
}
-
Public Sub tickByTickMidPoint(reqId As Integer, time As Long, midPoint As Double) Implements EWrapper.tickByTickMidPoint
Console.WriteLine("Tick-By-Tick. Request Id: {0}, TickType: MidPoint, Time: {1}, MidPoint: {2}",
reqId, Util.UnixSecondsToString(time, "yyyyMMdd-HH:mm:ss"), Util.DoubleMaxString(midPoint))
End Sub
-
void TestCppClient::tickByTickMidPoint(int reqId, time_t time, double midPoint) {
char timeStr[80];
ctime_s(timeStr, sizeof(timeStr), &time);
printf("Tick-By-Tick. ReqId: %d, TickType: MidPoint, Time: %s, MidPoint: %s\n", reqId, timeStr, Utils::doubleMaxString(midPoint).c_str());
}
-
2 def tickByTickMidPoint(self, reqId: int, time: int, midPoint: float):
3 super().tickByTickMidPoint(reqId, time, midPoint)
4 print(
"Midpoint. ReqId:", reqId,
5 "Time:", datetime.datetime.fromtimestamp(time).strftime(
"%Y%m%d-%H:%M:%S"),
6 "MidPoint:", floatMaxString(midPoint))
Halted and Unhalted ticks
Effective with TWS 10.15+ and TWS API 10.15+ a new Tick-By-Tick attribute has been introduced. The tick attribute pastLimit is also returned with historical Tick-By-Tick responses. Check Historical Halted and Unhalted ticks section.
- If tick has zero price, zero size and pastLimit flag is set - this is "Halted" tick.
- If tick has zero price, zero size and followed immediately after "Halted" tick - this is "Unhalted" tick.
Canceling Tick-By-Tick Subscriptions
Tick-by-tick subscriptions can be cancelled using the function IBApi::EClient::cancelTickByTickData
-
client.cancelTickByTickData(19001);
client.cancelTickByTickData(19002);
client.cancelTickByTickData(19003);
client.cancelTickByTickData(19004);
-
client.cancelTickByTickData(19001);
client.cancelTickByTickData(19002);
client.cancelTickByTickData(19003);
client.cancelTickByTickData(19004);
-
client.cancelTickByTickData(19001)
client.cancelTickByTickData(19002)
client.cancelTickByTickData(19003)
client.cancelTickByTickData(19004)
-
m_pClient->cancelTickByTickData(20001);
m_pClient->cancelTickByTickData(20002);
m_pClient->cancelTickByTickData(20003);
m_pClient->cancelTickByTickData(20004);
-
1 self.cancelTickByTickData(19001)
2 self.cancelTickByTickData(19002)
3 self.cancelTickByTickData(19003)
4 self.cancelTickByTickData(19004)