1

I am using API manager for the trading platform MetaTrader 4

I need to get ALL SECURITIES per GROUP

for example GROUP=preliminary|SECUTIRY_0=Forex|SECUTIRY_1=CFD|SECUTIRY_2=|

i have some tips how to do it below:

    1. After request Securities config using CfgRequestSymbolGroup(ConSymbolGroup configurations) you got all securities.*
    1. So you got ConSymbolGroup for each security and now that configurations[0] is forex, configurations[1] is cfd and configurations[2] is metals for example.*
    1. Then request group config using CfgRequestGroup(int total) you will get ConGroup structure for each group.
    1. ConGroup has ConGroupSec secgroups[MAX_SEC_GROUPS] parameter - security group settings.*
    1. The indexes will be the same so secgroups[0] is forex settings for this group, secgroups[1] is cfd and so on.*

my code is below but can not get the desired result, in the code below i get the list with SECURITIES AND THE LIST WITH GROUPS but can not get indexes based on description above to get the result in this format

GROUP=preliminary|SECUTIRY_0=Forex|SECUTIRY_1=CFD|SECUTIRY_2=|

    // 1 step
    // request all securities
    // list with securities
    ConSymbolGroup securities[MAX_SEC_GROUP];

    int result = ExtManager->CfgRequestSymbolGroup(securities);

    // 2 step
    // request all groups
    // list with groups

    ConGroup *groups = ExtManager->CfgRequestGroup(&total);
    ConGroupSec secgroups[MAX_SEC_GROUPS];

    int index_secgroup = 0;
    int index_security = 0;


    for (int i = 0; i < MAX_SEC_GROUP; i++)     
        for (int i =0; i < total; i++)              
            ExtProcessor.PrintResponse(size,                    
                "GROUP=%s|"
                "SECUTIRY_0=%s|"    
                "SECUTIRY_1=%s|"
                "SECUTIRY_2=%s|\r\n",
                groups[i].group,
                securities[0].name,
                securities[1].name,
                securities[2].name);

}
aaa
  • 446
  • 2
  • 8
  • 29
  • 1
    Although you experiencing this problem while reading data from MT, the problem it self is not related to MetaTrader. I strongly suggest you to isolate it from MT(create dummy classes, references from one of them to another) and will help you a lot understand the problem, or it will help other people to answer you question(right now everybody thinks that it's about MT and skips it). The one problem in your code is that you using to cycles, both of which uses same variable `i` – Uriil May 11 '17 at 13:11
  • @Uriil actually this is the question, i have 1. securities (hold all securities) 2. groups (hold all groups) 3. secgroups (hold the security settings for groups) -> the proble is that in securities and securitiess ettings there no any common data that i can indetify which security belongs to which group, the answe i got that we can indentify them only by indexes how the rensponse is returned -> for loop how to make it correct, i have all necessary data, the only thing remained to use security index and secgroup index to indentify for which group they belong, could u help with the for loop? – aaa May 11 '17 at 14:10
  • Ok, let's say you have two groups and one of them has FOREX and CFD and second one FOREX and METALS. What should be the output? – Uriil May 11 '17 at 19:56
  • @Uriil the output that i need will be the following GROUP1=preliminary|SECUTIRY=Forex (new line) GROUP1=preliminary|SECUTIRY=CFD (new line) GROUP2=preliminary2|SECUTIRY=Forex (new line) GROUP2=preliminary2|SECUTIRY=METALS, as well in this way for each line we can add all the settings for each security from the group using secgroups[MAX_SEC_GROUPS] GROUP1=preliminary|SECUTIRY=CFD|SETTINGS1=aaa|SETTINGS2=ddd| and so on(new line) – aaa May 12 '17 at 03:55

1 Answers1

1

Here is code snippet which will give you required data, so you can output it as you need:

ConSymbolGroup sgconfigurations[MAX_SEC_GROUP];
_manager->Manager->CfgRequestSymbolGroup(sgconfigurations);

int total = 0;
ConGroup* result = _manager->Manager->CfgRequestGroup(&total);

for (int i = 0; i < total; i++)
{
    for (int j = 0; j < MAX_SEC_GROUP; j++) {
        if (result[i].secgroups[j].show == 1 && sgconfigurations[j].name != NULL && sgconfigurations[j].name[0] != '\0') {
            char* groupName = result[i].group;
            char* securityName = sgconfigurations[j].name;
        }
    }
}
Uriil
  • 11,948
  • 11
  • 47
  • 68
  • thanks, seems isworking correctly, i can see that sgconfigurations[j].name in my result in a lot of places is emhpy, could we filter do not list the emhpy once? becaus enow is getting correct result but with a lot of emphy securities – aaa May 12 '17 at 07:50
  • I suspect, that `result[i].secgroups[j].show == 1` should do the job and hide unused secs. However I might be wrong – Uriil May 12 '17 at 08:03
  • now the response is like this GROUP=WLD-STD-1-USD|SECURITY=DEMO-Forex| GROUP=WLD-STD-1-USD|SECURITY=| GROUP=WLD-STD-1-USD|SECURITY=DEMO-CFD| GROUP=WLD-STD-1-USD|SECURITY=| GROUP=WLD-STD-1-USD|SECURITY=| GROUP=WLD-STD-1-USD|SECURITY=|, if u can filter this SECURITY=| when is emphy will be perfect – aaa May 12 '17 at 08:07
  • 1
    @ionluchian what's the problem just to check if it's empty and skipping it in this case? – Uriil May 12 '17 at 11:18
  • can i get iside the loop the type of security? for example char* securityType = fx or cfd or metals or etc? @Uriil – aaa May 12 '17 at 16:17
  • @ionluchian What do you mean by security type? There is no such property on this object. – Uriil May 12 '17 at 16:23
  • yes i saw that there is no type, metaquotes said that by indexes we can indentify them like security sgconfigurations[0] is FX sgconfigurations[1] is CDF sgconfigurations[3] is METALS etc-> can somehow assign this security type? @Uriil – aaa May 12 '17 at 16:33
  • It's not types, it's symbol groups. And you can configure them using MT4 Administrator on dedicated tab – Uriil May 12 '17 at 16:35
  • thnaks for information, so meansin the tab firt security is FX, second one is CFD, correct? If is correct what i said, can than we assign at list the position of the security to know for example group 1 have security a1 and b1 and a1 is on the first position and b1 is on second position and in the response can we do soemthing like int* securityPosition = here the position of the security? @Uriil – aaa May 12 '17 at 16:39
  • i am automizing now the groups, instruments and securities from mt4 with all the marckups and now the dificult stuff to assign the securities per group that already u helped me, but remined to indentfy on which position the security is in order to assign that this security is FX, CFD ect because based on this i will chekc the instrument type and check the markups in for different calculations @Uriil – aaa May 12 '17 at 16:41
  • 1
    @ionluchian You are a bit wrong. First does not have to Forex, it's defined by SymbolGroup configuration. – Uriil May 12 '17 at 18:11
  • i am little confused regarding securities, so in this case the code from above is correct security per group, u said is defined by SymbolGroup, so in order to to what kind of security is a1 for example we have to loop in SymbolGroup as well? What i have 1. List of groups requested by RequestGroup() 2. list of isntruments requested by SymbolsRefresh() and SymbolsGetAll() 3. and now from your code i have the lsit of securities.The question is the SymbolsGetAll() have type FX, CFD and so on, how i cna manage to indetify what kind of security is?My aim is to link securities by FX or CFD etc @Uriil – aaa May 13 '17 at 03:52
  • Could u please fixed the if statement in order to skip the empty securities? @Uriil – aaa May 13 '17 at 04:21
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144114/discussion-between-uriil-and-ionluchian). – Uriil May 13 '17 at 07:04