MBT Navigator Developer Notes
Last updated 11/27/2007   -   back to SDK Home page

D o w n l o a d s

MBT Navigator Version 11.1.0.2
IMPORTANT: 11.1.0.2 followup
11.1.0.2 7/7/2008 announcement


Our zipped collection of VB and C examples need only recompiling. The chm help file has been updated:
http://sdk.mbtrading.com/MbtSDK.zip
http://sdk.mbtrading.com/MbtSDK.chm

If you can't open the .chm help file, if you receive the error "Action canceled" or "Page cannot be displayed" then see the "IMPORTANT" note in the Welcome email you received when you signed up for the SDK. It basically says you must unblock it by right-clicking it, selecting Properties, and clicking the Unblock button:
right-click / Properties / Unblock

S n i p p e t s

' The proper way to create the objects: You must instantiate the MbtComMgr
' and then grab references to the MbtOrderClient and MbtQuotes objects off it.
' Only the MbtComMgr is instantiated using the VB "New" keyword:
'
' VB6:
Set myComMgr = New MbtComMgr ' instantiate
Set myOrders = myComMgr.OrderClient ' grab reference
Set myQuotes = myComMgr.Quotes ' grab reference

' VB.NET (NET has deprecated the "Set" keyword):
myComMgr = New MbtComMgr
myOrders = myComMgr.OrderClient
myQuotes = myComMgr.Quotes

' C#.NET
myComMgr = new MbtComMgr();
myOrderClient = myComMgr.OrderClient;
myQuotes = myComMgr.Quotes;

' VB6 - new timeActivate, timeExpire date fields and dStrikePrice in MbtOrderClient.Submit():
' -------------------------------------------------------------------------------------------------------
' Please note, timeActivate and timeExpire are NOT used yet. Just pass a NULL or blank
'
Dim timeActivate As Date
Dim timeExpire As Date
Dim dStrikePrice As Double

Function Submit(   ' copied from VB IDE Object Browser - function key F2
    lBuySell As Long,
    lVolume As Long,
    bstrSymbol As String,
    dPrice As Double,
    dStopPrice As Double,
    lTif As Long,
    lCapacity As Long,
    lOrdType As Long,
    lVolType As Long,
    lDisplayQty As Long,
    pAcct As MbtAccount,
    bstrMarket As String,
    bstrPrefMMID As String,
    dPriceOther As Double,
    dPriceOther2 As Double,
    timeActivate As Date, ' NOT used yet. Just pass a NULL or blank
    timeExpire As Date, ' NOT used yet. Just pass a NULL or blank
    lExpMonth As Long,
    lExpYear As Long,
    dStrikePrice As Double,
    lCondType As Long,
    lPriceVsSpeed As Long,
    pbstrRetMsg As String
) As Boolean

' C++ - extracting/parsing new UTCDateTime date/time object:
' -------------------------------------------------------------------------------------------------------
' Take a look at OnQuoteData in DlgLevel2.cpp in the NavOCq C++ sample:
HRESULT CDlgLevel2::OnQuoteData(QUOTERECORD* pQuote)
{
    CString sOut;
    double dLast = pQuote->dLast;
    long lSize = pQuote->lLastSize;
    long lVol = pQuote->lVolume;
    COleDateTime cTime(pQuote->UTCDateTime);
    sOut.Format("L1 $%.2f %d %d %s %s", dLast, lSize, lVol, cTime.Format("%m/%d/%y"), cTime.Format("%H:%M:%S"));
    ...

' C++ - new timeActivate, timeExpire date fields and dStrikePrice in MbtOrderClient.Submit():
' -------------------------------------------------------------------------------------------------------
' Please note, timeActivate and timeExpire are NOT used yet. Just pass a NULL or blank
'
double dStrikePrice = 0;
COleDateTime dDte;
VARIANT_BOOL bSubmit = m_pOrderClient->Submit(
    lBuySell, lVol, _bstr_t(sSym), dPrice, 0, lTIF, 0, lOrdType,
    lVolType, 0, m_pDefaultAccount, _bstr_t(sRoute), "", 0, 0,
    dDte, ' NOT used yet. Just pass a NULL or blank
    dDte, ' NOT used yet. Just pass a NULL or blank
    0, 0,
    dStrikePrice,
    0, 0,
    &bstrRetMsg
);

' C# - new timeActivate, timeExpire date fields and dStrikePrice in MbtOrderClient.Submit():
' -------------------------------------------------------------------------------------------------------
' Please note, timeActivate and timeExpire are NOT used yet. Just pass a NULL or blank
'
System.DateTime dDte = new System.DateTime(0);
bool bSubmit = m_OrderClient.Submit()(
    lBuySell, lVol, sSym, dPrice, 0.0, lTIF, 0, lOrdType,
    lVolType, 0, m_DefaultAccount, sRoute, "", 0, 0,
    dDte, ' NOT used yet. Just pass a NULL or blank
    dDte, ' NOT used yet. Just pass a NULL or blank
    0, 0,
    dStrikePrice,
    0, 0, ref bstrRetMsg
);

MbtOrderClient contains one new Boolean parameter and two new events. MbtOrderClient.OnDemandMode controls whether the order history is initially loaded for each account. If you set this Boolean to True, you must manually load each account (MbtAccount.Load) you wish to manipulate in any way. If you set this property to False, or if you set it to True and fail to preload the account(s) (see snippet below), you will experience, among other symptoms, errors such as entered orders not being acknowledged. The two new events report progress of loading accounts.

' VB6 - example showing grabbing reference to the MbtOrderClient object, setting
' the new OnDemandMode flag to True, and forcing the loading of all accounts:
' -------------------------------------------------------------------------------------------------------
Set oOrders = oComMgr.OrderClient
oOrders.OnDemandMode = True ' False to have all accounts automatically loaded

' Load each account upon MbtOrderClient.OnLogonSucceed firing:
Private Sub oOrders_OnLogonSucceed()
    Dim oAct As MbtAccount, oActs As MbtAccounts
    Set oActs = oOrders.Accounts
    ' For-Each internally locks the collection; For-Next does not!
    For Each oAct In oActs
        oAct.Load
    Next
End Sub

' Typically fires immediately after executing the MbtAccount.Load method.
Private Sub oOrders_OnAccountLoading(ByVal pAcct As MBTORDERSLib.IMbtAccount)
    Debug.Print "OnAccountLoading! " & pAcct.Account
End Sub

' Typically fires when the MbtAccount has been fully loaded and is ready for use.
Private Sub oOrders_OnAccountLoaded(ByVal pAcct As MBTORDERSLib.IMbtAccount)
    Debug.Print "OnAccountLoading! " & pAcct.Account
End Sub

MbtOrderClient also contains two new events that report failure of order cancel and order replace requests:

' VB6 - new MbtOrderClient events indicate failure to cancel or change an order
' -------------------------------------------------------------------------------------------------------
Private Sub oOrders_OnCancelRejected(ByVal pOrd As MBTORDERSLib.IMbtOpenOrder)
    Debug.Print "OnCancelRejected! " & pOrd.Account.Account
End Sub

Private Sub oOrders_OnReplaceRejected(ByVal pOrd As MBTORDERSLib.IMbtOpenOrder)
    Debug.Print "OnReplaceRejected! " & pOrd.Account.Account
End Sub


I m p o r t a n t   N o t e s

There is only one installer and it installs the retail Navigator and the SDK, for equities, futures and forex, and for live and demo accounts. There is no other installer.
While installing the Navigator, CLOSE YOUR IDE and any projects that may be running (check your Task Manager to be sure)! A development platform typically locks up Navigator components. Failure to do so may result in incomplete installations, whether or not errors are reported visibly. A typical error will refer to the inability to update MbtCommon.dll.
Never manually register any Navigator dll. And, uninstalling / reinstalling is not typically needed when upgrading to a newer version.
A login (username/password pair) can only be in use with one instance of the Navigator (retail Navigator or SDK project) at a time. Logging in to a second instance will either simply fail with no message at all, or give you the message "Login rejected for reason: Somebody logged in as you"
The Object Browser within the VB IDE (function key F2) is very useful in showing you all members of COM objects (in case we missed on in our documentation).
Always UCase() the ticker symbol in any project. If you pass other than an upper case symbol in MbtOrderClient.Submit or .Replace (or possibly while iterating positions), ibm <> IBM and CsCo <> cScO. This can easily result in a "Sell 100 msft" (lower case "msft") being converted automatically by our servers to a "Sell Short" because it insists that you do not own the stock.
Do not use VALUE_DAYPLUS when using the MBTX route in your MbtOrderClient.Submit() method. Use VALUE_DAY instead; otherwise you'll see an "Invalid TimeInForce" error.
Forex orders must always use VALUE_GTC or you will see an "Invalid TimeInForce" error.
For forex orders, Enter 1000 for 1,000 forex shares, or 10000 for a "mini" lot, or 100000 for a "regular" lot (by comparison; in the Navigator, you must enter 0.1 for 1,000 forex shares, but only if Preferences / General / "Use lots for forex quote/order" is unchecked).
The native (retail) Navigator is a 32-bit platform (API) but works fine with Vista and 64-bit operating systems. BUT, be sure to set your SDK project for "x86" and NOT "AnyCPU" or "x64" as your project must be compiled or built as a 32-bit executable -- Project / [projectname] Properties / Compile / Advanced Compile Options / Target CPU: / x86
Automation (connecting to a running instance of the Navigator) is not possible. Also, please read the "Multiple Logins.txt" file in the samples collection where it discusses the use of logins (a login is only allowed to be in use once).
Forex demo data *closely* approximates live data, but not exactly. Demo forex and equity quote data should never be used for live trading.
Always try to pass event handlers' objects to external Subs and Functions. This holds true for timer handlers, too. See the following Yahoo SDK forum posts: 2434, 2515 and 3543
-- E O F --