/// <summary> /// Запись в БД Command, новой команды для бота и времени ёё выполнения, возвращает 1, если команда успешно записана. /// </summary> /// <param name="command">новая команда</param> /// <returns></returns> public static int WriteCommand(TradeTaskRequest command) { var fileName = DecimalTradeDBhelper.CreateFileName(command.currencyPair); try { if (!File.Exists(fileName)) { DecimalTradeDBhelper.InitDbCommandResponse(fileName); } using (var tf = TeaFile <TradeTaskRequest> .Append(fileName)) { // if the stream is a filestream that was opened in FileMode.Append, this call is redundant. // this line is here for the allowed case were the stream and headerstream point to the same stream. //https://github.com/discretelogics/TeaFiles.Net-time-series-storage-in-flat-files/blob/938e3fd46e9c55b80e81163495cdd30ebd0112c4/TeaFiles/TeaFileT.cs //tf.SetFilePointerToEnd(); tf.Write(command); // TODO транзакция } return(1); } catch (Exception ex) { //Logger.Log.Error("Произошла ошибка! Команда не была записана"); } return(0); }
internal static void InitDbCommand(string fileNameCommand) { TradeTaskRequest lastCommand = new TradeTaskRequest() { command = CommandType.Wait, currencyPair = MoneyPair.btc_usdt, Id = 1, requestTime = DateTime.Now }; try { using (var tf = TeaFile <TradeTaskRequest> .Create(fileNameCommand)) { tf.Write(lastCommand); } } catch (Exception ex) { //Logger.Log.Error("Ошибка! Не удалось создать файл базы данных нейросети"); } }
/// <summary> /// Получаем последнюю команду от нейросети /// </summary> /// <returns></returns> public static TradeTaskRequest ReadLastCommand() { if (!File.Exists(fileNameCommand)) { InitDbCommand(fileNameCommand); } TradeTaskRequest lastCommand = new TradeTaskRequest(); try { Stopwatch watch = Stopwatch.StartNew(); var teaCurrencyPairs = new List <TradeTaskRequest>(); using (var tf = TeaFile <TradeTaskRequest> .OpenRead(fileNameCommand)) { lastCommand = tf.Items.Last(); } } catch (Exception ex) { //Logger.Log.Error("Произошла ошибка! Не удалось прочитать последнюю команду от нейросети"); } return(lastCommand); }