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 and take-profit 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 (original)
remaining_amountdecimal(30,18)NULLABLETokens remaining after take-profit
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
take_profit_levels_hitintNOT NULL, DEFAULT 0Number of TP levels triggered
take_profit_transaction_idstext[]NOT NULL, DEFAULT []TP sale transaction refs
last_take_profit_timetimestamptzNULLABLELast TP execution
moon_bag_activatedbooleanNOT NULL, DEFAULT falseMoon bag set aside
moon_bag_amountdecimal(30,18)NULLABLETokens reserved as moon bag
realized_profit_soldecimal(20,8)NULLABLECumulative profit from TP sales
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

Take-Profit Fields: remaining_amount tracks tokens after partial sales, take_profit_levels_hit counts executed levels, and realized_profit_sol accumulates profit from take-profit sales. When take-profit is enabled, remaining_amount may be less than purchase_amount.


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
is_take_profitbooleanNOT NULL, DEFAULT falseIs take-profit sale
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 (original position)
purchase_pricedecimal(30,18)NOT NULLBuy price (weighted average)
sale_pricedecimal(30,18)NOT NULLSell price (effective average if take-profit)
change_percentdecimal(10,4)NOT NULL% return (vs original cost basis)
profit_loss_usddecimal(20,8)NOT NULLTotal P/L in USD (includes take-profit)
profit_loss_soldecimal(20,8)NOT NULLTotal P/L in SOL (includes take-profit)
purchase_timetimestamptzNOT NULLBuy time
sale_timetimestamptzNOT NULLFinal sale time
purchase_transaction_iduuidFK → agent_transactions, NULLABLEBuy transaction
sale_transaction_iduuidFK → agent_transactions, NULLABLEFinal sell transaction
signal_idintFK → trading_signals, NULLABLEOriginal signal
close_reasonvarchar(20)NULLABLEstop_loss, stale_trade, manual, take_profit
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)

Positions with Take-Profit: For positions that had take-profit sales, amount is the original position size, sale_price is the effective average across all sales (take-profit + final close), and profit_loss_sol includes realized profit from all sales. The close_reason may be take_profit if the final close was triggered by take-profit completing.


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'
);