OS Trading Engine
Technical Documentation
Database
Tables Reference

Tables Reference

Complete column reference for all Nexgent database tables.


users

User accounts for authentication.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
emailvarchar(255)UNIQUE, NOT NULLUser email address
password_hashvarchar(255)NULLABLEbcrypt password hash
created_attimestamptzNOT NULL, DEFAULT now()Account creation time
failed_login_attemptsintNOT NULL, DEFAULT 0Failed login counter
locked_untiltimestamptzNULLABLEAccount lockout expiry

Indexes: email (unique)


api_keys

API keys for programmatic access.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
user_iduuidFK → users, NOT NULLOwner user
namevarchar(100)NOT NULLKey display name
key_hashtextUNIQUE, NOT NULLbcrypt hash of key
key_prefixvarchar(12)NOT NULLFirst 12 chars for identification
scopestext[]NOT NULL, DEFAULT []Permission scopes
created_attimestamptzNOT NULL, DEFAULT now()Creation time

Indexes: user_id, key_hash (unique)

The raw API key is only shown once at creation. Only the hash is stored.


agents

Trading agents created by users.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
user_iduuidFK → users, NOT NULLOwner user
namevarchar(255)NOT NULLAgent display name
trading_modevarchar(20)NOT NULL, DEFAULT 'simulation''simulation' or 'live'
automated_trading_simulationbooleanNOT NULL, DEFAULT trueAuto-trade in simulation
automated_trading_livebooleanNOT NULL, DEFAULT trueAuto-trade in live
trading_configjsonbNULLABLEAgentTradingConfig JSON
created_attimestamptzNOT NULL, DEFAULT now()Creation time
updated_attimestamptzNOT NULLLast update time

Indexes: user_id


agent_wallets

Wallet assignments for agents. Private keys are never stored.

ColumnTypeConstraintsDescription
wallet_addressvarchar(44)PKSolana wallet address
agent_iduuidFK → agents, NOT NULLAssigned agent
wallet_typevarchar(20)NOT NULL'simulation' or 'live'
created_attimestamptzNOT NULL, DEFAULT now()Assignment time
updated_attimestamptzNOT NULLLast update time

Indexes: agent_id

Unique Constraints: (agent_id, wallet_type) - One wallet per mode per agent


agent_balances

Token balances per wallet.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
agent_iduuidFK → agents, NOT NULLOwner agent
wallet_addressvarchar(44)FK → agent_wallets, NOT NULLWallet address
token_addressvarchar(255)NOT NULLToken mint address
token_symbolvarchar(20)NOT NULLToken symbol (e.g., SOL)
balancetextNOT NULLBalance as string (arbitrary precision)
last_updatedtimestamptzNOT NULLLast balance update

Indexes: agent_id, wallet_address, (agent_id, wallet_address), token_address

Unique Constraints: (wallet_address, token_address) - One balance per token per wallet

💡

Balance is stored as string to support arbitrary precision for all token types.


agent_positions

Open trading positions with stop loss state.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
agent_iduuidFK → agents, NOT NULLOwner agent
wallet_addressvarchar(44)FK → agent_wallets, NOT NULLWallet address
token_addressvarchar(255)NOT NULLToken mint address
token_symbolvarchar(20)NOT NULLToken symbol
purchase_transaction_iduuidFK → agent_transactions, UNIQUEInitial purchase
purchase_pricedecimal(30,18)NOT NULLPrice at purchase (SOL per token)
purchase_amountdecimal(30,18)NOT NULLToken amount purchased
current_stop_loss_percentagedecimal(5,2)NULLABLEActive stop loss %
peak_pricedecimal(30,18)NULLABLEHighest price seen
lowest_pricedecimal(30,18)NULLABLELowest price seen
last_stop_loss_updatetimestamptzNULLABLELast SL evaluation
dca_countintNOT NULL, DEFAULT 0Number of DCA buys
dca_transaction_idsuuid[]NOT NULL, DEFAULT []DCA transaction refs
last_dca_timetimestamptzNULLABLELast DCA execution
total_invested_soldecimal(20,8)NOT NULL, DEFAULT 0Total SOL invested
created_attimestamptzNOT NULL, DEFAULT now()Position open time
updated_attimestamptzNOT NULLLast update time

Indexes: agent_id, token_address, (agent_id, wallet_address), purchase_transaction_id

Unique Constraints: (agent_id, wallet_address, token_address) - One position per token per wallet


agent_transactions

All transaction records (deposits, withdrawals, swaps, burns).

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
agent_iduuidFK → agents, NOT NULLOwner agent
wallet_addressvarchar(44)FK → agent_wallets, NULLABLEWallet address
transaction_typeenumNOT NULLDEPOSIT, WITHDRAWAL, SWAP, BURN
transaction_value_usddecimal(20,8)NOT NULLUSD value at time
transaction_timetimestamptzNOT NULLExecution time
destination_addressvarchar(255)NULLABLEFor withdrawals
signal_idintFK → trading_signals, NULLABLETriggering signal
feesdecimal(20,8)NULLABLETransaction fees
routesjsonbNULLABLEJupiter route info
input_mintvarchar(255)NULLABLEInput token address
input_symbolvarchar(20)NULLABLEInput token symbol
input_amountdecimal(30,18)NULLABLEInput amount
input_pricedecimal(30,18)NULLABLEInput price
output_mintvarchar(255)NULLABLEOutput token address
output_symbolvarchar(20)NULLABLEOutput token symbol
output_amountdecimal(30,18)NULLABLEOutput amount
output_pricedecimal(30,18)NULLABLEOutput price
slippagedecimal(10,4)NULLABLEActual slippage
price_impactdecimal(10,4)NULLABLEPrice impact
is_dcabooleanNOT NULL, DEFAULT falseIs DCA transaction
transaction_hashvarchar(255)NULLABLEOn-chain tx hash
swap_payloadjsonbNULLABLEFull Jupiter response
created_attimestamptzNOT NULL, DEFAULT now()Record creation
updated_attimestamptzNOT NULLLast update

Indexes: agent_id, wallet_address, (agent_id, wallet_address), transaction_type, transaction_time, signal_id, (agent_id, transaction_time), (agent_id, transaction_type)


agent_historical_swaps

Completed trade records with profit/loss.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
agent_iduuidFK → agents, NOT NULLOwner agent
wallet_addressvarchar(44)FK → agent_wallets, NULLABLEWallet address
token_addressvarchar(255)NOT NULLToken mint address
token_symbolvarchar(20)NOT NULLToken symbol
amountdecimal(30,18)NOT NULLToken amount traded
purchase_pricedecimal(30,18)NOT NULLBuy price
sale_pricedecimal(30,18)NOT NULLSell price
change_percentdecimal(10,4)NOT NULL% change
profit_loss_usddecimal(20,8)NOT NULLP/L in USD
profit_loss_soldecimal(20,8)NOT NULLP/L in SOL
purchase_timetimestamptzNOT NULLBuy time
sale_timetimestamptzNOT NULLSell time
purchase_transaction_iduuidFK → agent_transactions, NULLABLEBuy transaction
sale_transaction_iduuidFK → agent_transactions, NULLABLESell transaction
signal_idintFK → trading_signals, NULLABLEOriginal signal
close_reasonvarchar(20)NULLABLEstop_loss, stale_trade, manual, etc.
created_attimestamptzNOT NULL, DEFAULT now()Record creation

Indexes: agent_id, wallet_address, (agent_id, wallet_address), token_address, signal_id, purchase_transaction_id, sale_transaction_id, purchase_time, sale_time, (agent_id, token_address), (agent_id, purchase_time), (agent_id, sale_time), (agent_id, created_at), (agent_id, signal_id)


agent_balance_snapshots

Hourly portfolio snapshots for charting.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
agent_iduuidFK → agents, NOT NULLOwner agent
wallet_addressvarchar(44)FK → agent_wallets, NOT NULLWallet address
snapshot_timestamptimestamptzNOT NULLSnapshot time (hourly)
portfolio_balance_soldecimal(20,8)NOT NULLTotal portfolio in SOL
sol_balancedecimal(20,8)NOT NULLSOL balance only
positions_value_soldecimal(20,8)NOT NULLOpen positions value
unrealized_pnl_soldecimal(20,8)NOT NULLUnrealized P/L
created_attimestamptzNOT NULL, DEFAULT now()Record creation
updated_attimestamptzNOT NULLLast update

Indexes: (agent_id, wallet_address, snapshot_timestamp), wallet_address, snapshot_timestamp

Unique Constraints: (agent_id, wallet_address, snapshot_timestamp) - One snapshot per hour per wallet


trading_signals

Trading signals from external sources.

ColumnTypeConstraintsDescription
idserialPKAuto-increment ID
token_addressvarchar(255)NOT NULLToken mint address
symbolvarchar(50)NULLABLEToken symbol
signal_typevarchar(50)NOT NULLSignal type (e.g., 'buy')
activation_reasontextNULLABLEWhy signal was created
signal_strengthintNOT NULLStrength 1-5
sourcevarchar(100)NULLABLESignal source
created_attimestamptzNOT NULL, DEFAULT now()Signal creation time
updated_attimestamptzNOT NULLLast update

Indexes: token_address, signal_type, created_at


signal_executions

Signal processing status per agent.

ColumnTypeConstraintsDescription
iduuidPKUnique identifier
signal_idintFK → trading_signals, NOT NULLSignal reference
agent_iduuidFK → agents, NOT NULLAgent reference
statusvarchar(20)NOT NULLsuccess, failed, skipped
transaction_iduuidFK → agent_transactions, NULLABLEResulting transaction
errortextNULLABLEError message if failed
executed_attimestamptzNOT NULL, DEFAULT now()Execution time

Indexes: signal_id, agent_id

Unique Constraints: (signal_id, agent_id) - One execution per agent per signal


Enums

TransactionType

CREATE TYPE "TransactionType" AS ENUM (
  'DEPOSIT',
  'WITHDRAWAL',
  'SWAP',
  'BURN'
);