-
Notifications
You must be signed in to change notification settings - Fork 0
/
PosixIBClient.h
157 lines (131 loc) · 5.76 KB
/
PosixIBClient.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/* Copyright (C) 2013 Interactive Brokers LLC. All rights reserved. This code is subject to the terms
* and conditions of the IB API Non-Commercial License or the IB API Commercial License, as applicable. */
#ifndef posixtestclient_h__INCLUDED
#define posixtestclient_h__INCLUDED
#include <QObject>
#include <QThread>
#include <QString>
#include <QDateTime>
#include "EWrapper.h"
#include <memory>
class EPosixClientSocket;
enum State {
ST_CONNECT,
ST_PLACEORDER,
ST_PLACEORDER_ACK,
ST_CANCELORDER,
ST_CANCELORDER_ACK,
ST_PING,
ST_PING_ACK,
ST_IDLE,
ST_REQMKTDATA,
ST_REQMKTDATA_ACK
};
class PosixIBClient :public QObject, public EWrapper
{
Q_OBJECT
public:
explicit PosixIBClient(QObject *parent = 0);
virtual ~PosixIBClient();
void processMessages();
//PosixIBClient();
//~PosixIBClient();
public slots:
void sayHello();
void onConnect( int port, int pubport, int subport);
void onDisconnect();
void onReqCurrentTime();
void onReqMktData();
void onCancelMktData();
void onProcessMessages();
void onTest();
signals:
void connected();
void disconnected();
void orderSubmitted(QString msg);
void orderCanceled(QString msg);
void orderUpdated(QString msg);
void orderFilled(QString msg);
public:
bool connect(const char * host, unsigned int port, int clientId = 0);
void disconnect() const;
bool isConnected() const;
private:
long count = 0;
int port;
int pubport;
int subport;
void reqCurrentTime();
void placeOrder();
void cancelOrder();
void getNextValidID();
public:
// events
void tickPrice(TickerId tickerId, TickType field, double price, int canAutoExecute);
void tickSize(TickerId tickerId, TickType field, int size);
void tickOptionComputation( TickerId tickerId, TickType tickType, double impliedVol, double delta,
double optPrice, double pvDividend, double gamma, double vega, double theta, double undPrice);
void tickGeneric(TickerId tickerId, TickType tickType, double value);
void tickString(TickerId tickerId, TickType tickType, const IBString& value);
void tickEFP(TickerId tickerId, TickType tickType, double basisPoints, const IBString& formattedBasisPoints,
double totalDividends, int holdDays, const IBString& futureExpiry, double dividendImpact, double dividendsToExpiry);
void orderStatus(OrderId orderId, const IBString &status, int filled,
int remaining, double avgFillPrice, int permId, int parentId,
double lastFillPrice, int clientId, const IBString& whyHeld);
void openOrder(OrderId orderId, const Contract&, const Order&, const OrderState&);
void openOrderEnd();
void winError(const IBString &str, int lastError);
void connectionClosed();
void updateAccountValue(const IBString& key, const IBString& val,
const IBString& currency, const IBString& accountName);
void updatePortfolio(const Contract& contract, int position,
double marketPrice, double marketValue, double averageCost,
double unrealizedPNL, double realizedPNL, const IBString& accountName);
void updateAccountTime(const IBString& timeStamp);
void accountDownloadEnd(const IBString& accountName);
void nextValidId(OrderId orderId);
void contractDetails(int reqId, const ContractDetails& contractDetails);
void bondContractDetails(int reqId, const ContractDetails& contractDetails);
void contractDetailsEnd(int reqId);
void execDetails(int reqId, const Contract& contract, const Execution& execution);
void execDetailsEnd(int reqId);
void error(const int id, const int errorCode, const IBString errorString);
void updateMktDepth(TickerId id, int position, int operation, int side,
double price, int size);
void updateMktDepthL2(TickerId id, int position, IBString marketMaker, int operation,
int side, double price, int size);
void updateNewsBulletin(int msgId, int msgType, const IBString& newsMessage, const IBString& originExch);
void managedAccounts(const IBString& accountsList);
void receiveFA(faDataType pFaDataType, const IBString& cxml);
void historicalData(TickerId reqId, const IBString& date, double open, double high,
double low, double close, int volume, int barCount, double WAP, int hasGaps);
void scannerParameters(const IBString &xml);
void scannerData(int reqId, int rank, const ContractDetails &contractDetails,
const IBString &distance, const IBString &benchmark, const IBString &projection,
const IBString &legsStr);
void scannerDataEnd(int reqId);
void realtimeBar(TickerId reqId, long time, double open, double high, double low, double close,
long volume, double wap, int count);
void currentTime(long time);
void fundamentalData(TickerId reqId, const IBString& data);
void deltaNeutralValidation(int reqId, const UnderComp& underComp);
void tickSnapshotEnd(int reqId);
void marketDataType(TickerId reqId, int marketDataType);
void commissionReport( const CommissionReport& commissionReport);
void position( const IBString& account, const Contract& contract, int position, double avgCost);
void positionEnd();
void accountSummary( int reqId, const IBString& account, const IBString& tag, const IBString& value, const IBString& curency);
void accountSummaryEnd( int reqId);
void verifyMessageAPI( const IBString& apiData);
void verifyCompleted( bool isSuccessful, const IBString& errorText);
void displayGroupList( int reqId, const IBString& groups);
void displayGroupUpdated( int reqId, const IBString& contractInfo);
private:
//use unique_ptr for release version, in qt unique_ptr makes code assistance disappeared
std::auto_ptr<EPosixClientSocket> pClient;
std::auto_ptr<QThread> pThread;
State state;
time_t sleepDeadline;
OrderId nextOrderId;
};
#endif