Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions Exchange/Resources/Php/Exchange/ExchangeManager.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<?php

namespace Resources\Php\Exchange;

use Resources\Php\Exchange\exchanges\Binance;

class ExchangeManager {
private string $selectedExchange = 'binance';

public function getExchange(string $exchange, string $apiKey, string $apiSecret): Exchange {
//TODO: exchange selection
return new Binance($apiKey, $apiSecret);
}
}
?>
<?php

namespace Resources\Php\Exchange;

use Resources\Php\Exchange\exchanges\Binance;
use Resources\Php\Exchange\PriceLogger;

class ExchangeManager {

private string $selectedExchange = 'binance';

public function getExchange(string $exchange, string $apiKey, string $apiSecret): Exchange
{
// Log when exchange is initialized
$logger = new PriceLogger();
$logger->logPrice($exchange, 0.0);

// TODO: exchange selection
return new Binance($apiKey, $apiSecret);
}
}
?>
26 changes: 26 additions & 0 deletions Exchange/Resources/Php/Exchange/PriceLogger.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Resources\Php\Exchange;

class PriceLogger
{
private string $logFile;

public function __construct()
{
$this->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());
}
}
}
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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