1515
1616using QuantConnect . Logging ;
1717using System ;
18+ using System . Collections . Generic ;
1819using System . IO ;
20+ using System . Linq ;
21+ using QuantConnect . DataLibrary ;
1922
2023namespace QuantConnect . DataProcessing
2124{
@@ -76,7 +79,29 @@ public bool Run()
7679 {
7780 try
7881 {
79- // Your data downloading/processing code goes here
82+ // Your data downloading/processing code goes here. The lines below
83+ // can be deleted since they are only meant to be an example.
84+ // ================================================================
85+ var underlying = Symbol . Create ( "SPY" , SecurityType . Equity , Market . USA ) ;
86+ var symbol = Symbol . CreateBase (
87+ typeof ( MyCustomDataType ) ,
88+ underlying ,
89+ Market . USA ) ;
90+
91+ var lines = new [ ]
92+ {
93+ "20131001,buy" ,
94+ "20131003,buy" ,
95+ "20131006,buy" ,
96+ "20131007,sell" ,
97+ "20131009,buy" ,
98+ "20131011,sell"
99+ } ;
100+
101+ var instances = lines . Select ( x => ParseLine ( symbol , x ) ) ;
102+ var csvLines = instances . Select ( x => ToCsvLine ( x ) ) ;
103+
104+ SaveContentsToFile ( symbol , csvLines ) ;
80105 }
81106 catch ( Exception e )
82107 {
@@ -87,6 +112,52 @@ public bool Run()
87112 return true ;
88113 }
89114
115+ /// <summary>
116+ /// Example method to parse and create an instance from a line of CSV
117+ /// </summary>
118+ /// <param name="symbol">Symbol</param>
119+ /// <param name="line">Line of raw data</param>
120+ /// <returns>Instance of <see cref="MyCustomDataType"/></returns>
121+ private MyCustomDataType ParseLine ( Symbol symbol , string line )
122+ {
123+ var csv = line . Split ( ',' ) ;
124+ return new MyCustomDataType
125+ {
126+ Time = Parse . DateTimeExact ( csv [ 0 ] , "yyyyMMdd" ) ,
127+ Symbol = symbol ,
128+
129+ SomeCustomProperty = csv [ 1 ]
130+ } ;
131+ }
132+
133+ /// <summary>
134+ /// Example method to convert an instance to a CSV line
135+ /// </summary>
136+ /// <param name="instance">Custom Data instance</param>
137+ /// <returns>CSV line</returns>
138+ private string ToCsvLine ( MyCustomDataType instance )
139+ {
140+ return string . Join ( "," ,
141+ $ "{ instance . Time : yyyyMMdd} ",
142+ instance . SomeCustomProperty ) ;
143+ }
144+
145+ /// <summary>
146+ /// Example method to save CSV lines to disk
147+ /// </summary>
148+ /// <param name="symbol">Symbol of the data</param>
149+ /// <param name="csvLines">CSV lines to write</param>
150+ private void SaveContentsToFile ( Symbol symbol , IEnumerable < string > csvLines )
151+ {
152+ var ticker = symbol . Value . ToLowerInvariant ( ) ;
153+
154+ var tempPath = new FileInfo ( Path . Combine ( Path . GetTempPath ( ) , $ "{ Guid . NewGuid ( ) } -{ ticker } .csv") ) ;
155+ var finalPath = Path . Combine ( _destinationDirectory , $ "{ ticker } .csv") ;
156+
157+ File . WriteAllLines ( tempPath . FullName , csvLines ) ;
158+ tempPath . MoveTo ( finalPath , true ) ;
159+ }
160+
90161 /// <summary>
91162 /// If you need to shut down things like database connections, threads, or other
92163 /// resources that require manual shutdown, do it here. This will be called after
0 commit comments