算起来,这个系列的文章算是鸽了很久,休息这两天,正好填一下这个系列的坑。那么接下来这几篇文章就重点介绍一下TWS API中最重要的几个类。正如之前提过,TWS的提交机制,主要消息需要通过EWrapper来向TWS进行提交订单、账户、交易信息提交等工作。所以,我想了一下,就需要重点说明和介绍我们的EWrapper类。
EWrapper是什么
首先看一眼IB对于这个类的介绍
This interface’s methods are used by the TWS/Gateway to communicate with the API client. Every API client application needs to implement this interface in order to handle all the events generated by the TWS/Gateway. Almost every EClientSocket method call will result in at least one event delivered here.
可以知道,用于提交的几乎所有的消息事件,都是需要通过这个类进行处理。然而,如果你深入编程过程,就会发现IB是需要你自行实现这个类的全部虚函数的。也就是说,对于EWrapper来说,它其实是个接口。

那么,我们都需要实现哪些接口呢?接口具体实现,你可以直接把样例里的EWrapper直接拿来用,但是我这里还是稍微介绍一下,你也可以把这篇文章当成一个查询使用。

美国盈透证券优惠信息(新、老盈透用户均适用):
盈透证券优惠开户链接:https://www.e-investingguide.com/interactivebrokers
无论你是已经在盈透证券入金交易的老客户或者是正准备在盈透证券开户的新客户,如果你需要免除盈透证券每月10美元账户维护费以及降低盈透证券账户交易佣金水平(具体能优惠和降低多少,取决于你的交易量,已经入金交易的盈透用户也能挂靠降低佣金),都可以联系我,在IB盈透证券出入金及TWS软件使用、API接口使用、开立机构类账户(离岸对冲基金、家族办公室、自营交易集团)等方面遇到问题的也可以联系我询问。 可以发Email邮件联系我,我的邮箱地址是 [email protected]

我的微信号:47268101 或者打开微信,直接扫描下方二维码添加我为好友即可咨询:

账户信息相关函数
void accountDownloadEnd
它是与账号信息有关的一个函数,在你对账号操作请求发送后,并被处理后得到的返回信息。所以当账号信息处理完毕后,该函数会被TWS激活。
相关参数
string account:账户ID
实现方式
public virtual void accountDownloadEnd(string account)
{
Console.WriteLine(“Account download finished: ” + account + “\n”);
}
相关函数
updateAccountTime
updatePortfolio
updateAccountValue
EClientSocket::reqAccountUpdates
void accountSummary
它也是一个与账号信息有关的函数,通常在使用了 EClientSocket::reqAccountSummary 之后从TWS获取相关信息,返回类容和 TWS’ Account Summary Window 一致。
相关参数:
int reqId,reqid
string account,账户id
string tag, 返回以下标识,标识具体信息参考TWS API中的介绍
string value, 账户相关属性信息,比如返回头寸、账户属性等
string currency,用于进一步表示value的附加信息,如果表示金钱的时候,它就会表示金钱的单位是美元还是人民币等
tag:
AccountType — Identifies the IB account structure
NetLiquidation — The basis for determining the price of the assets in your account. Total cash value + stock value + options value + bond value
TotalCashValue — Total cash balance recognized at the time of trade + futures PNL
SettledCash — Cash recognized at the time of settlement – purchases at the time of trade – commissions – taxes – fees
AccruedCash — Total accrued cash value of stock, commodities and securities
BuyingPower — Buying power serves as a measurement of the dollar value of securities that one may purchase in a securities account without depositing additional funds
EquityWithLoanValue — Forms the basis for determining whether a client has the necessary assets to either initiate or maintain security positions. Cash + stocks + bonds + mutual funds
PreviousEquityWithLoanValue — Marginable Equity with Loan value as of 16:00 ET the previous day
GrossPositionValue — The sum of the absolute value of all stock and equity option positions
RegTEquity — Regulation T equity for universal account
RegTMargin — Regulation T margin for universal account
SMA — Special Memorandum Account: Line of credit created when the market value of securities in a Regulation T account increase in value
InitMarginReq — Initial Margin requirement of whole portfolio
MaintMarginReq — Maintenance Margin requirement of whole portfolio
AvailableFunds — This value tells what you have available for trading
ExcessLiquidity — This value shows your margin cushion, before liquidation
Cushion — Excess liquidity as a percentage of net liquidation value
FullInitMarginReq — Initial Margin of whole portfolio with no discounts or intraday credits
FullMaintMarginReq — Maintenance Margin of whole portfolio with no discounts or intraday credits
FullAvailableFunds — Available funds of whole portfolio with no discounts or intraday credits
FullExcessLiquidity — Excess liquidity of whole portfolio with no discounts or intraday credits
LookAheadNextChange — Time when look-ahead values take effect
LookAheadInitMarginReq — Initial Margin requirement of whole portfolio as of next period’s margin change
LookAheadMaintMarginReq — Maintenance Margin requirement of whole portfolio as of next period’s margin change
LookAheadAvailableFunds — This value reflects your available funds at the next margin change
LookAheadExcessLiquidity — This value reflects your excess liquidity at the next margin change
HighestSeverity — A measure of how close the account is to liquidation
DayTradesRemaining — The Number of Open/Close trades a user could put on before Pattern Day Trading is detected. A value of “-1” means that the user can put on unlimited day trades.
Leverage — GrossPositionValue / NetLiquidation
相关函数
accountSummaryEnd
EClientSocket::reqAccountSummary
实现方式
public virtual void accountSummary(int reqId, string account, string tag, string value, string currency)
{
Console.WriteLine(“Acct Summary. ReqId: ” + reqId + “, Acct: ” + account + “, Tag: ” + tag + “, Value: ” + value + “, Currency: ” + currency);
}
void accountSummaryEnd
基本上没什么用的一个函数,主要告诉你请求信息已经发送完毕了。
相关参数
int reqId
相关函数
accountSummary
EClientSocket::reqAccountSummary
实现方式
public virtual void accountSummaryEnd(int reqId)
{
Console.WriteLine(“AccountSummaryEnd. Req Id: ” + reqId + “\n”);
}
void accountUpdateMulti
用于账户更新信息使用的一个函数
相关参数
int requestId,请求id
string account, 账户id
string modelCode, the model code with updates
string key,需要更新的键值对
string value,需要更新的键值对
string currency,键值对的补充信息,通常为货币符号
相关函数
accountUpdateMultiEnd
EClient::reqAccountUpdatesMulti
实现方式
public virtual void accountUpdateMulti(int reqId, string account, string modelCode, string key, string value, string currency)
{
Console.WriteLine(“Account Update Multi. Request: ” + reqId + “, Account: ” + account + “, ModelCode: ” + modelCode + “, Key: ” + key + “, Value: ” + value + “, Currency: ” + currency + “\n”);
}
void accountUpdateMultiEnd
更新信息完成后发送的补充信息
相关参数
int requestId,请求id
相关函数
EWrapper::accountUpdateMulti
EClientSocket::reqAccountUpdatesMulti
相关实现
public virtual void accountUpdateMultiEnd(int reqId)
{
Console.WriteLine(“Account Update Multi End. Request: ” + reqId + “\n”);
}
————————————————
版权声明:本文为CSDN博主「打码的阿通」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/poisonchry/article/details/111601016