You are on page 1of 39

API documentation for Mflib.

dll
http://meta-all.sourceforge.net/

Table of Contents
License.......................................................................................................................................................4 Introduction................................................................................................................................................4 Background................................................................................................................................................4 Class Overview..........................................................................................................................................6 How to Add Mflib.dll to my Project..........................................................................................................8 Reference w/o Source Code..................................................................................................................8 Reference w/ Source Code..................................................................................................................10 PortfolioGroup.........................................................................................................................................14 Methods...............................................................................................................................................14 Public Sub add(ByVal Path As String, ByVal IsExisting As Boolean)..........................................14 Public Sub add(ByRef portf As MFLib.Portfolio).........................................................................14 Properties.............................................................................................................................................15 Public ReadOnly Property Portfolio(ByVal index As Integer) As MFLib.Portfolio......................15 Public ReadOnly Property Portfolio(ByVal dir As String) As MFLib.Portfolio............................15 Public ReadOnly Property Count() As Integer...............................................................................15 Portfolio...................................................................................................................................................17 Methods...............................................................................................................................................18 Public Sub New(ByVal Path As String, ByVal IsExisting As Boolean, Optional ByVal AdjustForSplits As Boolean = False).............................................................................................18 Public Function NewSecurity(ByVal Symbol As String, ByVal Desc As String, ByVal StartDate As Date) As MFLib.Metafile..........................................................................................................18 Public Sub Save(Optional ByVal path As String = "", Optional ByVal CreateDir As Boolean = False)..............................................................................................................................................18 Public Function Exists(ByVal symbol As String) As Boolean.......................................................19 Public Function FindSecurityByName(ByVal name As String) As Integer...................................19 Public Function FindSecurityBySymbol(ByVal symbol As String) As Integer.............................20 Public Sub Delete(ByVal index As Integer)...................................................................................20 Public Sub Delete(ByVal symbol As String)..................................................................................20 Public Function Update(Optional ByVal UseThreading As Boolean = True) As Long.................21 Public Sub StopUpdate()................................................................................................................21 Properties.............................................................................................................................................21 Public Property DataProvider(ByVal DataSource As Object) As MFLib.DataProviders.Service. 21 Public ReadOnly Property Path() As String...................................................................................22 Public ReadOnly Property QuotesUpdated() As Long...................................................................22 Public ReadOnly Property Security(ByVal index As Integer) As MFLib.Metafile........................23 Public ReadOnly Property Security(ByVal symbol As String) As MFLib.Metafile......................23 Public ReadOnly Property SecurityCount() As Integer..................................................................23 Public Property ThreadCount() As Integer.....................................................................................24 Public ReadOnly Property UpdatePercentage() As Decimal..........................................................24 Public ReadOnly Property UpdatingSecurities() As String().........................................................24 Public Property Use20Min() As Boolean.......................................................................................25 Metafile....................................................................................................................................................26 Methods...............................................................................................................................................27 Public Function AddQuote(ByVal QDate As String, ByVal QClose As Single, ByVal QHigh As Single, ByVal QLow As Single, ByVal QOpen As Single, ByVal QInterest As Single, ByVal QVolume As Single) As Object......................................................................................................27 Public Function AddQuote(ByVal QDate As String, ByVal QTime As Single, ByVal QClose As Single, ByVal QHigh As Single, ByVal QLow As Single, ByVal QOpen As Single, ByVal QInterest As Single, ByVal QVolume As Single) As Object..........................................................27

Public Sub LoadQuotes()................................................................................................................28 Public Function RecordNumber() As Integer.................................................................................28 Public Sub Save(Optional ByVal OverrideLocks As Boolean = True, Optional ByVal SaveTo As String = "")......................................................................................................................................28 Public Sub Sort(ByRef DeleteDuplicates As Boolean)..................................................................29 Public Sub UnloadQuotes()............................................................................................................29 Public Function Update(ByVal Service As MFLib.DataProviders.Service, ByVal AdjustSplits As Boolean, ByVal Delayed20min As Boolean) As Long...................................................................29 Properties.............................................................................................................................................30 Public ReadOnly Property CountQuotes() As Object....................................................................30 Public ReadOnly Property FileName() As String...........................................................................30 Public ReadOnly Property GetName() As String...........................................................................30 Public ReadOnly Property GetQuote(ByVal Qdate As Date) As MFLib.Quote............................31 Public ReadOnly Property GetQuote(ByVal index As Integer) As MFLib.Quote.........................31 Public ReadOnly Property GetSymbol() As String........................................................................31 Public ReadOnly Property HasDelayed() As Object......................................................................31 Public ReadOnly Property IsUpToDate() As Boolean...................................................................32 Public ReadOnly Property QuotesAreLoaded() As Boolean..........................................................32 Appendix A - MASTER...........................................................................................................................34 Appendix B - EMASTER........................................................................................................................35 Appendix C - XMASTER........................................................................................................................37 Appendix D F*.DAT (or F*.MWD)......................................................................................................39

License
This work is licensed under the Creative Commons Attributions-NonCommerical-ShareAlike 2.5 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/2.5/deed.en

Introduction
The purpose of this document is to provide the user/developer with an understanding of the classes used in the DLL. The Document will try to show examples and use scenarios to help budding programmers learn the MFLib.dll to create their own applications. The Document will also try to provide a high level view of the DLL to give experienced developers a better understanding of the code and the opportunity to contribute to the project instead of trying to wade through the code.

Background
The main function of the DLL is to provide the ability to read and write to the Metastock/Computrac file format. In a Metastock directory it is likely that there will be several different files. The following files may be present in the directory.

MASTER EMASTER XMASTER(only if there are more than 255 security records) F*.DAT files(or F*.WMD where * is greater than 255)

First lets discuss these files, and what they are. MASTER The MASTER files contains a list of securities and information about the securities, as well as the index number for the DAT file which contains all the quote information for a respective security. This file can contain up to 255 securities. See the masterfiledescriptor.vb file and/or Appendix A for further detail on the construction of this file. EMASTER The EMASTER files contains the same list of securities as in the MASTER file, with some additional information, that the MASTER does not provide. See the emasterfiledescriptor.vb file and/or Appendix B for further detail on the construction of this file. XMASTER The XMASTER file contains a list of securities and information about the securities similar to the EMASTER. The XMASTER is used to store securities from index number 256 and up to 65535. This file automatically gets created when a new security needs to

get added and the MASTER and EMASTER files are full. See the xmasterfiledescriptor.vb file and/or Appendix C for further detail on the construction of this file. F*.DAT The F*.DAT file where * is the index number as defined in the MASTER/EMASTER or XMASTER file is the data file that stores the quotes for a particular security. See the Appendix D for further detail on the construction of this file.

Class Overview

The above class diagram gives a basic functional hierarchy of the MFLib.dll and its functionality. PortfolioGroup class is an object for holding multiple Portfolios. Portfolio class pertains to an object that holds all or most of the data pertaining to a particular Metastock directory. Metafile class is an object for holding information about a particular security Therefore a Portfolio Object can contain many MetaFile Objects. Where the Portfolio object contains the list of all the securities(as defined by the MASTER, EMASTER and XMASTER files) and the Metafile objects contain all the information pertaining to those securities which is a combination of security configuration defined in the MASTER files and the Quote data as defined by the F*.DAT files.

The Purpose of the PortfolioGroup object is to house multiple Metastock directories/Portfolio Objects, which gives the developer the ability to load, read, write, update and manipulate multiple sets of data. Under the Metafile class are several helper type classes and objects. The Quote Classes are used to retrieve quote data from particular websites. The Quote object is used to hold the quote data. Where each quote object contains a public varible for Date, Time, Open, High, Low Close, Volume and Open Interest which can be used as required. The Fields Class holds the information received from the EMASTER or XMASTER pertaining to the Securities configuration information, whether the security has a time field or Open Interest Field etc. The SUTC class provides the Multi threading, which is actually used by the Portfolio class to call the Metafile functions. The FileRecord and FileDescriptor classes are used to define how the MASTER, EMASTER and XMASTER are configured and how the data is read. The Functions Module contains many low level functions for reading and writing to files, performing common math functions, and for creating byte arrays required for writing to files. The Symbol List Classes are used to define how the Metastock symbol list files are configured and how the data is read.

How to Add Mflib.dll to my Project


Prior to Starting it is probably best to download the latest copy of the source code. First create a new .NET project or open an existing .NET project.

Reference w/o Source Code


If you are only interested in using the API and are not interested in the underlying code in the API follow these directions for adding the DLL to the project. Right click on your solution in the solution explorer and select properties.

With the Properties tab open select the references button on the left side.

Next click on the Add->Reference button.

Once the Add Reference file dialog is open click on the browse tab and locate the mflib.dll. This can either be found in the source code that is downloaded or with the Meta-All installation, under program files.

Then click OK. Mflib.dll should now be listed as a reference and you can begin coding.

Reference w/ Source Code


To add the mflib.dll code to your project follow the procedure below. With your application open, click File - > Add - > Existing Project on the file menu.

Locate the Mflib.vproj file and click open.

The MFLib.dll project will now be visible in the solution explorer window. Right click on the windows application in the solution explorer and click on properties.

When the Properties tab open select references on the left side of the properties tab.

Next click on the Add->Reference button.

With the add Reference File dialog open click on the Projects tab, and select Mflib.

Then click the OK button.Mflib.dll should now be listed as a reference and you can begin coding.

Please feel free to contribute code changes ;)

PortfolioGroup
The PortfolioGroup resides in the PortfolioHolder.vb file. The function of the PortfolioGroup is to hold an array of Metastock Portfolios where a Portfolio consists of a Metastock Directory.
PortfolioGroup
C lass

Fields tab Properties Count Portfolio (+ 1 not Methods add (+ 1 overload) Remove

Methods
Public Sub add(ByVal Path As String, ByVal IsExisting As Boolean) Member of: MFLib.PortfolioGroup Summary: Creates and adds a Portfolio to the Portfolio Group. Parameters: path: The file or directory where Metastock Data Located (MASTER/EMASTER and XMASTER ) IsExisting: True if the directory contains Metastock Data, false if new files need to be created Return Values: none.

Example:
Dim PFG As New MFLib.PortfolioGroup PFG.add("C:\MetaStock Data\Index\", True)

Public Sub add(ByRef portf As MFLib.Portfolio) Member of: MFLib.PortfolioGroup Summary: Adds a existing Portfolio to the Portfolio Group. Parameters: portf : The existing portfolio object to be added to the PortfolioGroup Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim PFG As New MFLib.PortfolioGroup PFG.add(PF)

Properties
Public ReadOnly Property Portfolio(ByVal index As Integer) As MFLib.Portfolio Member of: MFLib.PortfolioGroup Summary: Returns a Portfolio object specified by index number for the given PortfolioGroup. Parameters: index : The index number of the Portfolio within the PortfolioGroup. Return Values: Returns a Portfolio Object.

Example:
Dim PFG As New MFLib.PortfolioGroup PFG.add("C:\MetaStock Data\Index\", True) PFG.add("C:\MetaStock Data\Test\", True) Dim PF As MFLib.Portfolio PF = PFG.Portfolio(1)

Public ReadOnly Property Portfolio(ByVal dir As String) As MFLib.Portfolio Member of: MFLib.PortfolioGroup Summary: Returns a Portfolio object specified by the directory for the Portfolio in a given PortfolioGroup. Parameters: dir : The directory of the Portfolio within the PortfolioGroup. Return Values: Returns a Portfolio Object.

Example:
Dim PFG As New MFLib.PortfolioGroup PFG.add("C:\MetaStock Data\Index\", True) PFG.add("C:\MetaStock Data\Test\", True) Dim PF As MFLib.Portfolio PF = PFG.Portfolio("C:\MetaStock Data\Test\")

Public ReadOnly Property Count() As Integer Member of: MFLib.PortfolioGroup Summary: Returns an integer count on the number of Portfolios in the Portfolio Group. Parameters: none. Return Values: Returns a Integer.

Example:
Dim PFG As New MFLib.PortfolioGroup PFG.add("C:\MetaStock Data\Index\", True) PFG.add("C:\MetaStock Data\Test\", True) Dim iCount As Integer iCount = PFG.Count

Portfolio
The portfolio code resides in the portfolio.vb file. The function of the Portfolio object to house the data pertaining to a particular Metastock data directory. This would consist of the MASTER/EMASTER/XMASTER data file information and an array of Metafile Objects which contain the security information.
Portfolio
C lass

Fields AdjustSplits DefaultService dir MaxThreads SecCount SecUpd Stocks UCount UDone URunning Use20Minutes UThread Properties DataProvider Path QuotesUpdated Security (+ 1 not SecurityCount ThreadCount UpdatePercentage UpdatingSecurities Use20Min Methods Delete (+ 1 overl Exists FindSecurityByNa FindSecurityBySy New NewSecurity Save StopUpdate Update UpdateThreaded

Methods
Public Sub New(ByVal Path As String, ByVal IsExisting As Boolean, Optional ByVal AdjustForSplits As Boolean = False) Member of: MFLib.Portfolio Summary: Creates a Portfolio Object, reads the MASTER,EMASTER and XMASTER, stores pertinent information in private variables, and then builds the Metafile objects from the data found in the master files and stores them as part of the portfolio Object. Parameters: path: The file or directory where Metastock Data Located (MASTER/EMASTER and XMASTER ) IsExisting: True if the directory contains Metastock Data, false if new files need to be created.

AdjustForSplits: True if the user would like to use split adjusted data from Yahoo
Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True)

Public Function NewSecurity(ByVal Symbol As String, ByVal Desc As String, ByVal StartDate As Date) As MFLib.Metafile Member of: MFLib.Portfolio Summary: Creates a MetaFile object, appends it to the Portfolio Object. The function also writes the appropriate security data to the MASTER/EMASTER or XMASTER file. Parameters: Symbol: The String to be used for the Security Symbol Desc: The String to be used for the Security Description.

StartDate: The Date used to define when the first quote date should be. Is used when downloading data. Though the startdate could be defined as 1/1/1900, data may not be available, but the date will not affect the data.
Return Values: returns a Metafile object.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim MySec As MFLib.Metafile MySec = PF.NewSecurity("YHOO", "Yahoo Security", New Date(1900, 1, 1))

Public Sub Save(Optional ByVal path As String = "", Optional ByVal CreateDir As Boolean = False) Member of: MFLib.Portfolio Summary: The Save function saves all the security data received. The Save function essential uses the MetaFile Object save function to update each each security. It updates the MASTER/EMASTER or XMASTER and stores any Quote data into the appropriate F*.DAT file. Optionally it can be used to save all the files to a new directory. This function would be useful after manually adding multiple quotes to various securities.

Alternately the Metafile.vb Save method could be used to save each individual security. Parameters: path: (Optionally) The file or directory where Metastock Data is to be Saved (MASTER/EMASTER and XMASTER ) CreateDir: True if the directory needs to be created. Return Values: none.

Example:
''Save the Security Data for a given Portfolio. This adds the quote to the first Security and the Second Security ''A Security Index number is being used or a Symbol as shown in the example below. Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security(YHOO).AddQuote(New Date(1900, 1, 1), 1, 2, 1, 1, 0, 10000) PF.Security(GOOG).AddQuote(New Date(1900, 1, 1), 1, 2, 1, 1, 0, 10000) PF.Save()

Public Function Exists(ByVal symbol As String) As Boolean Member of: MFLib.Portfolio Summary: Given a ascii symbol the Exist function checks the portfolio for a security with a matching symbol. If a Security with a matching symbol is found, the function returns a boolean True. Parameters: symbol: The symbol to search for in the current Portfolio. Return Values: returns a boolean true if a security with a matching symbol is found.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim IsMySymExist As Boolean IsMySymExist = PF.Exists("YHOO")

Public Function FindSecurityByName(ByVal name As String) As Integer Member of: MFLib.Portfolio Summary: Searches through the descriptions of the all the securities in the Portfolio for a match. If a match is found the function returns the index number of the security. Parameters: name: The Ascii String used in the search through security descriptions. Return Values: Returns the Index of the security held in the Portfolio if a match is found. If nothing is found returns -1.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim WhatIsMySecIndexNum As Integer WhatIsMySecIndexNum = PF.FindSecurityByName("YAHOO")

Public Function FindSecurityBySymbol(ByVal symbol As String) As Integer Member of: MFLib.Portfolio Summary: Searches through the Symbols of the all the securities in the Portfolio for a match. If a match is found the function returns the index number of the security. Parameters: symbol: The Ascii Symbol used in the search through the securities in the Portfolio. Return Values: Returns the Index of the security held in the Portfolio if a match is found. If nothing is found returns -1.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim WhatIsMySecIndexNum As Integer WhatIsMySecIndexNum = PF.FindSecurityBySymbol("YHOO")

Public Sub Delete(ByVal index As Integer) Member of: MFLib.Portfolio Summary:

Permanently deletes the security from the Portlio, MASTER/EMASTER or XMASTER given an index number.
Parameters: index: The index number of the security to be deleted. Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Delete(1)

Public Sub Delete(ByVal symbol As String) Member of: MFLib.Portfolio Summary:

Permanently deletes the security from the Portlio, MASTER/EMASTER or XMASTER given an Ascii Symbol.
Parameters: symbol: The Symbol of the security to be deleted. Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Delete("YHOO")

Public Function Update(Optional ByVal UseThreading As Boolean = True) As Long Member of: MFLib.Portfolio Summary: The update function updates the securities in the Portfolio using one of the available DataProviders as defined in the DataProviders.vb file. The Update function cycles through the Securities in the Portfolio by downloading the data, updating the master files, and then updating the Quote Data. The Function allows the user to optionally disable the Threading and perform the update sequentially. By Default the Update function performs the update in a multi-threaded fashion. Prior to using the Update function be sure to assign the right dataprovider to the Portfolio. Parameters: UseThreading: (Optional)True by default. If set to false the securities will be updated in a sequential fashion. Return Values: Returns a Long containing the total Number of Quotes added to all the securities.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myDataProviderService As MFLib.DataProviders.Service Dim NumOfQuotesAdded As Long myDataProviderService = MFLib.DataProviders.Service.BSEEOD 'Set the Service to BSEEOD PF.DataProvider(0) = myDataProviderService 'Set the Portfolio Service to BSEEOD NumOfQuotesAdded = PF.Update(True) 'Update all the securities in the Portfolio

Public Sub StopUpdate() Member of: MFLib.Portfolio Summary: Cleanly Halts the Update process by waiting for the current threads running to complete. Parameters: none. Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myDataProviderService As MFLib.DataProviders.Service Dim NumOfQuotesAdded As Long myDataProviderService = MFLib.DataProviders.Service.BSEEOD 'Set the Service to BSEEOD PF.DataProvider(0) = myDataProviderService 'Set the Portfolio Service to BSEEOD NumOfQuotesAdded = PF.Update(True) 'Update all the securities in the Portfolio PF.StopUpdate() 'Halts the Update Process

Properties
Public Property DataProvider(ByVal DataSource As Object) As MFLib.DataProviders.Service Member of: MFLib.Portfolio

Summary: Its important to set this property prior to running the portfolio update function. This sets the Data provider property in the Portfolio Object which tells the security update function where to retrieve the data from. This property can also return DataProvider. Parameters: DataSource. - Set to 0 Return Values: Will return the DataProvider service for the portfolio.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myDataProviderService As MFLib.DataProviders.Service PF.DataProvider(0) = MFLib.DataProviders.Service.BSEEOD 'set the Data Provider as BSEEOD myDataProviderService = PF.DataProvider(0) 'Get the Function to return the DataProvider

Public ReadOnly Property Path() As String Member of: MFLib.Portfolio Summary: This is a readonly property which can be used to retrieve the path of the current portfolio. Parameters: none. Return Values: Returns the Portfolio File Path.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim WhatisthePath As String WhatisthePath = PF.Path 'Should return "C:\MetaStock Data\Index\"
Public ReadOnly Property QuotesUpdated() As Long Member of: MFLib.Portfolio Summary: The QuotesUpdated function returns the current number of quotes added to the securities that have been updated. This number reflects all securities during that update process that have completed their update process. This can be used in a Timer to process and number of quotes entered. Parameters: none. Return Values: Returns a Long reflecting all quotes added across all securities that have been completed.

Example:
'This shows an example of a timer which updates the text in a Label with QuotesUpdated Value 'Start this timer before the Update Function is called, stop the timer when PF.UpdatePercentage = 1 using a while loop Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick lblQuotesDown.Text = PF.QuotesUpdated End Sub

Public ReadOnly Property Security(ByVal index As Integer) As MFLib.Metafile Member of: MFLib.Portfolio Summary: This function returns the Metafile object for a particular security in the portfolio Object given an Index Number. This Property can also be used to access the Metafile objects methods and properties. Parameters: index. The function requires an index number for the Metafile object. Return Values: Returns the Metafile object or provides access to the Metafile objects methods and properties.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim SecTimeFrame As String 'Method 1 Dim mySecurity As MFLib.Metafile mySecurity = PF.Security(0) SecTimeFrame = mySecurity.TimeFrame 'Method 2 (prefered Method) SecTimeFrame = PF.Security(0).TimeFrame
Public ReadOnly Property Security(ByVal symbol As String) As MFLib.Metafile Member of: MFLib.Portfolio Summary: This function returns the Metafile object for a particular security in the portfolio Object given an Ascii Symbol String. This Property can also be used to access the Metafile objects methods and properties. Parameters: symbol . The function requires a Symbol for the Metafile Object. Return Values: Returns the Metafile object or provides access to the Metafile objects methods and properties.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim SecTimeFrame As String 'Method 1 Dim mySecurity As MFLib.Metafile mySecurity = PF.Security(YHOO) SecTimeFrame = mySecurity.TimeFrame 'Method 2 (prefered Method) SecTimeFrame = PF.Security(YHOO).TimeFrame

Public ReadOnly Property SecurityCount() As Integer Member of: MFLib.Portfolio Summary: The SecurityCount Property is a readonly property that returns the number of securities stored in the Portfolio object as metafile objects. Parameters: none. Return Values: This Property returns an Integer as the number of Securities in the Portfolio.

Example:

Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim howManySec As Integer howManySec = PF.SecurityCount

Public Property ThreadCount() As Integer Member of: MFLib.Portfolio Summary: This property can be used to set or get the number of threads to be used when running the Update function in multithreaded mode. Parameters: none. Return Values: Returns an integer indicating the number of threads being used by the update function.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim NumOfQuotesAdded As Long PF.DataProvider(0) = MFLib.DataProviders.Service.BSEEOD PF.ThreadCount = 6 'Set the number of threads to 6 NumOfQuotesAdded = PF.Update(True) 'Update all the securities in the Portfolio Dim howManyThreads As Integer howManyThreads = PF.ThreadCount 'Read back the number of threads

Public ReadOnly Property UpdatePercentage() As Decimal Member of: MFLib.Portfolio Summary: This readonly proper returns a decimal value indicating the % completion of the update process. Parameters: none. Return Values: returns % complete in decimal form.

Example:
'This shows an example of a timer which updates the text in a Label with UpdatePercentage Value 'Start this timer before the Update Function is called, stop the timer when PF.UpdatePercentage = 1 using a while loop Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick lblUpdatePercentage.Text = PF.UpdatePercentage End Sub
Public ReadOnly Property UpdatingSecurities() As String() Member of: MFLib.Portfolio Summary: This property returns an array of symbols (stings()) that are currently being updated by the update function while running multithreaded. Parameters: none. Return Values: Returns an Array of strings.

Example:
'This shows an example of a timer which updates the text in a Label with Symbols of the Securities being updated 'Start this timer before the Update Function is called, stop the timer when PF.UpdatePercentage = 1 using a while loop 'This shows a loop to build a comma delimited string of the symbols to post in a label on the form Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick Dim temp() As String = PfG.Portfolio(GblPortfolioIndex).UpdatingSecurities If (Not (temp Is Nothing)) Then lblSecurity.Text = "" Dim i As Integer For i = 0 To temp.Length - 1 Step 1 If (temp(i) <> "") Then If (lblSecurity.Text = "") Then lblSecurity.Text = temp(i) Else lblSecurity.Text = lblSecurity.Text & "," & temp(i) End If End If Next End If End Sub
Public Property Use20Min() As Boolean Member of: MFLib.Portfolio Summary: The Use20Min property is used to get or set a boolean which tells the Update function whether to use 20minute delayed data when updating a security. This can be useful as often times Yahoo is extremely slow at updating their EOD Data. The Update function will replace the 20min data stored from previous days with proper EOD data that it downloads. This should be set prior to running the Update function. Parameters: none. Return Values: Returns the Boolean value for determining whether the portfolio update uses 20min quotes.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim WhatsMyUse20min As Boolean Dim NumOfQuotesAdded As Long PF.DataProvider(0) = MFLib.DataProviders.Service.BSEEOD 'Set the Service to BSEEOD PF.Use20Min = True 'Set Use20min delay quotes to True NumOfQuotesAdded = PF.Update(True) 'Update all the securities in the Portfolio WhatsMyUse20min = PF.Use20Min 'Get boolean value of Use20Min

Metafile
The purpose of the Metafile object is store and hold data specific to a security. Any data related to the security which was stored in the MASTER/EMASTER or XMASTER will be stored in the securities Metafile Object. The Metafile object is also responsible for updating and managing the Quote Data. Though an individual Metafile object can be created and used it seems to make more logical sense to interact with the Metafile objects housed within a portfolio Object.

Metafile
C lass

Fields AutoRun DataLoaded DefaultService FDate File FileNum FileType FirstDateLng Has20Minute IDATime IsX LastUpdQuoteCo LastVolume LDate Name Quotecount QuoteData RecCount RecLen RecNumber Starttime Stoptime StoredFields Symbol TimeFrame v28 Properties CountQuotes FileName GetName GetQuote (+ 1 n GetSymbol HasDelayed IsUpToDate LastUpdateQuote QuotesAreLoaded Methods AddQuote (+ 1 o Delete LoadQuotes New (+ 4 overloa RecordNumber Save Se tLDateFromQu Sort UnloadQuotes Update

Methods
All examples shown will access the Metafile objects through the portfolio Object.
Public Function AddQuote(ByVal QDate As String, ByVal QClose As Single, ByVal QHigh As Single, ByVal QLow As Single, ByVal QOpen As Single, ByVal QInterest As Single, ByVal QVolume As Single) As Object Member of: MFLib.Metafile Summary: This Method adds a EOD quote to a Security Metafile Object. The quote data must be specified as the parameters of the function. The Metafile Save Method must be called after the addquote function is called in order to save the data to the security files. Parameters: QDate . The date must be a string in the following format MM/DD/YYYY. QClose . The Close parameter is the closing value for the security on the specified date. QHigh . The High parameter is the Daily high for the security on the specified date. QLow . The Low parameter is the Daily Low for the security on the specified date. QOpen . The open parameter is the Open value of the security on the specified date. QInterest .The Interest Parameter is the Open Interest of a commodity on the specified date. QVolume . The volume Parameter is the Volume of the security on the specified date.. Return Values: Returns 1 if the quote is added and 0 if the quote is not added.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security("YHOO").AddQuote("12/25/2007", 900, 1200, 300, 100, 0, 1000000) PF.Security("YHOO").Save() 'Save the Data to the F*.dat and MASTER/EMASTER or XMASTER
Public Function AddQuote(ByVal QDate As String, ByVal QTime As Single, ByVal QClose As Single, ByVal QHigh As Single, ByVal QLow As Single, ByVal QOpen As Single, ByVal QInterest As Single, ByVal QVolume As Single) As Object Member of: MFLib.Metafile Summary: This Method adds a Intraday quote to a Security Metafile Object. The quote data must be specified as the parameters of the function. The Metafile Save Method must be called after the addquote function is called in order to save the data to the security files. Parameters: QDate . The date must be a string in the following format MM/DD/YYYY. QTime . The Time must be provided as a Single. Eg 9:30am is 930, Eg. 4Pm is 1600 QClose . The Close parameter is the closing value for the security on the specified date. QHigh . The High parameter is the Daily high for the security on the specified date. QLow . The Low parameter is the Daily Low for the security on the specified date. QOpen . The open parameter is the Open value of the security on the specified date. QInterest .The Interest Parameter is the Open Interest of a commodity on the specified date. QVolume . The volume Parameter is the Volume of the security on the specified date.. Return Values: Returns 1 if the quote is added and 0 if the quote is not added..

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security("YHOO").AddQuote("12/25/2007", 930, 900, 1200, 300, 100, 0, 1000000) PF.Security("YHOO").Save() 'Save the Data to the F*.dat and MASTER/EMASTER or XMASTER

Public Sub LoadQuotes() Member of: MFLib.Metafile Summary: The LoadQuotes function loads the quotes for the Metafile Security into memory. By default the quotes are not loaded into the Metafile Object. Calling this function will load the Quotes into the Metafile Object, allowing the user to read all the quotes out of the Metafile object for a particular security. When the Quotes are no longer loaded it is good practice to call the UnloadQuotes function to free the memory that the application is utilizing. Parameters: none. Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security("YHOO").LoadQuotes()

Public Function RecordNumber() As Integer Member of: MFLib.Metafile Summary: The RecordNumber function returns the record number as defined by the MASTER/EMASTER or XMASTER file. The Record number can then be used to locate F#.dat file where # represents the record number Parameters: none. Return Values: Returns an Integer which represents the Record Number for specified Security.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security(2).RecordNumber()

Public Sub Save(Optional ByVal OverrideLocks As Boolean = True, Optional ByVal SaveTo As String = "") Member of: MFLib.Metafile Summary: The Save Function updates the MASTER/EMASTER or XMASTER with the appropriate last date, and writes any quotes that have been added to the quotes in memory to the F#.dat file for that particular security. Parameters: OverrideLocks . - Writes to the files even if Metastock has the files locked. SaveTo . - Writes to the quote data to an alternate location if a master file exists. Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security("YHOO").AddQuote("12/25/2007", 900, 1200, 300, 100, 0, 1000000) PF.Security("YHOO").Save() 'Save the Data to the F*.dat and MASTER/EMASTER or XMASTER

Public Sub Sort(ByRef DeleteDuplicates As Boolean) Member of: MFLib.Metafile Summary: The Sort Function, loads all quotes into memory, and then sorts them by date and time. If the Parameter DeleteDuplicates is set to true, any duplicate date/ time entries will be removed. Parameters: DeleteDuplicates . - noneSet to True to delete duplicate date/ time entries . Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security(2).Sort(True) PF.Security(2).Save()
Public Sub UnloadQuotes() Member of: MFLib.Metafile Summary: The UnloadQuotes function unloads the quotes from memory for the respective Metafile Object.This function should be used when the quote data for the Metafile object is no longer need in memory. Parameters: none. Return Values: none.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myquote As MFLib.Quote PF.Security("YHOO").LoadQuotes() myquote = PF.Security("YHOO").GetQuote(0) 'Get the first quote in the data file PF.Security("YHOO").UnloadQuotes()

Public Function Update(ByVal Service As MFLib.DataProviders.Service, ByVal AdjustSplits As Boolean, ByVal Delayed20min As Boolean) As Long Member of: MFLib.Metafile Summary: The Metafile Update function updates an individual security metafile object with EOD or Intraday backfill data. A data provider must be specified in the parameters to indicate where the source of the data will come from. AdjustSplits parameters indicates that when using Yahoo EOD data use the data that has already been adjusted for splits. The delayed 20 min parameter indicates that 20min data is to be used if the EOD data is not available yet. The last two Data records are always over written with EOD data to prevent having 20min delayed data in the data files. Rerunning this function using 20min delayed data will updated the last record with the lastest 20min delayed data that was downloaded. To permanently save the data to file the Save function must be called after the update function. Parameters: Service . - This parameter indicates what the source of the data should be. AdjustSplits . - The AdjustSplits parameter indicates that when using Yahoo EOD data that the data adjusted for stock splits should be used.. Delayed20min . - This parameter indicates that 20min delayed data should be used if EOD data is not available. Return Values:

Returns the number of quotes added to the Data Record.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security("YHOO").Update(MFLib.DataProviders.Service.YahooEOD, True, True) PF.Security("YHOO").Save(True)

Properties
Public ReadOnly Property CountQuotes() As Object Member of: MFLib.Metafile Summary: The CountQuotes Property returns the number of quotes that a specific security has stored in its F#.dat file. Parameters: none. Return Values: Returns the Length of the Quote Array.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim whatsNumofQuotes As Integer whatsNumofQuotes = PF.Security("YHOO").CountQuotes

Public ReadOnly Property FileName() As String Member of: MFLib.Metafile Summary: The FileName Property returns the F#.dat file filename in that format. Eg wil return F1.dat. Parameters: none. Return Values: Returns the filename for the security which holds the securities quote data.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myfilenamestore As String myfilenamestore = PF.Security("YHOO").FileName

Public ReadOnly Property GetName() As String Member of: MFLib.Metafile Summary: The GetName property returns the description of the security as provided when the security was created.. Parameters: none. Return Values:

Returns a string value which is the description of the security.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim mysecDescription As String mysecDescription = PF.Security("YHOO").GetName

Public ReadOnly Property GetQuote(ByVal Qdate As Date) As MFLib.Quote Member of: MFLib.Metafile Summary: This GetQuote Property returns the quote specified by the date passed in by the parameter. Parameters: Qdate . - The Date of the quote specified to be returned. Return Values: Returns a Quote object.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myquote As MFLib.Quote PF.Security("YHOO").LoadQuotes() myquote = PF.Security("YHOO").GetQuote(New Date(1900, 1, 1)) 'Get the quote with date 1/1/1900 PF.Security("YHOO").UnloadQuotes()

Public ReadOnly Property GetQuote(ByVal index As Integer) As MFLib.Quote Member of: MFLib.Metafile Summary: This GetQuote Property returns the quote specified by the index number passed in by the parameter. Parameters: index . - The index number of the quote to be returned. Return Values: Returns a Quote Object.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim myquote As MFLib.Quote PF.Security("YHOO").LoadQuotes() myquote = PF.Security("YHOO").GetQuote(0) 'Get the first quote in the data file PF.Security("YHOO").UnloadQuotes()

Public ReadOnly Property GetSymbol() As String Member of: MFLib.Metafile Summary: Returns the Symbol of the specified security. Parameters: none.

Return Values: Returns the String value of the specified security.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim mysecSymbol As String mysecSymbol = PF.Security(1).GetSymbol

Public ReadOnly Property HasDelayed() As Object Member of: MFLib.Metafile Summary: Add Here. Parameters: none. Return Values: none.

Example:

Public ReadOnly Property IsUpToDate() As Boolean Member of: MFLib.Metafile Summary: The IsUpToDate property returns a boolean true if the security has a quote for the last business day. This does not take into account holidays Parameters: none. Return Values: Returns a Boolean True if the security has the latest quote.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim mysecUpToDate As Boolean mysecUpToDate = PF.Security("YHOO").IsUpToDate

Public ReadOnly Property LastUpdateQuoteCount() As Long Member of: MFLib.Metafile Summary: This property returns the number of quotes received in the last update. Parameters: none. Return Values: Returns a long representing the number of quotes received in the last update.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) PF.Security("YHOO").Update(MFLib.DataProviders.Service.YahooEOD, True, True)

PF.Security("YHOO").Save(True) Dim numofquotesreclastupdate As Long numofquotesreclastupdate = PF.Security("YHOO").LastUpdateQuoteCount

Public ReadOnly Property QuotesAreLoaded() As Boolean Member of: MFLib.Metafile Summary: The QuotesAreLoaded property returns a boolean true if the Metafile Object has the quotes loaded into memory. Parameters: none. Return Values: Returns a boolean true if the quotes are loaded into memory for the respective security.

Example:
Dim PF As New MFLib.Portfolio("C:\MetaStock Data\Index\", True, True) Dim areLoaded As Boolean PF.Security("YHOO").LoadQuotes() areLoaded = PF.Security("YHOO").QuotesAreLoaded 'Will return Boolean True PF.Security("YHOO").UnloadQuotes() areLoaded = PF.Security("YHOO").QuotesAreLoaded 'Will return Boolean False

Appendix A - MASTER
This Appendix describes the format of the MASTER file. Each Record in the Master file is 53 bytes in Length. The first 53 bytes in the file contains some information regarding index numbers, and all remaining 53 byte records contain security information. The Master file record can contain no more than 255 security records. The following shows the Byte Configuration for reading and writing to the MASTER File. This shows the configuration for the first 53 byte record.
Field Name

Format Start(Position Length(# of Bytes) Byte#) UB UB 1 3 5 2 2 48

Function Stores the # of records stored in the MASTER file Stores the last # used for a F#.dat file

# of Records Next Record # Blank Space

The following shows the 53 Byte configuration for the security records which would consist of all remaining 53Byte records found in this file.
Field Name

Format Start(Position Length(# of Bytes) Byte#) UB 1 2 4 5 1 2 1 1

Function Stores the index # for the F#.dat file This is always written as 25856(Int). Not
sure what function this provides

Record # File Type Record Length Record Count

# of 4 byte fields in the F#.dat file. Dependant on whether its Intraday, has Open Price, Open Interest and High and low. Description provide for the security

Unknown Issue Name Unknown CT_V2_8_ FLAG

6 8 24 25

2 16 1 1 If this is 89(Int) then V28 is true, if this is 42(Int) then Autorun is True. (I have no clue what this is used for, but it doesn seem to affect anything) This is the date defined when the security is created. Is used to determine how far back to capture security data. This is the date of the last quote on

First Date MBF

26

Last Date MBF

30

record. Time Frame A 34 1 This is the timeframe for the security defined when the security is created. 'I' for Intraday, 'D' for Daily, 'W' for Weekly, Etc. This is the Intraday Time base defined when the security is created. 1Min,5min, 10min Ascii symbol defined when the security is created. Always set to 0.

Intraday Timefram e Symbol Unknown Flag Unknown A

35

37 51 52 53

14 1 1 1

See MasterFileRecord.vb for further details on how each security record is read, and the functions used to convert the bytes to useful data. See Functions.vb for how a MasterByteArray is constructed. The MasterFileRecord.vb class uses the MasterFileDescriptor.vb to provide the byte locations for each record.

Appendix B - EMASTER
This Appendix describes the format of the EMASTER file. Each Record in the EMaster file is 192 bytes in Length. The first 192 bytes in the file contains some information regarding index numbers, and all remaining 192 byte records contain security information. The EMaster file contains some duplicate data of the the MASTER, and like the Master file contains no more than 255 security records The following shows the Byte Configuration for reading and writing to the EMASTER File. This shows the configuration for the first 192 byte record.
Field Name

Format Start(Position Length(# of Bytes) Byte#) UB UB 1 3 5 2 2 187

Function Stores the # of records stored in the EMASTER file Stores the last # used for a F#.dat file

# of Records Next Record # Blank Space

The following shows the 192 Byte configuration for the security records which would consist of all remaining 192Byte records found in this file.
Field Name

Format Start(Position Length(# of Bytes) Byte#) 1 1

Function

ID Code

Record # Unknown Record Count

2 3 5

1 2 1

Stores the index # for the F#.dat file # of 4 byte fields in the F#.dat file. Dependant on whether its Intraday, has Open Price, Open Interest and High and low. Tells which fields are active, MSBTime,OI,OP,HighorLow,HighorLow,Unk nown,Uknown LSB Unsure what this is used for Ascii symbol defined when the security is created. Security description defined when the security is created. This is the timeframe for the security defined when the security is created. 'I' for Intraday, 'D' for Daily, 'W' for Weekly, Etc. This is the date defined when the security is created. Is used to determine how far back to capture security data. YYMMDD

Fields

Unknown AutoRun Unknown Symbol Unknown Issue Name Unknown Time Frame Ascii Ascii Ascii

7 10 11 12 26 33 50 61

8 1 1 13 6 16 11 1

Unknown

62

3 4

First Date CVS - 65 4 byte single precisio n real Uknown 70 Last Date CVS - 4 73 byte single precisio n real Unknown 78 Start Time CVS - 4 81 byte single precisio n real End Time CVS - 4 85 byte single precisio n real

3 4 The is the date of the Last quote on Record. YYMMDD

3 4 Defines the start time for an Intraday Security

Defines the stop time for an Intraday Security.

Unknown

89

38 4 This is the date of the Last Quote in Long Format YYYYMMDD

First Date CVL - 127 Long 4 byte long integer Unknown Dividend Date 131 CVL - 132 4 byte long integer
CVS - 4

1 4 Not sure how this is used.

Dividend Date

136

Not sure how this is used.

byte single precisio n real 141 52

Unknown

See EMasterFileRecord.vb for further details on how each security record is read, and the functions used to convert the bytes to useful data. See Functions.vb for how a EMasterByteArray is constructed. The EMasterFileRecord.vb class uses the EMasterFileDescriptor.vb to provide the byte locations for each record.

Appendix C - XMASTER
This Appendix describes the format of the XMASTER file. Each Record in the XMaster file is 150 bytes in Length. The first 150 bytes in the file contains some information regarding index numbers, and all remaining 150 byte records contain security information. The XMaster file is used after the MASTER and EMASTER have been populated with 255 security records, the Limit of the MASTER and EMASTER files. The XMaster can house Index Number 256 to 65535, and its respective information. The following shows the Byte Configuration for reading and writing to the MASTER File. This shows the configuration for the first 150 byte record.
Field Name

Format Start(Position Length(# of Bytes) Byte#) 1 2 3 5 11 13 15 1 1 2 6 2 2 2

Function Always seems to be 0x5D Always seems to be 0xFE Always seems to be Ascii XM Number of records stored in the XMASTER Number of records stored in the XMASTER(seems to be the same)

Unknown Unknown Unknown Unknown # of Records Unknown # of Records

Unknown Next Record # Unknown

17 19 21

2 2 129 Stores the last # used for a F#.dat file

The following shows the 150 Byte configuration for the security records which would consist of all remaining 150Byte records found in this file.
Field Name

Format Start(Position Length(# of Bytes) Byte#) 1 Ascii Ascii 2 17 41 42 43 47 48 Ascii 62 1 14 23 1 1 5 1 13 1

Function

Uknown Symbol Issue Name Unknown Unknown Unknown Unknown Unknown Time Frame

Ascii symbol defined when the security is created. Security description defined when the security is created. Always seems to be 0xFF. Unsure of function. Always seems to be 0x7F. Unsure of function This is the timeframe for the security defined when the security is created. 'I' for Intraday, 'D' for Daily, 'W' for Weekly, Etc. Stores the index # for the F#.dat file Tells which fields are active, MSBTime,OI,OP,HighorLow,HighorLow,Unk nown,Uknown LSB

Unknown Record # Unknown Fields

63 66 68 71

1 2 2 1

Unknown

72

7 4

Start Date CVL - 81 4 byte long integer Short Start Date Unknown First Date CVL Long 4 byte long 85 87 105

3 16 4 This is the date of the Last Quote in Long Format YYYYMMDD

integer Last Date CVL - 109 4 byte long integer Unknown 113 Last Date CVL - 117 4 byte long integer Unknown 121 4 The is the date of the Last quote on Record. Long Format YYYYMMDD

3 4 The is the date of the Last quote on Record. Long Format YYYYMMDD (seems to repeat)

29

See XMasterFileRecord.vb for further details on how each security record is read, and the functions used to convert the bytes to useful data. See Functions.vb for how a XMasterByteArray is constructed. The XMasterFileRecord.vb class uses the XMasterFileDescriptor.vb to provide the byte locations for each record.

Appendix D F*.DAT (or F*.MWD)


This Appendix describes the format of the .DAT or .MWD file. The .dat file contains a Dummy record at the beginning of the file. In the Dummy record the Number of quotes records stored .dat file are recorded/stored at the 3rd and 4th byte of that .dat file. The byte configuration is a little flexible in that it changes depending on the # of Fields defined by the MASTER/EMASTER or XMASTER files. The Fields byte in the EMASTER or XMASTER determine how many 4 byte fields will make up a record. In the case of Tick data a record could have as few as 4 by 4 byte fields making up a record which would consist of Date, Time, Close and Volume for a total of 16 bytes per record. In the case of an Intraday Commodity, you could have as many as 8 by 4 byte fields making up a record which would consist of Date, Time, Open, High, Low, Close, Volume, Open Interest for a total of 32 bytes per record. Each 4 byte record goes in the following sequential order : Date, Time, Open, High, Low, Close, Volume, Open Interest. If any field is not present it is removed from the order in order to make up that particular record. See the if statements in the LoadQuotes function in the Metafile.vb for the possible combinations.

You might also like