pymarket.transactions.transactions module¶
-
class
pymarket.transactions.transactions.
TransactionManager
[source]¶ Bases:
object
An interaface to store and manage all transactions. Transactions are the minimal unit to represent the outcome of a market.
-
name_col
¶ Name of the columns to use in the dataframe returned.
Type: list of str
-
trans
¶ List of the actual transactions available
Type: list of tuples
-
add_transaction
(bid, quantity, price, source, active)[source]¶ Add a transaction to the transactions list
Parameters: - bid (int) – Unique identifier of the bid
- quantity (float) – transacted quantity
- price (float) – transacted price
- source (int) – Identifier of the second party in the trasaction, -1 if there is no clear second party, such as in a double auction.
- active – True` if the bid is still active after the transaction.
Returns: trans_id – id of the added transaction, -1 if fails
Return type: Examples
>>> tm = pm.TransactionManager() >>> tm.add_transaction(1, 0.5, 2.1, -1, False) 0 >>> tm.trans [(1, 0.5, 2.1, -1, False)] >>> tm.n_trans 1
-
get_df
()[source]¶ Returns the transaction dataframe
Returns: df – A pandas dataframe representing all the transactions stored. Return type: pd.DataFrame Examples
>>> tm = pm.TransactionManager() >>> tm.add_transaction(1, 0.5, 2.1, -1, False) 0 >>> tm.add_transaction(5, 0, 0, 3, True) 1 >>> tm.get_df() bid quantity price source active 0 1 0.5 2.1 -1 False 1 5 0.0 0.0 3 True
-
merge
(other)[source]¶ Merges two transaction managers with each other There are no checks on whether the new TransactionManger is consisten after the merge.
Parameters: other (TransactionManager) – A different transaction manager to merge with Returns: trans – A new transaction Manager with the transactions of the two. Return type: TransactionManager Examples
>>> tm_1 = pm.TransactionManager() >>> tm_1.add_transaction(1, 0.5, 2.1, -1, False) 0 >>> tm_2 = pm.TransactionManager() >>> tm_2.add_transaction(5, 0, 0, 3, True) 0 >>> tm_3 = tm_1.merge(tm_2) >>> tm_3.get_df() bid quantity price source active 0 1 0.5 2.1 -1 False 1 5 0.0 0.0 3 True
-
name_col
= ['bid', 'quantity', 'price', 'source', 'active']
-