本文整理匯總了C#中StockSharp.InteractiveBrokers.Native.IBSocket.ReadStr方法的典型用法代碼示例。如果您正苦於以下問題:C# IBSocket.ReadStr方法的具體用法?C# IBSocket.ReadStr怎麽用?C# IBSocket.ReadStr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類StockSharp.InteractiveBrokers.Native.IBSocket
的用法示例。
在下文中一共展示了IBSocket.ReadStr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: ReadMyTrade
private void ReadMyTrade(IBSocket socket, ServerVersions version)
{
/* requestId */
if (version >= ServerVersions.V7)
socket.ReadInt();
// http://www.interactivebrokers.com/en/software/api/apiguide/java/execution.htm
var transactionId = socket.ReadInt();
//Handle the 2^31-1 == 0 bug
if (transactionId == int.MaxValue)
transactionId = 0;
//Read Contract Fields
var contractId = version >= ServerVersions.V5 ? socket.ReadInt() : -1;
var secName = socket.ReadStr();
var type = socket.ReadSecurityType();
var expiryDate = socket.ReadExpiry();
var strike = socket.ReadDecimal();
var optionType = socket.ReadOptionType();
var multiplier = version >= ServerVersions.V9 ? socket.ReadMultiplier() : null;
var boardCode = socket.ReadBoardCode();
var currency = socket.ReadCurrency();
var secCode = socket.ReadLocalCode(secName);
var secClass = (version >= ServerVersions.V10) ? socket.ReadStr() : null;
var tradeId = socket.ReadStr();
var time = socket.ReadDateTime("yyyyMMdd HH:mm:ss");
var portfolio = socket.ReadStr();
/* exchange */
socket.ReadStr();
var side = socket.ReadTradeSide();
var volume = socket.ReadDecimal();
var price = socket.ReadDecimal();
var permId = version >= ServerVersions.V2 ? socket.ReadInt() : (int?)null;
var clientId = version >= ServerVersions.V3 ? socket.ReadInt() : (int?)null;
var liquidation = version >= ServerVersions.V4 ? socket.ReadInt() : (int?)null;
var cumulativeQuantity = version >= ServerVersions.V6 ? socket.ReadInt() : (int?)null;
var averagePrice = version >= ServerVersions.V6 ? socket.ReadDecimal() : (decimal?)null;
var orderRef = version >= ServerVersions.V8 ? socket.ReadStr() : null;
var evRule = version >= ServerVersions.V9 ? socket.ReadStr() : null;
var evMultiplier = version >= ServerVersions.V9 ? socket.ReadDecimal() : (decimal?)null;
var secId = new SecurityId
{
SecurityCode = secCode,
BoardCode = GetBoardCode(boardCode),
InteractiveBrokers = contractId,
};
SendOutMessage(new SecurityMessage
{
SecurityId = secId,
Name = secName,
SecurityType = type,
ExpiryDate = expiryDate,
Strike = strike,
OptionType = optionType,
Currency = currency,
Multiplier = multiplier ?? 0,
Class = secClass
});
// заявка была создана руками
if (transactionId == 0)
return;
_secIdByTradeIds[tradeId] = secId;
var execMsg = new ExecutionMessage
{
ExecutionType = ExecutionTypes.Transaction,
OriginalTransactionId = transactionId,
TradeStringId = tradeId,
OriginSide = side,
TradePrice = price,
TradeVolume = volume,
PortfolioName = portfolio,
ServerTime = time,
SecurityId = secId,
HasTradeInfo = true,
};
if (permId != null)
execMsg.SetPermId(permId.Value);
if (clientId != null)
execMsg.SetClientId(clientId.Value);
if (liquidation != null)
execMsg.SetLiquidation(liquidation.Value);
if (cumulativeQuantity != null)
execMsg.SetCumulativeQuantity(cumulativeQuantity.Value);
if (averagePrice != null)
execMsg.SetAveragePrice(averagePrice.Value);
//.........這裏部分代碼省略.........
示例2: ReadCommissionReport
private void ReadCommissionReport(IBSocket socket)
{
var tradeId = socket.ReadStr();
var value = socket.ReadDecimal();
var currency = socket.ReadCurrency();
var pnl = socket.ReadNullDecimal();
var yield = socket.ReadNullDecimal();
var redemptionDate = socket.ReadNullDateTime("yyyyMMdd");
var secId = _secIdByTradeIds.TryGetValue2(tradeId);
if (secId == null)
return;
// TODO
//SendOutMessage(new ExecutionMessage
//{
// ExecutionType = ExecutionTypes.Trade,
// TradeStringId = tradeId,
// Commission = value,
// SecurityId = secId.Value,
//});
}
示例3: OnProcessResponse
private bool OnProcessResponse(IBSocket socket)
{
var str = socket.ReadStr(false);
if (str.IsEmpty())
{
socket.AddErrorLog(LocalizedStrings.Str2524);
return false;
}
var message = (ResponseMessages)str.To<int>();
socket.AddDebugLog("Msg: {0}", message);
if (message == ResponseMessages.Error)
return false;
var version = (ServerVersions)socket.ReadInt();
switch (message)
{
case ResponseMessages.CurrentTime:
{
// http://www.interactivebrokers.com/en/software/api/apiguide/java/currenttime.htm
var time = socket.ReadLongDateTime();
OnProcessTimeShift(TimeHelper.NowWithOffset - time);
break;
}
case ResponseMessages.ErrorMessage:
{
if (version < ServerVersions.V2)
{
OnProcessMarketDataError(socket.ReadStr());
}
else
{
var id = socket.ReadInt();
var code = socket.ReadInt();
var msg = socket.ReadStr();
socket.AddInfoLog(() => msg);
if (id == -1)
break;
switch ((NotifyCodes)code)
{
case NotifyCodes.OrderCancelled:
{
OnProcessOrderCancelled(id);
break;
}
case NotifyCodes.OrderCannotTransmit:
case NotifyCodes.OrderCannotTransmitId:
case NotifyCodes.OrderCannotTransmitIncomplete:
case NotifyCodes.OrderDuplicateId:
case NotifyCodes.OrderFilled:
case NotifyCodes.OrderNotMatchPrev:
case NotifyCodes.OrderPriceOutOfRange:
case NotifyCodes.OrderSubmitFailed:
case NotifyCodes.OrderVolumeTooSmall:
case NotifyCodes.Rejected:
{
OnProcessOrderError(id, msg);
break;
}
case NotifyCodes.SecurityNoDefinition:
OnProcessSecurityLookupNoFound(id);
break;
default:
OnProcessMarketDataError(LocalizedStrings.Str2525Params.Put(msg, id, code));
break;
}
}
break;
}
case ResponseMessages.VerifyMessageApi:
{
/*int version =*/
socket.ReadInt();
/*var apiData = */
socket.ReadStr();
//eWrapper().verifyMessageAPI(apiData);
break;
}
case ResponseMessages.VerifyCompleted:
{
/*int version =*/
socket.ReadInt();
var isSuccessfulStr = socket.ReadStr();
var isSuccessful = "true".CompareIgnoreCase(isSuccessfulStr);
/*var errorText = */
socket.ReadStr();
if (isSuccessful)
{
//.........這裏部分代碼省略.........
示例4: ReadManagedAccounts
private void ReadManagedAccounts(IBSocket socket)
{
var names = socket.ReadStr().Split(',');
//managedAccounts(accountsList);
names.ForEach(pf => SendOutMessage(new PortfolioMessage { PortfolioName = pf }));
}
示例5: ReadPortfolio
private void ReadPortfolio(IBSocket socket, ServerVersions version)
{
var name = socket.ReadStr();
var value = socket.ReadStr();
var currency = socket.ReadStr();
var port = version >= ServerVersions.V2 ? socket.ReadStr() : null;
if (port == null || currency == "BASE")
return;
var pfMsg = this.CreatePortfolioChangeMessage(port);
switch (name)
{
case "CashBalance":
pfMsg.Add(PositionChangeTypes.CurrentValue, value.To<decimal>());
break;
case "Currency":
pfMsg.Add(PositionChangeTypes.Currency, currency.To<CurrencyTypes>());
break;
case "RealizedPnL":
pfMsg.Add(PositionChangeTypes.RealizedPnL, value.To<decimal>());
break;
case "UnrealizedPnL":
pfMsg.Add(PositionChangeTypes.UnrealizedPnL, value.To<decimal>());
break;
case "NetLiquidation":
pfMsg.Add(PositionChangeTypes.CurrentPrice, value.To<decimal>());
break;
case "Leverage-S":
pfMsg.Add(PositionChangeTypes.Leverage, value.To<decimal>());
break;
default:
var info = pfMsg.ExtensionInfo = new Dictionary<object, object>();
if (currency.IsEmpty())
info[name] = value;
else
{
info[name] = new Currency
{
Type = currency.To<CurrencyTypes>(),
Value = value.To<decimal>(),
};
}
break;
}
SendOutMessage(pfMsg);
}
示例6: ReadPortfolioUpdateTime
private void ReadPortfolioUpdateTime(IBSocket socket)
{
/*var timeStamp = */socket.ReadStr();
//updateAccountTime(timeStamp);
}
示例7: ReadNewsBulletins
private void ReadNewsBulletins(IBSocket socket)
{
var newsId = socket.ReadInt();
var newsType = (ExchangeNewsTypes)socket.ReadInt();
var newsMessage = socket.ReadStr();
var originatingExch = socket.ReadBoardCode();
SendOutMessage(new NewsMessage
{
Id = newsId.To<string>(),
BoardCode = originatingExch,
Headline = newsMessage,
ExtensionInfo = new Dictionary<object, object> { { "Type", newsType } },
ServerTime = this.CurrentTime.Convert(TimeHelper.Est)
});
}
示例8: ReadPortfolioName
private void ReadPortfolioName(IBSocket socket)
{
/*var str = */socket.ReadStr();
//return str.IsEmpty() ? null : str;
}
示例9: ReadSecurityInfo
private void ReadSecurityInfo(IBSocket socket, ServerVersions version)
{
var requestId = version >= ServerVersions.V3 ? socket.ReadInt() : -1;
var secName = socket.ReadStr();
var type = socket.ReadSecurityType();
var expiryDate = socket.ReadExpiry();
var strike = socket.ReadDecimal();
var optionType = socket.ReadOptionType();
var boardCode = socket.ReadBoardCode();
var currency = socket.ReadCurrency();
var secCode = version >= ServerVersions.V2 ? socket.ReadLocalCode(secName) : null;
var marketName = socket.ReadStr();
var secClass = socket.ReadStr();
var contractId = socket.ReadInt();
var priceStep = socket.ReadDecimal();
var multiplier = socket.ReadMultiplier();
var orderTypes = socket.ReadStr();
var validExchanges = socket.ReadStr();
var priceMagnifier = version >= ServerVersions.V2 ? socket.ReadInt() : (int?)null;
var underlyingSecurityNativeId = version >= ServerVersions.V4 ? socket.ReadInt() : (int?)null;
var name = version >= ServerVersions.V4 ? socket.ReadStr() : null;
var routingExchange = version >= ServerVersions.V4 ? socket.ReadBoardCode() : null;
var contractMonth = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var industry = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var category = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var subCategory = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var timeZoneId = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var tradingHours = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var liquidHours = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var evRule = version >= ServerVersions.V8 ? socket.ReadStr() : null;
var evMultiplier = version >= ServerVersions.V8 ? socket.ReadDecimal() : (decimal?)null;
var secId = new SecurityId
{
SecurityCode = secCode,
BoardCode = GetBoardCode(boardCode),
InteractiveBrokers = contractId,
};
if (version >= ServerVersions.V7)
socket.ReadSecurityId(secId);
var secMsg = new SecurityMessage
{
SecurityId = secId,
Name = secName,
SecurityType = type,
ExpiryDate = expiryDate,
Strike = strike,
OptionType = optionType,
Currency = currency,
Multiplier = multiplier ?? 0,
Class = secClass,
OriginalTransactionId = requestId,
PriceStep = priceStep,
};
secMsg.SetMarketName(marketName);
secMsg.SetOrderTypes(orderTypes);
secMsg.SetValidExchanges(validExchanges);
if (priceMagnifier != null)
secMsg.SetPriceMagnifier(priceMagnifier.Value);
if (!routingExchange.IsEmpty())
secMsg.SetRoutingBoard(routingExchange);
if (contractMonth != null)
secMsg.SetContractMonth(contractMonth);
if (industry != null)
secMsg.SetIndustry(industry);
if (category != null)
secMsg.SetCategory(category);
if (subCategory != null)
secMsg.SetSubCategory(subCategory);
if (timeZoneId != null)
secMsg.SetTimeZoneId(timeZoneId);
if (tradingHours != null)
secMsg.SetTradingHours(tradingHours);
if (liquidHours != null)
secMsg.SetLiquidHours(liquidHours);
if (evRule != null)
secMsg.SetEvRule(evRule);
if (evMultiplier != null)
secMsg.SetEvMultiplier(evMultiplier.Value);
// TODO
//if (underlyingSecurityNativeId != null)
// ProcessSecurityAction(null, SecurityIdGenerator.GenerateId(underlyingSecurityNativeId.Value.To<string>(), exchangeBoard), underSec => security.UnderlyingSecurityId = underSec.Id);
SendOutMessage(secMsg);
//.........這裏部分代碼省略.........
示例10: ReadBondInfo
private void ReadBondInfo(IBSocket socket, ServerVersions version)
{
var requestId = version >= ServerVersions.V3 ? socket.ReadInt() : -1;
var secCode = socket.ReadStr();
var type = socket.ReadSecurityType();
var cusip = socket.ReadStr();
var coupon = socket.ReadDecimal();
var maturity = socket.ReadStr();
var issueDate = socket.ReadStr();
var ratings = socket.ReadStr();
var bondType = socket.ReadStr();
var couponType = socket.ReadStr();
var convertible = socket.ReadBool();
var callable = socket.ReadBool();
var putable = socket.ReadBool();
var description = socket.ReadStr();
var boardCode = socket.ReadBoardCode();
var currency = socket.ReadCurrency();
var marketName = socket.ReadStr();
var secClass = socket.ReadStr();
var contractId = socket.ReadInt();
var priceStep = socket.ReadDecimal();
var orderTypes = socket.ReadStr();
var validExchanges = socket.ReadStr();
var nextOptionDate = version >= ServerVersions.V2 ? socket.ReadStr() : null;
var nextOptionType = version >= ServerVersions.V2 ? socket.ReadStr() : null;
var nextOptionPartial = version >= ServerVersions.V2 ? socket.ReadBool() : (bool?)null;
var notes = version >= ServerVersions.V2 ? socket.ReadStr() : null;
var name = version >= ServerVersions.V4 ? socket.ReadStr() : null;
var evRule = version >= ServerVersions.V6 ? socket.ReadStr() : null;
var evMultiplier = version >= ServerVersions.V6 ? socket.ReadDecimal() : (decimal?)null;
var secId = new SecurityId
{
SecurityCode = secCode,
BoardCode = GetBoardCode(boardCode),
InteractiveBrokers = contractId,
};
if (version >= ServerVersions.V5)
socket.ReadSecurityId(secId);
var secMsg = new SecurityMessage
{
SecurityId = secId,
//Name = secName,
SecurityType = type,
Currency = currency,
Class = secClass,
PriceStep = priceStep,
};
secMsg.SetMarketName(marketName);
secMsg.SetOrderTypes(orderTypes);
secMsg.SetValidExchanges(validExchanges);
// TODO
//s.SetBondCusip(cusip);
//s.SetCoupon(coupon);
//s.SetMaturity(maturity);
//s.SetIssueDate(issueDate);
//s.SetRatings(ratings);
//s.SetBondType(bondType);
//s.SetCouponType(couponType);
//s.SetConvertible(convertible);
//s.SetCallable(callable);
//s.SetPutable(putable);
//s.SetDescription(description);
//if (nextOptionDate != null)
// s.SetNextOptionDate(nextOptionDate);
//if (nextOptionType != null)
// s.SetNextOptionType(nextOptionType);
//if (nextOptionPartial != null)
// s.SetNextOptionPartial(nextOptionPartial.Value);
//if (notes != null)
// s.SetNotes(notes);
if (evRule != null)
secMsg.SetEvRule(evRule);
if (evMultiplier != null)
secMsg.SetEvMultiplier(evMultiplier.Value);
SendOutMessage(secMsg);
}
示例11: ReadScannerData
private void ReadScannerData(IBSocket socket, ServerVersions version)
{
var requestId = socket.ReadInt();
var count = socket.ReadInt();
var tmp = Enumerable
.Range(0, count)
.Select(s =>
{
var rank = socket.ReadInt();
var contractId = version >= ServerVersions.V3 ? socket.ReadInt() : -1;
var secName = socket.ReadStr();
var type = socket.ReadSecurityType();
var expiryDate = socket.ReadExpiry();
var strike = socket.ReadDecimal();
var optionType = socket.ReadOptionType();
var boardCode = socket.ReadBoardCode();
var currency = socket.ReadCurrency();
var secCode = socket.ReadLocalCode(secName);
var marketName = socket.ReadStr();
var secClass = socket.ReadStr();
var distance = socket.ReadStr();
var benchmark = socket.ReadStr();
var projection = socket.ReadStr();
var legs = version >= ServerVersions.V2 ? socket.ReadStr() : null;
return new
{
Rank = rank,
ContractId = contractId,
SecName = secName,
SecCode = secCode,
Type = type,
ExpiryDate = expiryDate,
Strike = strike,
OptionType = optionType,
BoardCode = boardCode,
Currency = currency,
MarketName = marketName,
SecClass = secClass,
Distance = distance,
Benchmark = benchmark,
Projection = projection,
Legs = legs,
};
})
.ToArray();
var results = tmp.Select(t =>
{
var secId = new SecurityId
{
SecurityCode = t.SecCode,
BoardCode = GetBoardCode(t.BoardCode),
InteractiveBrokers = t.ContractId,
};
SendOutMessage(new SecurityMessage
{
SecurityId = secId,
Name = t.SecName,
SecurityType = t.Type,
ExpiryDate = t.ExpiryDate,
Strike = t.Strike,
OptionType = t.OptionType,
Currency = t.Currency,
Class = t.SecClass
});
var result = new ScannerResult
{
Rank = t.Rank,
SecurityId = secId,
Distance = t.Distance,
Benchmark = t.Benchmark,
Projection = t.Projection,
Legs = t.Legs
};
return result;
}).ToArray();
SendOutMessage(new ScannerResultMessage
{
Results = results,
OriginalTransactionId = requestId,
});
}
示例12: ReadTickEfp
private void ReadTickEfp(IBSocket socket)
{
var requestId = socket.ReadInt();
var fieldType = (FieldTypes)socket.ReadInt();
var basisPoints = socket.ReadDecimal();
var formattedBasisPoints = socket.ReadStr();
var impliedFuturesPrice = socket.ReadDecimal();
var holdDays = socket.ReadInt();
var futureExpiry = socket.ReadStr();
var dividendImpact = socket.ReadDecimal();
var dividendsToExpiry = socket.ReadDecimal();
//tickEfp(requestId, fieldType, basisPoints, formattedBasisPoints, impliedFuturesPrice,
// holdDays, futureExpiry, dividendImpact, dividendsToExpiry);
var l1Msg = GetLevel1Message(requestId)
.TryAdd(Level1Fields.StepPrice, basisPoints)
.TryAdd(Level1Fields.Yield, dividendsToExpiry);
SendOutMessage(l1Msg);
}
示例13: ReadTickString
private void ReadTickString(IBSocket socket)
{
var requestId = socket.ReadInt();
var field = (FieldTypes)socket.ReadInt();
var valueRenamed = socket.ReadStr();
//GetLevel1Message(requestId);
//tickString(requestId, fieldType, valueRenamed);
}
示例14: ReadPosition
private void ReadPosition(IBSocket socket, ServerVersions version)
{
var account = socket.ReadStr();
var contractId = socket.ReadInt();
var secName = socket.ReadStr();
var type = socket.ReadSecurityType();
var expiryDate = socket.ReadExpiry();
var strike = socket.ReadDecimal();
var optionType = socket.ReadOptionType();
var multiplier = socket.ReadMultiplier();
var boardCode = socket.ReadBoardCode();
var currency = socket.ReadCurrency();
var secCode = socket.ReadLocalCode(secName);
var secClass = (version >= ServerVersions.V2) ? socket.ReadStr() : null;
var pos = socket.ReadDecimal();
var avgCost = 0m;
if (version >= ServerVersions.V3)
avgCost = socket.ReadDecimal();
var secId = new SecurityId
{
SecurityCode = secCode,
BoardCode = GetBoardCode(boardCode),
InteractiveBrokers = contractId,
};
SendOutMessage(new SecurityMessage
{
SecurityId = secId,
Name = secName,
SecurityType = type,
ExpiryDate = expiryDate,
Strike = strike,
OptionType = optionType,
Currency = currency,
Multiplier = multiplier ?? 0,
Class = secClass
});
SendOutMessage(this
.CreatePositionChangeMessage(account, secId)
.Add(PositionChangeTypes.CurrentValue, pos)
.Add(PositionChangeTypes.AveragePrice, avgCost));
}
示例15: ReadHistoricalData
private void ReadHistoricalData(IBSocket socket, ServerVersions version)
{
var requestId = socket.ReadInt();
if (version >= ServerVersions.V2)
{
//Read Start Date String
/*String startDateStr = */
socket.ReadStr();
/*String endDateStr = */
socket.ReadStr();
//completedIndicator += ("-" + startDateStr + "-" + endDateStr);
}
var secId = GetSecurityId(requestId);
var itemCount = socket.ReadInt();
for (var i = 0; i < itemCount; i++)
{
//Comes in as seconds
//2 - dates are returned as a long integer specifying the number of seconds since 1/1/1970 GMT.
var time = socket.ReadLongDateTime();
var open = socket.ReadDecimal();
var high = socket.ReadDecimal();
var low = socket.ReadDecimal();
var close = socket.ReadDecimal();
var volume = socket.ReadInt();
var wap = socket.ReadDecimal();
/* hasGaps */
socket.ReadStr().To<bool>();
var barCount = -1;
if (version >= ServerVersions.V3)
barCount = socket.ReadInt();
SendOutMessage(new TimeFrameCandleMessage
{
OpenPrice = open,
HighPrice = high,
LowPrice = low,
ClosePrice = close,
TotalVolume = volume,
OpenTime = time,
TotalTicks = barCount,
SecurityId = secId,
OriginalTransactionId = requestId,
State = CandleStates.Finished,
IsFinished = i == (itemCount - 1)
});
}
}