Skip to content

Commit

Permalink
v0.4
Browse files Browse the repository at this point in the history
- Yobit added
- Balances, Alerts - many improvements
- Main Window - sorting fixed
  • Loading branch information
bitwhiskey committed Feb 2, 2018
1 parent 82415b2 commit c9289a2
Show file tree
Hide file tree
Showing 39 changed files with 2,696 additions and 465 deletions.
129 changes: 125 additions & 4 deletions Alert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Media;
using System.IO;


namespace BitWhiskey
{
public class Alert
{
private static int IdCounter=0;
//private static int IdCounter=0;
public int id;
public string market;
public string caption;
public string tickerPair;
public DateTime createDate;
Expand All @@ -22,20 +26,137 @@ public class Alert
public bool playSound;

public bool alertExecute;
public bool enabled;

public Alert(string caption_)
{
IdCounter++;
id = IdCounter;
//IdCounter++;

id = GetNewId();

caption = caption_;
createDate = DateTime.Now;
showInChart = true;
alertExecute = false;
enabled = true;
}
public static int GetNewId()
{
return IdCounter + 1;
int newid = 0;
if (AlertManager.alerts.Count() == 0)
newid = 1;
else
newid = AlertManager.alerts.Max(x => x.Key) + 1;

return newid;
}

}


public static class AlertManager
{
public static SettingsAlert settingsAlert;
public static Dictionary<int, Alert> alerts = new Dictionary<int, Alert>();
public static SoundPlayer player = null;


public static void CheckAlerts()
{
foreach (Alert alert in alerts.Values)
{
if (alert.alertExecute)
continue;
if (!alert.enabled)
continue;
double price = Global.GetCurrentPrice(alert.market, alert.tickerPair);
if (alert.priceAlert > alert.createPrice)
{
if (alert.priceAlert <= price)
alert.alertExecute = true;
}
else
{
if (alert.priceAlert >= price)
alert.alertExecute = true;
}
}
/*
foreach (Alert alert in alerts.Values)
{
if (alert.alertExecute)
{
string soundfile = Path.Combine(Path.Combine(ApplicationPath.directory, @"AppBin"), "alert.wav");
player = new SoundPlayer(soundfile);
player.PlayLooping();
break;
}
}
*/
int count = alerts.Values.Count(x => x.alertExecute == true && x.enabled == true && x.playSound == true);
if (count > 0)
{
if (player == null)
{
string soundfile = Path.Combine(Path.Combine(ApplicationPath.directory, @"AppBin"), "alert.wav");
player = new SoundPlayer(soundfile);
player.Tag = false;
}
if ((bool)player.Tag == false)
{
player.PlayLooping();
player.Tag = true;
}
}
else
{
PlayerStop();
}

// SystemSounds.Asterisk. Playloo();

}

public static void SaveAlerts()
{
settingsAlert.alerts = alerts;
settingsAlert.Save(AppSettingsManager.pathAlert);
}
public static void Remove(int alertid)
{
alerts.Remove(alertid);
SaveAlerts();
}
public static void PlayerStop()
{
if (player != null)
{
player.Stop();
player.Tag = false;
}
}
public static void RemoveAll()
{
alerts.Clear();
SaveAlerts();
PlayerStop();
}
public static void ToggleAll()
{
int count = alerts.Values.Count(x => x.enabled == false);
bool enableAlert = false;
if (count == alerts.Count)
enableAlert = true;

foreach (Alert alert in alerts.Values)
{
alert.enabled = enableAlert;
if(!alert.enabled)
alert.alertExecute = false;
}
SaveAlerts();
if (count == alerts.Count)
PlayerStop();
}

}
Expand Down
2 changes: 1 addition & 1 deletion AppBin/Profiles/MarketTrade/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"poloniexkey":"","poloniexsecret":"","bittrexkey":"","bittrexsecret":"","defaultlimitorders":true}
{"poloniexkey":"","poloniexsecret":"","bittrexkey":"","bittrexsecret":"","yobitkey":"","yobitsecret":"","defaultlimitorders":true}
2 changes: 1 addition & 1 deletion AppBin/Profiles/Standart/settings.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"poloniexkey":"","poloniexsecret":"","bittrexkey":"","bittrexsecret":"","defaultlimitorders":true}
{"poloniexkey":"","poloniexsecret":"","bittrexkey":"","bittrexsecret":"","yobitkey":"","yobitsecret":"","defaultlimitorders":true}
1 change: 1 addition & 0 deletions AppBin/alert.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"alerts":{}}
18 changes: 18 additions & 0 deletions AppSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,27 @@ public class AppSettingsManager
{
public string pathProfiles;
public string pathStandart ;
public static string fileAlert;
public static string pathAlert ;

public AppSettingsManager()
{
pathProfiles = Path.Combine(ApplicationPath.directory, @"AppBin\Profiles");
fileAlert = "alert.json";
pathAlert = Path.Combine(ApplicationPath.directoryAppBin, fileAlert);
}
public static void LoadSettings()
{
Global.settingsInit = SettingsInit.Load(Path.Combine(ApplicationPath.directoryAppBin, "init.json"));
AppSettingsManager settingsManager = new AppSettingsManager();
string settingsPath = settingsManager.GetSettingsFilePath(Global.settingsInit.currentprofile, "settings.json");
Global.settingsMain = MySettings.Load(settingsPath);

if(File.Exists(pathAlert))
AlertManager.settingsAlert = SettingsAlert.Load(pathAlert);
else
AlertManager.settingsAlert = new SettingsAlert();
AlertManager.alerts= AlertManager.settingsAlert.alerts;
}

public string GetProfileDir(string profileName)
Expand Down Expand Up @@ -71,10 +82,17 @@ public class MySettings : AppSettings<MySettings>
public string poloniexsecret = "";
public string bittrexkey = "";
public string bittrexsecret = "";
public string yobitkey = "";
public string yobitsecret = "";
public bool defaultlimitorders = true;
}
public class SettingsInit : AppSettings<SettingsInit>
{
public string currentprofile = "Standart";
// public string alertSettingsFile = "Standart";
}
public class SettingsAlert : AppSettings<SettingsAlert>
{
public Dictionary<int, Alert> alerts = new Dictionary<int, Alert>();
}
}
14 changes: 12 additions & 2 deletions BitWhiskey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
<ApplicationIcon>if_CoinSphere-Bitcoin-Red-Casino-Chip-48_134211.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json.Net20">
<HintPath>.\Newtonsoft.Json.Net20.dll</HintPath>
<Reference Include="Newtonsoft.Json">
<HintPath>.\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="NLog, Version=4.0.0.0, Culture=neutral, PublicKeyToken=5120e14c03d0593c, processorArchitecture=MSIL">
<HintPath>packages\NLog.4.4.12\lib\net45\NLog.dll</HintPath>
Expand Down Expand Up @@ -69,6 +69,7 @@
<Compile Include="Chart.cs" />
<Compile Include="ConvertData.cs" />
<Compile Include="Cryptor.cs" />
<Compile Include="DataGridViewExWrapper.cs" />
<Compile Include="DataGridViewWrapper.cs" />
<Compile Include="ExchangeManager.cs" />
<Compile Include="Form1.cs">
Expand Down Expand Up @@ -108,6 +109,12 @@
<Compile Include="FormSettings.Designer.cs">
<DependentUpon>FormSettings.cs</DependentUpon>
</Compile>
<Compile Include="FormTicker.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="FormTicker.designer.cs">
<DependentUpon>FormTicker.cs</DependentUpon>
</Compile>
<Compile Include="FormTrade.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -146,6 +153,9 @@
<EmbeddedResource Include="FormSettings.resx">
<DependentUpon>FormSettings.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormTicker.resx">
<DependentUpon>FormTicker.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="FormTrade.resx">
<DependentUpon>FormTrade.cs</DependentUpon>
</EmbeddedResource>
Expand Down
4 changes: 2 additions & 2 deletions Chart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class BChartStyle
public Color backColor;
public Pen barUp = new Pen(Color.FromArgb(63, 170, 57));// new Pen(Color.FromArgb(73,192,67));
public Pen barDown = new Pen(Color.FromArgb(200, 11,11));
public Pen volbarUp = new Pen(Helper.ColorAlpha(Color.LightBlue,120));
public Pen volbarDown = new Pen(Helper.ColorAlpha(Color.LightPink,120));
public Pen volbarUp = new Pen(Helper.ColorAlpha(Color.MediumSeaGreen,100));
public Pen volbarDown = new Pen(Helper.ColorAlpha(Color.LightPink,130));
public Pen SelLine = Pens.Pink;

public Brush barUpBrush;
Expand Down
Loading

0 comments on commit c9289a2

Please sign in to comment.