replay
This commit is contained in:
@ -2,37 +2,56 @@ import sys
|
||||
import os
|
||||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||
|
||||
import json
|
||||
from typing import NamedTuple
|
||||
|
||||
class Transaction(NamedTuple):
|
||||
wallet: str
|
||||
transaction_type: str
|
||||
symbol_in: str
|
||||
amount_in: float
|
||||
value_in_usd: float
|
||||
symbol_out: str
|
||||
amount_out: float
|
||||
value_out_usd: float
|
||||
tx_signature: str
|
||||
|
||||
from enum import Enum
|
||||
from datetime import datetime
|
||||
import prisma
|
||||
from enum import Enum
|
||||
import json
|
||||
from prisma import Prisma
|
||||
|
||||
class TransactionStatus(Enum):
|
||||
PENDING = "PENDING"
|
||||
SENT = "SENT"
|
||||
CONFIRMED = "CONFIRMED"
|
||||
|
||||
# Initialize the Prisma client
|
||||
prisma_client = Prisma()
|
||||
|
||||
async def init_db():
|
||||
await prisma_client.connect()
|
||||
|
||||
async def store_transaction(transaction_data):
|
||||
async def store_transaction(transaction: Transaction):
|
||||
"""
|
||||
Store a transaction record in the database using a dictionary.
|
||||
Store a transaction record in the database.
|
||||
"""
|
||||
default_data = {
|
||||
'wallet_id': None,
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'type': None,
|
||||
'sell_currency': None,
|
||||
'sell_amount': 0.0,
|
||||
'sell_value': 0.0,
|
||||
'buy_currency': None,
|
||||
'buy_amount': 0.0,
|
||||
'buy_value': 0.0,
|
||||
'solana_signature': None,
|
||||
'details': json.dumps({}),
|
||||
'status': prisma_client.transactionStatus.ORIGINAL
|
||||
}
|
||||
default_data.update(transaction_data)
|
||||
await prisma_client.transaction.create(data=default_data)
|
||||
await prisma_client.transaction.create(
|
||||
data={
|
||||
'wallet_id': transaction.wallet,
|
||||
'timestamp': datetime.now().isoformat(),
|
||||
'type': transaction.transaction_type,
|
||||
'sell_currency': transaction.symbol_in,
|
||||
'sell_amount': transaction.amount_in,
|
||||
'sell_value': transaction.value_in_usd,
|
||||
'buy_currency': transaction.symbol_out,
|
||||
'buy_amount': transaction.amount_out,
|
||||
'buy_value': transaction.value_out_usd,
|
||||
'solana_signature': transaction.tx_signature,
|
||||
'details': json.dumps({}),
|
||||
'status': TransactionStatus.PENDING.value
|
||||
}
|
||||
)
|
||||
|
||||
async def update_holdings(wallet_id, currency, amount_change):
|
||||
holding = await prisma_client.holding.find_first(
|
||||
|
Reference in New Issue
Block a user