public Instruction( DateTime submissionTime, ITradingObject tradingObject, TradingAction action, TradingPrice price) { Id = IdGenerator.Next; TradingObject = tradingObject; Action = action; Price = price; SubmissionTime = submissionTime; }
private (decimal mainBalance, decimal secondaryBalance) TradingAction(TradingAction action, decimal price, decimal mainBalance, decimal secondaryBalance) { if (action == Environments.TradingAction.Buy) { (decimal cost, decimal count) = Buy(price, mainBalance); return(mainBalance - cost, secondaryBalance + count); } else { (decimal income, decimal count) = Sell(price, secondaryBalance); return(mainBalance + income, secondaryBalance - count); } }
/// <summary> /// 交易 /// </summary> /// <param name="action"> 動作(買/賣) </param> /// <param name="market"> 市場 (BTCUSDT, ETHUSDT, ETHBTC) </param> /// <returns></returns> public virtual (decimal balance, decimal CoinBalance1, decimal CoinBalance2) Trading(TradingAction action, TradingMarket market) { if (market == TradingMarket.Coin12Coin) { (Balance, CoinBalance1) = TradingAction(action, dataProvider.Current.Coin12CoinKline.Close, Balance, CoinBalance1); } if (market == TradingMarket.Coin22Coin) { (Balance, CoinBalance2) = TradingAction(action, dataProvider.Current.Coin22CoinKline.Close, Balance, CoinBalance2); } if (market == TradingMarket.Coin22Coin1) { (CoinBalance1, CoinBalance2) = TradingAction(action, dataProvider.Current.Coin22Coin1Kline.Close, CoinBalance1, CoinBalance2); } return(Balance, CoinBalance1, CoinBalance2); }