
    'i                     f    d dl mZmZmZmZ d dlZd dlZd dlmZm	Z	  G d dej                        Zy)    )absolute_importdivisionprint_functionunicode_literalsN)OrderPositionc                   2     e Zd ZdZdZ fdZd Zd Z xZS )Transactionsa  This analyzer reports the transactions occurred with each an every data in
    the system

    It looks at the order execution bits to create a ``Position`` starting from
    0 during each ``next`` cycle.

    The result is used during next to record the transactions

    Params:

      - headers (default: ``True``)

        Add an initial key to the dictionary holding the results with the names
        of the datas

        This analyzer was modeled to facilitate the integration with
        ``pyfolio`` and the header names are taken from the samples used for
        it::

          'date', 'amount', 'price', 'sid', 'symbol', 'value'

    Methods:

      - get_analysis

        Returns a dictionary with returns as values and the datetime points for
        each return as keys
    ))headersF)
_pfheaders)dateamountpricesidsymbolvaluec                    t         t        |           | j                  j                  rGt        | j                  j                  dd        g| j                  | j                  j                  d   <   t        j                  t              | _        t        t        | j                  j                                     | _        y )N   r   )superr
   startpr   listr   retscollectionsdefaultdictr   
_positions	enumeratestrategygetdatanames_idnames)self	__class__s    _/var/www/app/trading-bot/venv/lib/python3.12/site-packages/backtrader/analyzers/transactions.pyr   zTransactions.startA   s    lD')66>>/3DFF4E4Eab4I/J.KDIIdff''*+%11(;Yt}}'A'A'CDE    c                 6   |j                   t        j                  t        j                  fvry | j                  |j
                  j                     }|j                  j                         D ],  }| y |j                  |j                  |j                         . y N)statusr   Partial	Completedr   data_nameexecutediterpendingupdatesizer   )r!   orderposexbits       r#   notify_orderzTransactions.notify_orderI   sr     <<u??ooejj../^^//1 	0E}JJuzz5;;/		0r$   c           	      r   g }| j                   D ]Y  \  }}| j                  j                  |d       }|%|j                  |j                  }}|s@|j                  ||||| |z  g       [ |r1|| j                  | j                  j                  j                         <   | j                  j                          y r&   )
r    r   getr/   r   appendr   r   datetimeclear)r!   entriesidnamer1   r/   r   s          r#   nextzTransactions.nextZ   s     	KHAu//%%eT2C!hh		eNND%ED55=#IJ	K ;BDIIdmm,,5578r$   )	__name__
__module____qualname____doc__paramsr   r3   r<   __classcell__)r"   s   @r#   r
   r
      s    8F
F0" r$   r
   )
__future__r   r   r   r   r   
backtraderbtr   r   Analyzerr
    r$   r#   <module>rH      s,   ** *   &H 2;; H r$   