public TradingState BackTrading(IExchange ex1, IExchange ex2, Instrument ins, MatchingData data) { data.SetExchange1(ex1); data.SetExchange2(ex2); InitPrices(data, ins.GetBidPrice(ex2), ins.GetAskPrice(ex1), ins.GetBidOrderAmount(ex2), ins.GetAskOrderAmount(ex1)); var amount = data.Amount; SetUsdAmounts(ex1, ex2, data); if (data.ProfitRatio < ProfitRatio) { return(TradingState.Negative); } var buyAmount = Math.Min(data.AskAmount, data.BidAmount); if (buyAmount < data.Amount) { return(TradingState.Reject); } if (data.ProfitRatio > 0) { data.Amount = Math.Min(buyAmount, data.Amount); } double avgAmount = (ins.GetCryptoBalance(ex1) + ins.GetCryptoBalance(ex2)) / 2; if (buyAmount < avgAmount) { return(TransactionState.Reject); } data.Amount = Math.Min(buyAmount, data.Amount); SetUsdAmounts(ex1, ex2, data); var state = CheckBalancesImpl(ex1, ex2, ins, data); if (state != TradingState.Ok) { return(state); } return(TradingState.Back); }
public TradingState Trading(IExchange ex1, IExchange ex2, Instrument ins, MatchingData data, double maxBid, double minAsk, int depth = 0) { data.SetExchange1(ex1); data.SetExchange2(ex2); InitPrices(data, maxBid, minAsk, ins.GetBidOrderAmount(ex2), ins.GetAskOrderAmount(ex1)); SetUsdAmounts(ex1, ex2, data); if (data.ProfitRatio < 0) { return(depth == 1 ? TradingState.Negative : Trading(ex2, ex1, ins, data, maxBid, minAsk, 1)); } var state = CheckBalancesImpl(ex1, ex2, ins, data); if (state != TradingState.Ok) { return(state); } state = _profitStrategy.GetProfitState(data, ins.GetProfitRatios(), multiplier => { if (multiplier != 1) { SetUsdAmounts(ex1, ex2, data); } return(CheckBalancesImpl(ex1, ex2, ins, data)); }); if (state != TradingState.Ok) { return(state); } if (data.Profit < ins.GetMinUsdProfit()) { return(TradingState.NoProfit); } return(TradingState.Ok); }