Skip to content

Commit

Permalink
Integrates with crypto security
Browse files Browse the repository at this point in the history
  • Loading branch information
jameschch committed Sep 15, 2017
1 parent d6f5fb2 commit 7fab872
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 34 deletions.
2 changes: 1 addition & 1 deletion Algorithm.CSharp/FractionalQuantityRegressionAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void Initialize()
SetCash(100000);

SetTimeZone(NodaTime.DateTimeZone.Utc);
var security = AddSecurity(SecurityType.Forex, "BTCUSD", Resolution.Daily, Market.GDAX, false, 3.3m, true);
var security = AddSecurity(SecurityType.Crypto, "BTCUSD", Resolution.Daily, Market.GDAX, false, 3.3m, true);
var con = new QuoteBarConsolidator(1);
SubscriptionManager.AddConsolidator("BTCUSD", con);
con.DataConsolidated += con_DataConsolidated;
Expand Down
15 changes: 12 additions & 3 deletions Algorithm/QCAlgorithm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ public void SetTradeBuilder(ITradeBuilder tradeBuilder)
/// <summary>
/// Add specified data to our data subscriptions. QuantConnect will funnel this data to the handle data routine.
/// </summary>
/// <param name="securityType">MarketType Type: Equity, Commodity, Future or FOREX</param>
/// <param name="securityType">MarketType Type: Equity, Commodity, Future, FOREX or Crypto</param>
/// <param name="symbol">Symbol Reference for the MarketType</param>
/// <param name="resolution">Resolution of the Data Required</param>
/// <param name="fillDataForward">When no data available on a tradebar, return the last data that was generated</param>
Expand All @@ -1268,7 +1268,7 @@ public Security AddSecurity(SecurityType securityType, string symbol, Resolution
/// <summary>
/// Add specified data to required list. QC will funnel this data to the handle data routine.
/// </summary>
/// <param name="securityType">MarketType Type: Equity, Commodity, Future or FOREX</param>
/// <param name="securityType">MarketType Type: Equity, Commodity, Future, FOREX or Crypto</param>
/// <param name="symbol">Symbol Reference for the MarketType</param>
/// <param name="resolution">Resolution of the Data Required</param>
/// <param name="fillDataForward">When no data available on a tradebar, return the last data that was generated</param>
Expand All @@ -1283,7 +1283,7 @@ public Security AddSecurity(SecurityType securityType, string symbol, Resolution
/// <summary>
/// Set a required SecurityType-symbol and resolution for algorithm
/// </summary>
/// <param name="securityType">SecurityType Enum: Equity, Commodity, FOREX or Future</param>
/// <param name="securityType">MarketType Type: Equity, Commodity, Future, FOREX or Crypto</param>
/// <param name="symbol">Symbol Representation of the MarketType, e.g. AAPL</param>
/// <param name="resolution">Resolution of the MarketType required: MarketData, Second or Minute</param>
/// <param name="market">The market the requested security belongs to, such as 'usa' or 'fxcm'</param>
Expand Down Expand Up @@ -1512,6 +1512,15 @@ public Cfd AddCfd(string ticker, Resolution resolution = Resolution.Minute, stri
return AddSecurity<Cfd>(SecurityType.Cfd, ticker, resolution, market, fillDataForward, leverage, false);
}

/// <summary>
/// Creates and adds a new <see cref="Crypto"/> security to the algorithm
/// </summary>
/// <param name="ticker">The currency pair</param>
/// <param name="resolution">The <see cref="Resolution"/> of market data, Tick, Second, Minute, Hour, or Daily. Default is <see cref="Resolution.Minute"/></param>
/// <param name="market">The cfd trading market, <seealso cref="Market"/>. Default value is null and looked up using BrokerageModel.DefaultMarkets in <see cref="AddSecurity{T}"/></param>
/// <param name="fillDataForward">If true, returns the last available data even if none in that timeslice. Default is <value>true</value></param>
/// <param name="leverage">The requested leverage for this equity. Default is set by <see cref="SecurityInitializer"/></param>
/// <returns>The new <see cref="Crypto"/> security</returns>
public Crypto AddCrypto(string ticker, Resolution resolution = Resolution.Minute, string market = null, bool fillDataForward = true, decimal leverage = 0m)
{
return AddSecurity<Crypto>(SecurityType.Crypto, ticker, resolution, market, fillDataForward, leverage, false);
Expand Down
2 changes: 1 addition & 1 deletion Brokerages/GDAX/GDAXBrokerage.Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static string ConvertOrderType(Orders.OrderType orderType)
/// <returns>Symbol</returns>
public static Symbol ConvertProductId(string productId)
{
return Symbol.Create(productId.Replace("-", ""), SecurityType.Forex, Market.GDAX);
return Symbol.Create(productId.Replace("-", ""), SecurityType.Crypto, Market.GDAX);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Brokerages/GDAX/GDAXBrokerage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public override List<Holding> GetAccountHoldings()
{

var baseSymbol = (item.ProductId.Substring(0, 3) + "USD").ToLower();
var tick = this.GetTick(Symbol.Create(baseSymbol, SecurityType.Forex, Market.GDAX));
var tick = this.GetTick(Symbol.Create(baseSymbol, SecurityType.Crypto, Market.GDAX));
conversionRate = tick.Price;
}
else
Expand All @@ -259,7 +259,7 @@ public override List<Holding> GetAccountHoldings()
{
Symbol = ConvertProductId(item.ProductId),
Quantity = item.Side == "sell" ? -item.FilledSize : item.FilledSize,
Type = SecurityType.Forex,
Type = SecurityType.Crypto,
CurrencySymbol = item.ProductId.Substring(0, 3).ToUpper(),
ConversionRate = conversionRate,
MarketPrice = item.Price,
Expand Down Expand Up @@ -294,7 +294,7 @@ public override List<Cash> GetCashBalance()
}
else
{
var tick = GetTick(Symbol.Create(item.Currency + "USD", SecurityType.Forex, Market.GDAX));
var tick = GetTick(Symbol.Create(item.Currency + "USD", SecurityType.Crypto, Market.GDAX));

list.Add(new Securities.Cash(item.Currency.ToUpper(), item.Balance, tick.Price));
}
Expand Down
2 changes: 0 additions & 2 deletions Common/Brokerages/GDAXBrokerageModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
using QuantConnect.Data.Market;
using QuantConnect.Orders;
using QuantConnect.Securities;
using QuantConnect.Securities.Equity;
using QuantConnect.Securities.Forex;
using QuantConnect.Securities.Interfaces;
using QuantConnect.Orders.Fills;
using QuantConnect.Orders.Fees;
Expand Down
3 changes: 1 addition & 2 deletions Common/Data/SubscriptionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ public Dictionary<SecurityType, List<TickType>> DefaultDataTypes()
return new Dictionary<SecurityType, List<TickType>>()
{
{SecurityType.Base, new List<TickType>() { TickType.Trade } },
//todo: revert trade ticks for forex
{SecurityType.Forex, new List<TickType>() { TickType.Quote, TickType.Trade } },
{SecurityType.Forex, new List<TickType>() { TickType.Quote } },
{SecurityType.Equity, new List<TickType>() { TickType.Trade } },
{SecurityType.Option, new List<TickType>() { TickType.Quote, TickType.Trade, TickType.OpenInterest } },
{SecurityType.Cfd, new List<TickType>() { TickType.Quote } },
Expand Down
File renamed without changes.
23 changes: 11 additions & 12 deletions Data/symbol-properties/symbol-properties-database.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ market,symbol,type,description,quote_currency,contract_multiplier,minimum_price_

#
# Use # signs for comments
bitfinex,BTCUSD,forex,BTCUSD,USD,1,0.01,0.01
#

fxcm,AU200AUD,cfd,S&P/ASX index of Australian listed shares,USD,0.1,0.1,1
Expand Down Expand Up @@ -238,14 +237,14 @@ oanda,USDZAR,forex,USD/ZAR,ZAR,1,0.00001,1
oanda,ZARJPY,forex,ZAR/JPY,JPY,1,0.001,1


gdax,BTCUSD,forex,BTCUSD,USD,1,0.01,0.01
gdax,LTCUSD,forex,LTCUSD,USD,1,0.01,0.01
gdax,ETHUSD,forex,ETHUSD,USD,1,0.01,0.01
gdax,LTCBTC,forex,LTCBTC,BTC,1,0.00001,0.01
gdax,ETHBTC,forex,ETHBTC,BTC,1,0.00001,0.01
gdax,BTCGBP,forex,BTCGBP,GBP,1,0.01,0.01
gdax,LTCGBP,forex,LTCGBP,GBP,1,0.01,0.01
gdax,ETHGBP,forex,ETHGBP,GBP,1,0.01,0.01
gdax,BTCEUR,forex,BTCEUR,EUR,1,0.01,0.01
gdax,LTCEUR,forex,LTCEUR,EUR,1,0.01,0.01
gdax,ETHEUR,forex,ETHEUR,EUR,1,0.01,0.01
gdax,BTCUSD,crypto,BTCUSD,USD,1,0.01,0.01
gdax,LTCUSD,crypto,LTCUSD,USD,1,0.01,0.01
gdax,ETHUSD,crypto,ETHUSD,USD,1,0.01,0.01
gdax,LTCBTC,crypto,LTCBTC,BTC,1,0.00001,0.01
gdax,ETHBTC,crypto,ETHBTC,BTC,1,0.00001,0.01
gdax,BTCGBP,crypto,BTCGBP,GBP,1,0.01,0.01
gdax,LTCGBP,crypto,LTCGBP,GBP,1,0.01,0.01
gdax,ETHGBP,crypto,ETHGBP,GBP,1,0.01,0.01
gdax,BTCEUR,crypto,BTCEUR,EUR,1,0.01,0.01
gdax,LTCEUR,crypto,LTCEUR,EUR,1,0.01,0.01
gdax,ETHEUR,crypto,ETHEUR,EUR,1,0.01,0.01
2 changes: 1 addition & 1 deletion Tests/Brokerages/GDAX/GDAXBrokerageIntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override Symbol Symbol
/// </summary>
protected override SecurityType SecurityType
{
get { return SecurityType.Forex; }
get { return SecurityType.Crypto; }
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Tests/Brokerages/GDAX/GDAXBrokerageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void Setup()
_orderByIdData = File.ReadAllText("TestData//gdax_orderById.txt");
_tickerData = File.ReadAllText("TestData//gdax_ticker.txt");

_symbol = Symbol.Create("BTCUSD", SecurityType.Forex, Market.GDAX);
_symbol = Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX);

_rest.Setup(m => m.Execute(It.Is<IRestRequest>(r => r.Resource.StartsWith("/products/")))).Returns(new RestSharp.RestResponse
{
Expand Down Expand Up @@ -336,8 +336,8 @@ public void SubscribeTest()

_unit.Ticks.Clear();

_unit.Subscribe(Mock.Of<LiveNodePacket>(), new[] { Symbol.Create("BTCUSD", SecurityType.Forex, Market.GDAX), Symbol.Create("GBPUSD", SecurityType.Forex, Market.GDAX),
Symbol.Create("BTCETH", SecurityType.Forex, Market.GDAX)});
_unit.Subscribe(Mock.Of<LiveNodePacket>(), new[] { Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX), Symbol.Create("GBPUSD", SecurityType.Crypto, Market.GDAX),
Symbol.Create("BTCETH", SecurityType.Crypto, Market.GDAX)});

StringAssert.Contains(expected, actual);

Expand All @@ -352,7 +352,7 @@ public void UnsubscribeTest()
{
string actual = null;
_wss.Setup(w => w.Send(It.IsAny<string>())).Callback<string>(c => actual = c);
_unit.Unsubscribe(null, new List<Symbol> { Symbol.Create("BTCUSD", SecurityType.Forex, Market.GDAX) });
_unit.Unsubscribe(null, new List<Symbol> { Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX) });
StringAssert.Contains("user", actual);
StringAssert.Contains("heartbeat", actual);
StringAssert.Contains("ticker", actual);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Brokerages/GDAX/GDAXTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public static Security GetSecurity(decimal price = 1m)

private static SubscriptionDataConfig CreateConfig()
{
return new SubscriptionDataConfig(typeof(TradeBar), Symbol.Create("BTCUSD", SecurityType.Forex, Market.GDAX), Resolution.Minute, TimeZones.Utc, TimeZones.Utc,
return new SubscriptionDataConfig(typeof(TradeBar), Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX), Resolution.Minute, TimeZones.Utc, TimeZones.Utc,
false, true, false);
}

Expand Down
2 changes: 1 addition & 1 deletion Tests/Common/Securities/SecurityManagerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void NotifiesWhenSecurityRemoved()

[TestCase("EURUSD", SecurityType.Forex, Market.FXCM)]
[TestCase("EURUSD", SecurityType.Forex, Market.Oanda)]
[TestCase("BTCUSD", SecurityType.Crypto, Market.Bitfinex)]
[TestCase("BTCUSD", SecurityType.Crypto, Market.GDAX)]
public void SecurityManagerCanCreate_ForexOrCrypto_WithCorrectSubscriptions(string ticker, SecurityType type, string market)
{
var symbol = Symbol.Create(ticker, type, market);
Expand Down
2 changes: 1 addition & 1 deletion Tests/Symbols.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static Symbol CreateOptionSymbol(string symbol, OptionRight right, decim

private static Symbol CreateCryptoSymbol(string symbol)
{
return Symbol.Create(symbol, SecurityType.Crypto, Market.Bitfinex);
return Symbol.Create(symbol, SecurityType.Crypto, Market.GDAX);
}

}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ToolBox/LeanDataWriterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void Setup()
_cfd = Symbol.Create("BCOUSD", SecurityType.Cfd, Market.Oanda);
_equity = Symbol.Create("spy", SecurityType.Equity, Market.USA);
_date = DateTime.Parse("3/16/2017 12:00:00 PM", CultureInfo.InvariantCulture);
_crypto = Symbol.Create("BTCUSD", SecurityType.Crypto, Market.Bitfinex);
_crypto = Symbol.Create("BTCUSD", SecurityType.Crypto, Market.GDAX);
}

private List<Tick> GetTicks(Symbol sym)
Expand Down
1 change: 0 additions & 1 deletion ToolBox/QuandlBitfinexDownloader/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ static void Main(string[] args)
{
// Load settings from config.json
var dataDirectory = Config.Get("data-directory", "../../../Data");
var scaleFactor = Config.GetInt("bitfinex-scale-factor", 100);

// Create an instance of the downloader
const string market = Market.Bitfinex;
Expand Down

0 comments on commit 7fab872

Please sign in to comment.