Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trade log capability #107

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

TheoBrigitte
Copy link
Contributor

@TheoBrigitte TheoBrigitte commented May 11, 2024

This PR add capability to log trades into a journal file.

Here is an example of journal log entry

{
  "mint": "APW3JozNF2N1rCzN6nbgJNN3fWGS8qLgiY3DVeK6BpzV",
  "balance": 1.001200061,
  "amountIn": 0.001,
  "amountOut": 0.001227753,
  "profit": 0.00022775300000000003,
  "profitPercent": 22.7753,
  "start": "2024-05-11T08:24:22.440Z",
  "end": "2024-05-11T08:26:12.827Z",
  "time_to_entry": "0:05",
  "time_to_exit": "0:05",
  "status": "closed",
  "id": 1
}

It uses the LOG_FILENAME variable to define the journal file and can be set to none to disable logging.

Add capability to log trades into a journal file
helpers/trade.ts Outdated
// Trade sold, compute profit.
confirmedSell(amountOut: number) {
this.data.amountOut = amountOut;
this.data.profit = this.data.amountOut - this.data.amountIn.valueOf();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NOTE: profit computation does not account for fee

@@ -275,7 +317,20 @@ export class Bot {
}
} catch (error) {
logger.error({ mint: rawAccount.mint.toString(), error }, `Failed to sell token`);
if (trade) {
trade.close(0, 0, 'sell_failed');
this.balance += trade.profit;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not really needed since we later on call this.updatebalance, but that's paving the way for a future dry run mode implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants