Skip to content

Commit

Permalink
Merge pull request #639 from CoiniumServ/master
Browse files Browse the repository at this point in the history
sync develop with master
  • Loading branch information
Hüseyin Uslu committed Oct 27, 2014
2 parents 0d808e9 + c1c55e2 commit c4cd699
Show file tree
Hide file tree
Showing 41 changed files with 1,282 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/CoiniumServ/Blocks/BlockProcessor.cs
Expand Up @@ -195,7 +195,7 @@ private Block GetBlockInfo(IPersistedBlock block)
catch (RpcException e)
{
block.Status = BlockStatus.Pending; // and let block stay in pending status so we can query it again later.
_logger.Error("Unhandled rpc-exception: {0:l}", e);
_logger.Error("Unhandled rpc-exception: {0:l}", e.Message);
return null;
}
}
Expand Down Expand Up @@ -236,7 +236,7 @@ private Transaction GetGenerationTx(IPersistedBlock block)
catch (RpcException e)
{
block.Status = BlockStatus.Pending; // and let block stay in pending status so we can query it again later.
_logger.Error("Unhandled rpc-exception: {0:l}", e);
_logger.Error("Unhandled rpc-exception: {0:l}", e.Message);
return null;
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/CoiniumServ/CoiniumServ.csproj
Expand Up @@ -118,6 +118,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\packages\Newtonsoft.Json.6.0.6\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="RestSharp">
<HintPath>..\..\build\packages\RestSharp.104.5.0\lib\net4\RestSharp.dll</HintPath>
</Reference>
<Reference Include="Serilog, Version=1.4.0.0, Culture=neutral, PublicKeyToken=24c2f752a8e58a10, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\build\packages\Serilog.1.4.14\lib\net45\Serilog.dll</HintPath>
Expand Down Expand Up @@ -151,8 +154,24 @@
<Compile Include="Coin\Config\CoinOptions.cs" />
<Compile Include="Coin\Config\IBlockExplorerOptions.cs" />
<Compile Include="Coin\Config\ICoinOptions.cs" />
<Compile Include="Markets\Exchanges\BittrexClient.cs" />
<Compile Include="Markets\Exchanges\ExchangeApi.cs" />
<Compile Include="Markets\Exchanges\CryptsyClient.cs" />
<Compile Include="Markets\Exchange.cs" />
<Compile Include="Markets\Exchanges\IBittrexClient.cs" />
<Compile Include="Markets\Exchanges\ICryptsyClient.cs" />
<Compile Include="Markets\Exchanges\IExchangeClient.cs" />
<Compile Include="Markets\Exchanges\IPoloniexClient.cs" />
<Compile Include="Markets\Exchanges\PoloniexClient.cs" />
<Compile Include="Markets\IMarketData.cs" />
<Compile Include="Markets\IMarketsConfig.cs" />
<Compile Include="Markets\MarketData.cs" />
<Compile Include="Markets\MarketsConfig.cs" />
<Compile Include="Persistance\Layers\Hybrid\Migrations\M003FixDefaults.cs" />
<Compile Include="Pools\IProfitInfo.cs" />
<Compile Include="Pools\ProfitInfo.cs" />
<Compile Include="Server\Web\Modules\TosModule.cs" />
<Compile Include="Utils\Extensions\LinqExtensions.cs" />
<Compile Include="Utils\Helpers\Humanize.cs" />
<Compile Include="Configuration\IJsonConfigReader.cs" />
<Compile Include="Daemon\Converters\DifficultyConverter.cs" />
Expand Down Expand Up @@ -518,6 +537,9 @@
<None Include="config\coins\viacoin.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config\markets-example.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="config\software-example.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
18 changes: 12 additions & 6 deletions src/CoiniumServ/Configuration/ConfigManager.cs
Expand Up @@ -23,17 +23,15 @@

using System;
using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Reflection;
using CoiniumServ.Coin.Config;
using CoiniumServ.Daemon.Config;
using CoiniumServ.Logging;
using CoiniumServ.Markets;
using CoiniumServ.Mining.Software;
using CoiniumServ.Pools;
using CoiniumServ.Server.Stack;
using CoiniumServ.Server.Web;
using CoiniumServ.Server.Web.Config;
using CoiniumServ.Statistics;
using CoiniumServ.Utils.Helpers;
Expand All @@ -51,14 +49,16 @@ public class ConfigManager:IConfigManager

public IWebServerConfig WebServerConfig { get; private set; }

public IMarketsConfig MarketsConfig { get; private set; }

public ILogConfig LogConfig { get; private set; }

public List<IPoolConfig> PoolConfigs { get; private set; }

public ISoftwareRepositoryConfig SoftwareRepositoryConfig { get; private set; }

private const string GlobalConfigFilename = "config/config.json"; // global config filename.
private const string DaemonManagerConfigFilename = "config/daemons.json"; // daemon manager config filename.
private const string MarketsConfigFilename = "config/markets.json"; // markets config filename.
private const string SoftwareManagerConfigFilename = "config/software.json"; // software manager config filename.
private const string PoolConfigRoot = "config/pools"; // root of pool configs.
private const string CoinConfigRoot = "config/coins"; // root of pool configs.
Expand All @@ -79,6 +79,7 @@ public ConfigManager(IConfigFactory configFactory, IJsonConfigReader jsonConfigR
_logger = Log.ForContext<ConfigManager>();

LoadGlobalConfig(); // read the global config.
LoadMarketsManagerConfig();
LoadSoftwareManagerConfig(); // load software manager config file.
LoadDefaultPoolConfig(); // load default pool config if exists.
LoadPoolConfigs(); // load the per-pool config files.
Expand Down Expand Up @@ -110,10 +111,15 @@ private void LoadGlobalConfig()
WebServerConfig = new WebServerConfig(data.website);
}

private void LoadSoftwareManagerConfig()
private void LoadMarketsManagerConfig()
{
var data = _jsonConfigReader.Read(SoftwareManagerConfigFilename); // read the global config data.
var data = _jsonConfigReader.Read(MarketsConfigFilename); // read the config data.
MarketsConfig = new MarketsConfig(data);
}

private void LoadSoftwareManagerConfig()
{
var data = _jsonConfigReader.Read(SoftwareManagerConfigFilename); // read the config data.
SoftwareRepositoryConfig = new SoftwareRepositoryConfig(_configFactory, data);
}

Expand Down
5 changes: 3 additions & 2 deletions src/CoiniumServ/Configuration/IConfigManager.cs
Expand Up @@ -23,12 +23,11 @@

using System.Collections.Generic;
using CoiniumServ.Coin.Config;
using CoiniumServ.Daemon.Config;
using CoiniumServ.Logging;
using CoiniumServ.Markets;
using CoiniumServ.Mining.Software;
using CoiniumServ.Pools;
using CoiniumServ.Server.Stack;
using CoiniumServ.Server.Web;
using CoiniumServ.Server.Web.Config;
using CoiniumServ.Statistics;

Expand All @@ -42,6 +41,8 @@ public interface IConfigManager

IWebServerConfig WebServerConfig { get; }

IMarketsConfig MarketsConfig { get; }

ILogConfig LogConfig { get; }

List<IPoolConfig> PoolConfigs { get; }
Expand Down
9 changes: 9 additions & 0 deletions src/CoiniumServ/Container/IObjectFactory.cs
Expand Up @@ -33,6 +33,7 @@
using CoiniumServ.Jobs.Tracker;
using CoiniumServ.Logging;
using CoiniumServ.Markets;
using CoiniumServ.Markets.Exchanges;
using CoiniumServ.Mining;
using CoiniumServ.Mining.Software;
using CoiniumServ.Payments;
Expand Down Expand Up @@ -95,6 +96,8 @@ public interface IObjectFactory

INetworkInfo GetNetworkInfo(IDaemonClient daemonClient, IHashAlgorithm hashAlgorithm, IPoolConfig poolConfig);

IProfitInfo GetProfitInfo(INetworkInfo networkInfo, IPoolConfig poolConfig);

IBlockRepository GetBlockRepository(IStorageLayer storageLayer);

IMiningServer GetMiningServer(string type, IPoolConfig poolConfig, IPool pool, IMinerManager minerManager, IJobManager jobManager,IBanManager banManager);
Expand Down Expand Up @@ -156,6 +159,12 @@ public interface IObjectFactory

IMarketManager GetMarketManager();

IBittrexClient GetBittrexClient();

ICryptsyClient GetCryptsyClient();

IPoloniexClient GetPoloniexClient();

#endregion

#region mining software
Expand Down
27 changes: 27 additions & 0 deletions src/CoiniumServ/Container/ObjectFactory.cs
Expand Up @@ -34,6 +34,7 @@
using CoiniumServ.Jobs.Tracker;
using CoiniumServ.Logging;
using CoiniumServ.Markets;
using CoiniumServ.Markets.Exchanges;
using CoiniumServ.Mining;
using CoiniumServ.Mining.Software;
using CoiniumServ.Payments;
Expand Down Expand Up @@ -225,6 +226,17 @@ public INetworkInfo GetNetworkInfo(IDaemonClient daemonClient, IHashAlgorithm ha
return _applicationContext.Container.Resolve<INetworkInfo>(@params);
}

public IProfitInfo GetProfitInfo(INetworkInfo networkInfo, IPoolConfig poolConfig)
{
var @params = new NamedParameterOverloads
{
{"poolConfig", poolConfig},
{"networkInfo", networkInfo},
};

return _applicationContext.Container.Resolve<IProfitInfo>(@params);
}

public IBlockRepository GetBlockRepository(IStorageLayer storageLayer)
{
var @params = new NamedParameterOverloads
Expand Down Expand Up @@ -420,6 +432,21 @@ public IMarketManager GetMarketManager()
return _applicationContext.Container.Resolve<IMarketManager>();
}

public IBittrexClient GetBittrexClient()
{
return _applicationContext.Container.Resolve<IBittrexClient>();
}

public ICryptsyClient GetCryptsyClient()
{
return _applicationContext.Container.Resolve<ICryptsyClient>();
}

public IPoloniexClient GetPoloniexClient()
{
return _applicationContext.Container.Resolve<IPoloniexClient>();
}

public ISoftwareRepository GetSoftwareRepository()
{
return _applicationContext.Container.Resolve<ISoftwareRepository>();
Expand Down
7 changes: 7 additions & 0 deletions src/CoiniumServ/Container/Registries/ClassRegistry.cs
Expand Up @@ -29,6 +29,7 @@
using CoiniumServ.Daemon;
using CoiniumServ.Daemon.Config;
using CoiniumServ.Jobs.Tracker;
using CoiniumServ.Markets.Exchanges;
using CoiniumServ.Mining.Software;
using CoiniumServ.Payments;
using CoiniumServ.Pools;
Expand All @@ -54,6 +55,7 @@ public void RegisterInstances()
_applicationContext.Container.Register<IJobTracker, JobTracker>().AsMultiInstance();
_applicationContext.Container.Register<IBlockProcessor, BlockProcessor>().AsMultiInstance();
_applicationContext.Container.Register<INetworkInfo, NetworkInfo>().AsMultiInstance();
_applicationContext.Container.Register<IProfitInfo, ProfitInfo>().AsMultiInstance();
_applicationContext.Container.Register<IBlockRepository, BlocksRepository>().AsMultiInstance();
_applicationContext.Container.Register<IPaymentRepository, PaymentRepository>().AsMultiInstance();
_applicationContext.Container.Register<IAccountManager, AccountManager>().AsMultiInstance();
Expand All @@ -69,6 +71,11 @@ public void RegisterInstances()
_applicationContext.Container.Register<ICoinConfig, CoinConfig>().AsMultiInstance();
_applicationContext.Container.Register<IMiningSoftwareConfig, MiningSoftwareConfig>().AsMultiInstance();

// markets
_applicationContext.Container.Register<IBittrexClient, BittrexClient>().AsSingleton();
_applicationContext.Container.Register<ICryptsyClient, CryptsyClient>().AsSingleton();
_applicationContext.Container.Register<IPoloniexClient, PoloniexClient>().AsSingleton();

// web
_applicationContext.Container.Register<INancyBootstrapper, NancyBootstrapper>().AsSingleton();

Expand Down
33 changes: 33 additions & 0 deletions src/CoiniumServ/Markets/Exchange.cs
@@ -0,0 +1,33 @@
#region License
//
// CoiniumServ - Crypto Currency Mining Pool Server Software
// Copyright (C) 2013 - 2014, CoiniumServ Project - http://www.coinium.org
// http://www.coiniumserv.com - https://github.com/CoiniumServ/CoiniumServ
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// For the terms of this license, see licenses/gpl_v3.txt.
//
// Alternatively, you can license this software under a commercial
// license or white-label it as set out in licenses/commercial.txt.
//
#endregion

namespace CoiniumServ.Markets
{
public enum Exchange
{
Unknown,
Cryptsy,
Bittrex,
Poloniex
}
}
87 changes: 87 additions & 0 deletions src/CoiniumServ/Markets/Exchanges/BittrexClient.cs
@@ -0,0 +1,87 @@
#region License
//
// CoiniumServ - Crypto Currency Mining Pool Server Software
// Copyright (C) 2013 - 2014, CoiniumServ Project - http://www.coinium.org
// http://www.coiniumserv.com - https://github.com/CoiniumServ/CoiniumServ
//
// This software is dual-licensed: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// For the terms of this license, see licenses/gpl_v3.txt.
//
// Alternatively, you can license this software under a commercial
// license or white-label it as set out in licenses/commercial.txt.
//
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CSharp.RuntimeBinder;
using Serilog;

namespace CoiniumServ.Markets.Exchanges
{
public class BittrexClient: ExchangeApi, IBittrexClient
{
private const string ApiBase = "https://bittrex.com/api/v1.1/";

private readonly ILogger _logger;

public BittrexClient()
{
_logger = Log.ForContext<BittrexClient>();
}

public async Task<IList<IMarketData>> GetMarkets()
{
var list = new List<IMarketData>();
var data = await Request(ApiBase, "public/getmarketsummaries");

try
{
foreach (var market in data.@result)
{
try
{
string name = market.MarketName;
var temp = name.Split('-');

var entry = new MarketData
{
Exchange = Exchange.Bittrex,
MarketCurrency = temp.Last(),
BaseCurrency = temp.First(),
Ask = market.Ask,
Bid = market.Bid,
VolumeInMarketCurrency = market.Volume,
VolumeInBaseCurrency = market.BaseVolume
};

list.Add(entry);
}
catch (RuntimeBinderException)
{ } // just skip the exception that occurs when a field can not be read.
catch (Exception e)
{
_logger.Error(e.Message);
}
}
}
catch (Exception e)
{
_logger.Error(e.Message);
}

return list;
}
}
}

0 comments on commit c4cd699

Please sign in to comment.