Getting Session Properties (Username and Password) for QuickFix/n

5.1k views Asked by At

I have put my user name and password on the FIX configuration file. So I must think I should be able to get User name and passwords from some internal variable like session variable or SessionSetting variable or session.SessionDataDictionary or some other variable. However, I did not find any straight forward solution to get Username and Password from internal variable.

[SESSION]
BeginString=FIX.4.4
SenderCompID= xxxxx
Username= xxxx
Password= xxxx

Probably this is very doable, logically speaking. However, neither anyone suggest to do this or I have not seen anyone doing this on google. Only code bit I found from google is this.

String username = sessionSettings.getString(sessionId, "Username"); //only works for Java version of QuickFix

However above code is only working for Java Version of QuickFix and this method is not available in DotNet Version of QuickFix (i.e. QuickFix/n)

getString(sessionId, "Username"); 

I am looking to achieve similar results for FIX 4.4 using QuickFix/n. This might be very simple task if someone is familiar with QuickFix. I will really appreciate your tips or advice. I would not mind if you have some idea for Java or C++ version as they are all quite similar. I just need to know in which variable this user name and password is stored and how can I get this using Csharp code.

Thanks in advance.

1

There are 1 answers

1
hunch_hunch On BEST ANSWER

You are on the right track with String username = sessionSettings.getString(sessionId, "Username");, but the method call in QuickFIX/n is slightly different.

The call is more like sessionSettings.Get(sessionId).GetString("Username");.

See this example:

var configuration =
    new System.Text.StringBuilder().AppendLine("[ DEFAULT ]")
        .AppendLine("ConnectionType=initiator")
        .AppendLine("[SESSION]")
        .AppendLine("BeginString=FIX.4.4")
        .AppendLine("SenderCompID=Sender")
        .AppendLine("TargetCompID=Target")
        .AppendLine("Username=Gandalf")
        .AppendLine("Password=YouShallNotPass")
        .ToString();
var settings = new SessionSettings(new System.IO.StringReader(configuration));
var session = new SessionID("FIX.4.4", "Sender", "Target");
var sender = settings.Get(session).GetString("SenderCompID"); // Returns Sender
var user = settings.Get(session).GetString("Username"); // Returns Gandalf
var pass = settings.Get(session).GetString("Password"); // Returns YouShallNotPass

For reference, see the unit tests for SessionSettings.