Jump to content
Sign in to follow this  
Guest andreif

How to detect type of the market?

Recommended Posts

Guest andreif

How I can get type of the market (CFD or Spread Betting), given it’s market ID?

Share this post


Link to post

Currently we don’t provide the market type on the market information response. This works fine if you use the market search to find a market (the type is contained within the url). However, this causes problems when you use the watchlist to place trades on saved markets.

This is something we’re looking at adding to the market information call.

Share this post


Link to post
Guest mrdavidlaing

Until this gets added to the market information call, here is a workaround:

 /// <summary>
    /// Given a market, figures out which of the available TradingAccounts to use
    /// TODO - when the API is extended to include market type on the marketInfo object this method can be removed.
    /// </summary>
    /// <param name="marketInfo">The market that we want to trade on</param>
    /// <param name="accountInfo">The account we want to trade with</param>
    /// <returns></returns>
    public ApiTradingAccountDTO GetTradingAccountForMarket(ApiMarketInformationDTO marketInfo, AccountInformationResponseDTO accountInfo)
    {
        //Check if this is market appears in the CFD search
        var cfdMarkets = _client.CFDMarkets.ListCfdMarkets(marketInfo.Name, "", accountInfo.ClientAccountId, 50);
        if (   (cfdMarkets.Markets.Count() > 0 )
            && (cfdMarkets.Markets.FirstOrDefault(market => market.MarketId == marketInfo.MarketId)!=null)
           )
        {
            var tradingAccountForMarket = accountInfo.TradingAccounts.FirstOrDefault(ta => ta.TradingAccountType.ToUpper() == "CFD");
            if (tradingAccountForMarket == null)
                throw new NoTradingAccountForMarketTypeException(
                    string.Format("No trading account can be found that is able to trade on CFD market {0}, MarketId {1}",
                                  marketInfo.Name, marketInfo.MarketId));
            return tradingAccountForMarket;
        }

        //If not, try the spread markets
        var spreadMarkets = _client.SpreadMarkets.ListSpreadMarkets(marketInfo.Name, "", accountInfo.ClientAccountId, 50);
        if ((spreadMarkets.Markets.Count() > 0)
            && (spreadMarkets.Markets.FirstOrDefault(market => market.MarketId == marketInfo.MarketId) != null)
           )
        {
            var tradingAccountForMarket = accountInfo.TradingAccounts.FirstOrDefault(ta => ta.TradingAccountType.ToUpper().StartsWith("SPREAD"));
            if (tradingAccountForMarket == null)
                throw new NoTradingAccountForMarketTypeException(
                    string.Format("No trading account can be found that is able to trade on Spread market {0}, MarketId {1}",
                                  marketInfo.Name, marketInfo.MarketId));
            return tradingAccountForMarket;
        }

        //If we can't find a either a CFD or a Spread market, thrown an exception
        throw new UnknownMarketException(string.Format("Unable for find either a CFD or Spread market named {0} with MarketId {1}", marketInfo.Name, marketInfo.MarketId));
    }

Share this post


Link to post
Guest sky.sanders

Currently we don’t provide the market type on the market information response. This works fine if you use the market search to find a market (the type is contained within the url). However, this causes problems when you use the watchlist to place trades on saved markets.

This is something we’re looking at adding to the market information call.

it would be of value to have market type as a property of PriceDTO as well

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×