Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6915243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:27:04+00:00 2026-05-27T09:27:04+00:00

I am working on a trading API (activex from interactive brokers)which has a method

  • 0

I am working on a trading API (activex from interactive brokers)which has a method called:

void reqMktDataEx(int tickerId, IContract contract, string generalDetails, int snapshot)

The issue is around the last parameter "int snapshot" which obviously requires an int input which actually indicates that whether trader wanna snapshot market data or not. So I guess that if I set it to non-zero, then the implicit conversion would convert this non-zero to be bool value "true".

However, I am using c# to connect to this api. Everything was fine until this one. I tried this:

A. void reqMktDataEx(1, AUDUSD, "100", 0)
Please ignore the first three parameters "1, AUDUSD, "100"", the only matter is the last one 0 as int. I got paused during debugging and the information is :
"Specified cast is not valid. Invalidcastexception is unhandled" and "when casting from a number, the number must not be infinity".

After this I learned that here is a difficulty for c# to treat 1 as bool true and 0 as bool false IMPLICITLY according this
web http://www.dotnetperls.com/convert-bool-int

B. I tried this
void reqMktDataEx(1, AUDUSD, "100", Convert.ToInt16(false)) I got similar error again.

C. I tried again this one:

void reqMktDataEx(1, AUDUSD, "100", int.Parse("false"))

the complaint is input string was not in a correct format. Make sure that you method arguments are in the right format.

MY GUESS:
Here is a inside configuration of C# which does not treat 0 as false and 1 as true. Is there any way to solve?

First Edit

As suspected by one professional programmer below, I post the contract class and audusd definition here for him.

namespace InteractiveBrokersTradingSystem
{
    class Contract:TWSLib.IContract
    {
        public int conId { get; set; }
        public string symbol { get; set; }
        public string secType { get; set; }
        public string expiry { get; set; }
        public double strike { get; set; }
        public string right { get; set; }
        public string multiplier { get; set; }
        public string exchange { get; set; }
        public string primaryExchange { get; set; }
        public string currency { get; set; }
        public string localSymbol { get; set; }
        public int includeExpired { get; set; }
        public object comboLegs { get; set; }
        public object underComp { get; set; }
        public string comboLegsDescrip { get; set; }
        public string secIdType { get; set; }
        public string secId { get; set; }
    }
}

namespace InteractiveBrokersTradingSystem
{
    class Forex:Contract
    {
        public Forex(string preCurrency,string baseCurrency)
        {
            //conId = 14433401;
            symbol = preCurrency;
            secType = "CASH";
            exchange = "IDEALPRO";
            currency = baseCurrency;
            strike = 0;
            includeExpired = 0;
            primaryExchange = "IDEALPRO";       
        }
    }
}

The method I use to call the reqMktDataEx:
implementation first, simple inheritance:

public void MyReqMarketData(int tickId, IContract contract, string tickTypes, int snapshot)
{
    reqMktDataEx(tickId, contract, tickTypes, snapshot);
}


 private void AudButtonItemItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
 {
     Forex audusd = new Forex("AUD", "USD");

      _myTwsClass.MyReqMarketData(1,audusd, "100", 0);
  }

Second Edit:

  System.InvalidCastException was unhandled
  Message=Unable to cast object of type 'InteractiveBrokersTradingSystem.Forex' to type 'TWSLib.IContract'.
  Source=InteractiveBrokersTradingSystem

It seems that here is some casting problem between the forex class I defined and the Icontract com thing. Here is my new definition:

namespace InteractiveBrokersTradingSystem
{
    class Forex
    {
        public int conId { get; set; }
        public string symbol { get; set; }
        public string secType { get; set; }
        public string expiry { get; set; }
        public double strike { get; set; }
        public string right { get; set; }
        public string multiplier { get; set; }
        public string exchange { get; set; }
        public string primaryExchange { get; set; }
        public string currency { get; set; }
        public string localSymbol { get; set; }
        public int includeExpired { get; set; }
        public object comboLegs { get; set; }
        public object underComp { get; set; }
        public string comboLegsDescrip { get;set; }
        public string secIdType { get; set; }
        public string secId { get; set; }

        public Forex(string preCurrency,string baseCurrency)
        {
            //conId = 0;
            //symbol = preCurrency;
            //secType = "CASH";
            //expiry = null;
            //strike = double.Parse("0");
            //right = null;
            //multiplier = null;
            //exchange = "IDEALPRO";
            //primaryExchange = "IDEALPRO";
            //currency = baseCurrency;
            //localSymbol = null;
            //includeExpired = 0;
            //comboLegs = null;
            //underComp = null;
            //comboLegsDescrip = null;
            //secType = null;
            //secId = null;
        }
    }
}

As you can see that the Forex class inherits from the TWS.IContract. how it could not be cast to Icontract successively?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:27:05+00:00Added an answer on May 27, 2026 at 9:27 am

    There is no implicit conversion of a bool to an int. Only an explicit one:

    Convert.ToInt32(someBool)
    // or...
    someBool ? 1 : 0
    

    From that site you linked:

    First, you cannot implicitly convert from bool to int. The C# compiler uses this rule to enforce program correctness. It is the same rule that mandates you cannot test an integer in an if statement.

    Edit

    int doesn’t have a concept of infinity. Only float and double do. This means it won’t be related to that parameter, unless that parameter just controls the flow of the code that is actually crashing. Which still means it isn’t the conversion causing the problem.

    You’re getting a different error for int.Parse("false") because it is expecting a number, not a true/false value. This will always throw an exception at runtime, but it will throw in your code, not in the library’s code.

    I’m starting to think it is the second parameter, contract, for which you’ve supplied AUDUSD.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background I am working on a trading ActiveX API in visual studio 2010 on
I am working on task involving reading from the socket trading quotes and I
I am working on an ASP.NET MVC application which has a model for a
I'm working on a program which reacts to events coming from an internet socket,
I am working with Event Tracing for Windows API, and from time to time,
I developing an application, in which i working with database manipulation. The method i
I'm working on an online forex trading system and a while back we have
I'm working on a fairly large project for a trading company in Philadelphia. The
Working with python interactively, it's sometimes necessary to display a result which is some
I am working on a Recursive QuickSort method implementation in a GenericList Class. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.