From 3b0080858030174a33d918154757b0ded3ec62a9 Mon Sep 17 00:00:00 2001 From: Sneha Debnath Date: Tue, 9 Dec 2025 23:31:08 +0530 Subject: [PATCH] Add crypto price logging feature and improve exchange initialization --- .../Php/Exchange/ExchangeManager.php | 37 +++++++++++-------- .../Resources/Php/Exchange/PriceLogger.php | 26 +++++++++++++ README.md | 6 +++ 3 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 Exchange/Resources/Php/Exchange/PriceLogger.php diff --git a/Exchange/Resources/Php/Exchange/ExchangeManager.php b/Exchange/Resources/Php/Exchange/ExchangeManager.php index df09781..e28e2b3 100644 --- a/Exchange/Resources/Php/Exchange/ExchangeManager.php +++ b/Exchange/Resources/Php/Exchange/ExchangeManager.php @@ -1,15 +1,22 @@ - \ No newline at end of file +logPrice($exchange, 0.0); + + // TODO: exchange selection + return new Binance($apiKey, $apiSecret); + } +} +?> diff --git a/Exchange/Resources/Php/Exchange/PriceLogger.php b/Exchange/Resources/Php/Exchange/PriceLogger.php new file mode 100644 index 0000000..0d51b17 --- /dev/null +++ b/Exchange/Resources/Php/Exchange/PriceLogger.php @@ -0,0 +1,26 @@ +logFile = __DIR__ . "/price_history.log"; + } + + public function logPrice(string $symbol, float $price): void + { + $timestamp = date("Y-m-d H:i:s"); + + $entry = "[" . $timestamp . "] " . $symbol . " => " . $price . PHP_EOL; + + try { + file_put_contents($this->logFile, $entry, FILE_APPEND); + } catch (\Exception $e) { + error_log("Price Logger Error: " . $e->getMessage()); + } + } +} diff --git a/README.md b/README.md index c12c1d5..c777ea7 100644 --- a/README.md +++ b/README.md @@ -116,3 +116,9 @@ class ExchangeName extends Exchange { Im not sure if i will continue to work on this project, but if people want me to i will probaly continue. For private support, Contact me via discord Rick404#8294. + + +## Contribution + +This project was improved as part of a learning contribution. +Contributor: Sneha Debnath