I'm using TWS Api to connect to the IB Gateway to trade algorithmically via my third party c++ program. When I start my project up it shows on the IB gateway API client connection status that it does indeed connect and logs connection output in its own console within IB Gateway. However, I get Exception Unhandled "Unhandled exception at 0x5934F48C (TwsSocketClient.dll) in MARKET_MASTER.exe: 0xC0000005: Access violation reading location 0x00000000." within the class that agglomerates the different modules to then be called within main at run time and recommends I place a break point. The class that is supposed to agglomerate these calls
#include "EXECUTION_CONTROL.h"
execution_control::execution_control(trading_ai& exec_trading_ai, ib_api& exec_ib_api, rtrader_api& exec_rtrader_api, int& exec_market_depth_lvls)
{
//Initializations
//connection parameters for ib gateway paper trading
exec_ib_api.client.eConnect("127.0.0.1", 4002, 0);
/*exec_ib_api.contract.symbol = exec_ib_api.ticker_config.ticker;
exec_ib_api.contract.secType = exec_ib_api.ticker_config.type;
exec_ib_api.contract.exchange = exec_ib_api.ticker_config.exchange;
exec_ib_api.contract.currency = exec_ib_api.ticker_config.currency;
exec_ib_api.client.reqMktDepth(0, exec_ib_api.contract, exec_market_depth_lvls, true, nullptr);*/
//check for data updates and change output accordingly
for(;;)
{
std::cout << "oops sorry about that mods just caught it";
}
exec_ib_api.client.eDisconnect();
};
where the exec_ib_api comes from:
#include "IB_API.h"
//when in production, will not need to specify ticker string in constructor and development is set to false
//the loop to listen for updates will happen in execution_control constructor
ib_api::ib_api(std::string &ticker, bool development)
{
ib_api::ticker_types enum_ticker{ string_to_ticker(ticker) };
define_ticker_data(enum_ticker);
}
ib_api::ticker_config_blueprint ib_api::ticker_config;
Contract ib_api::contract;
//override all these functions or create empty functions in CONN_WRAPPER
conn_wrapper ib_api::connection_wrapper;
//pass in a pointer to client parameter
EClientSocket ib_api::client(&connection_wrapper);
void ib_api::define_ticker_data(ib_api::ticker_types &ticker)
{
switch (ticker)
{
case ES:
ib_api::ticker_config.ticker = "ES";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case NQ:
ib_api::ticker_config.ticker = "NQ";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case YM:
ib_api::ticker_config.ticker = "YM";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case RTY:
ib_api::ticker_config.ticker = "RTY";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case MES:
ib_api::ticker_config.ticker = "MES";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case MNQ:
ib_api::ticker_config.ticker = "MNQ";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case MYM:
ib_api::ticker_config.ticker = "MYM";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
case MRTY:
ib_api::ticker_config.ticker = "RTY";
ib_api::ticker_config.type = "FUT";
ib_api::ticker_config.exchange = "GLOBEX";
ib_api::ticker_config.currency = "USD";
break;
default:
std::cout << "ticker does not exist";
};
}
//this will map the empty struct data type
std::map<int, ib_api::ticker_config_blueprint> ib_api::get_ticker_data()
{
std::map<int, ib_api::ticker_config_blueprint> mapped_ticker_config;
mapped_ticker_config[0] = ib_api::ticker_config;
return mapped_ticker_config;
}
ib_api::ticker_types ib_api::string_to_ticker(std::string &ticker)
{
ib_api::ticker_types ticker_type{};
if (ticker == "ES" || ticker == "es")
ticker_type = ES;
else if (ticker == "NQ" || ticker == "nq")
ticker_type = NQ;
else if (ticker == "YM" || ticker == "ym")
ticker_type = YM;
else if (ticker == "RTY" || ticker == "rty")
ticker_type = RTY;
else if (ticker == "MES" || ticker == "mes")
ticker_type = MES;
else if (ticker == "MNQ" || ticker == "mnq")
ticker_type = MNQ;
else if (ticker == "MYM" || ticker == "mym")
ticker_type = MYM;
else if (ticker == "MRTY" || ticker == "mrty")
ticker_type = MRTY;
else std::cout << "Ticker does not exist or symbol was mix of capital and lower case characters";
return ticker_type;
}
#pragma once
#include "EClientSocket.h"
#include "Contract.h"
#include "CONFIG.h"
#include "CONN_WRAPPER.h"
#include <iostream>
#include <vector>
#include <map>
class ib_api
{
private:
struct ticker_config_blueprint
{
std::string ticker{};
std::string type{};
std::string exchange{};
std::string currency{"USD"};
};
enum ticker_types
{
ES,
NQ,
YM,
RTY,
MES,
MNQ,
MYM,
MRTY
};
static conn_wrapper connection_wrapper;
protected:
public:
//static classes to initialize in execution control class
static EClientSocket client;
static Contract contract;
static ticker_config_blueprint ticker_config;
ib_api(std::string &ticker, bool development);
void define_ticker_data(ticker_types &ticker);
std::map<int, ib_api::ticker_config_blueprint> get_ticker_data();
ib_api::ticker_types string_to_ticker(std::string &ticker);
};
I am indeed connected to paper trading and those should be the correct connection parameters, but I am unsure what to do about the problem that seems to be stemming from the .dll file.