Skip to content

Instantly share code, notes, and snippets.

@AnObfuscator
Created June 26, 2015 03:08
Show Gist options
  • Save AnObfuscator/12ad193fdfa8f4ffb20f to your computer and use it in GitHub Desktop.
Save AnObfuscator/12ad193fdfa8f4ffb20f to your computer and use it in GitHub Desktop.
namespace System
namespace System.Collections.Generic
namespace QuantConnnect
namespace QuantConnect.Orders
namespace QuantConnect.Algorithm
namespace QuantConnect.Interfaces
namespace QuantConnect.Securities
namespace QuantConnect.Securities.Interfaces
namespace QuantConnect.Algorithm.FSharp
open System
open System.Collections.Generic
open QuantConnect
open QuantConnect.Data.Market
open QuantConnect.Algorithm
open QuantConnect.Orders
open QuantConnect.Securities.Interfaces
// Declare algorithm name
type TickDataFilteringAlgorithm() =
//Reuse all the base class of QCAlgorithm
inherit QCAlgorithm()
let AllowedExchanges = [ "P" ]
let ExchangeDataFilter() =
{
new ISecurityDataFilter with
member this.Filter(vehicle, data) =
match data with
| :? Tick as tick -> List.exists ((=)tick.Exchange) AllowedExchanges
| _ -> false
}
//Implement core methods:
override this.Initialize() =
this.SetCash(100000)
this.SetStartDate(2013, 10, 07)
this.SetEndDate(2013, 10, 11)
this.AddSecurity(SecurityType.Equity, "SPY", Resolution.Second)
this.Securities.["SPY"].DataFilter <- ExchangeDataFilter()
//TradeBars Data Event
member this.OnData(data:Ticks) =
match data.["SPY"] with
| null -> ()
| _ as spyTickList ->
spyTickList.ForEach(fun tick -> this.Log(tick.Exchange))
match this.Portfolio.Invested with
| true -> this.SetHoldings("SPY", 1)
| false -> ()
module MarketCodes =
let US = dict [
("A", "American Stock Exchange");
("B", "Boston Stock Exchange");
("C", "National Stock Exchange");
("D", "FINRA ADF");
("I", "International Securities Exchange");
("J", "Direct Edge A");
("K", "Direct Edge X");
("M", "Chicago Stock Exchange");
("N", "New York Stock Exchange");
("P", "Nyse Arca Exchange");
("Q", "NASDAQ OMX");
("T", "NASDAQ OMX");
("U", "OTC Bulletin Board");
("u", "Over-the-Counter trade in Non-NASDAQ issue");
("W", "Chicago Board Options Exchange");
("X", "Philadelphia Stock Exchange");
("Y", "BATS Y-Exchange; Inc");
("Z", "BATS Exchange; Inc")
]
let Canada = dict [
("T", "Toronto");
("V", "Venture")
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment