BigBot/StatisticalBot.cs

69 lines
1.7 KiB
C#

using System;
using sharp.json;
using sharp.trading;
using System.IO;
namespace sharp.tradebot
{
public class StatisticalBot : TradingBot<BasicBotSetup>
{
FileBackedJSONValue<BotSetup> Setup;
public StatisticalBot()
{
initialize();
}
private void initialize()
{
Setup = new FileBackedJSONValue<BotSetup>(Path.Combine(DataDirectory, "setup.json"));
}
public override void Prepare()
{
base.Prepare();
if (Setup.CurrentValue == null){
Setup.CurrentValue = new BotSetup();
Setup.Save();
}
}
public void Trade()
{
if (Setup.CurrentValue.Enabled)
{
Market market = TradingEnvironment.DefaultConnection.openMarket(Setup.CurrentValue.MarketSymbol, Setup.CurrentValue.BaseSymbol);
OrderBook orderbook = market.getOrderBook();
OrderbookVolume[] obvolumes = orderbook.calculateVolumes(Setup.CurrentValue.OrderBookIndicationVolumina);
Log("Current Orderbook Indications:");
foreach (OrderbookVolume ovol in obvolumes)
{
Log("Volume: {0,15:#########0.0000} {1} BUY: {2,11:####0.00000000} {3} SELL: {4,11:####0.00000000} {3}", ovol.VolumeBuy, Setup.CurrentValue.MarketSymbol, ovol.PriceBuy, Setup.CurrentValue.BaseSymbol, ovol.PriceSell);
Log(" RATIO: {0,11:####0.00000000} AVERAGE: {1,11:####0.00000000} {2}", ovol.PriceBuy / ovol.PriceSell, (ovol.AverageUnitPriceBuy + ovol.AverageUnitPriceSell) / 2, Setup.CurrentValue.BaseSymbol);
}
}
}
public override int SchedulingIntervall()
{
return 60;
}
class BotSetup {
public bool Enabled;
public string MarketSymbol = "";
public string BaseSymbol = "";
public double[] OrderBookIndicationVolumina = new double[] { 10, 25, 50, 100, 200, 400, 800, 1600, 3200 };
}
}
}