Skip to content

Commit

Permalink
Adding changes from lazy pnl update
Browse files Browse the repository at this point in the history
  • Loading branch information
wshainin committed Jun 24, 2024
1 parent 85406f8 commit ab49768
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/agent0/traiderdaive/gym_environments/full_hyperdrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,18 @@ def __init__(
self.eval_mode = gym_config.eval_mode
self.sample_actions = gym_config.sample_actions
if self.eval_mode:
local_chain_config = LocalChain.Config(block_timestamp_interval=12, db_port=5434, chain_port=10001)
db_port = 5434
chain_port = 10001
else:
local_chain_config = LocalChain.Config(block_timestamp_interval=12, db_port=5435, chain_port=10002)
db_port = 5435
chain_port = 10002

local_chain_config = LocalChain.Config(
block_timestamp_interval=12,
db_port=db_port,
chain_port=chain_port,
calc_pnl=False)

initial_pool_config = LocalHyperdrive.Config()
self.chain = LocalChain(local_chain_config)
self.interactive_hyperdrive = LocalHyperdrive(self.chain, initial_pool_config)
Expand Down Expand Up @@ -507,7 +516,7 @@ def _get_observation(self) -> dict[str, np.ndarray]:
out_obs["lp_orders"] = np.zeros(2)

# Observation data uses floats
rl_bot_wallet = self.rl_bot.get_positions(coerce_float=True)
rl_bot_wallet = self.rl_bot.get_positions(coerce_float=True, calc_pnl=True)

if not rl_bot_wallet.empty:
position_duration = self.interactive_hyperdrive.config.position_duration
Expand Down Expand Up @@ -543,7 +552,10 @@ def _get_observation(self) -> dict[str, np.ndarray]:
def _calculate_reward(self) -> float:
# The total delta for this episode

current_wallet = self.interactive_hyperdrive.get_positions(show_closed_positions=True, coerce_float=True)
current_wallet = self.interactive_hyperdrive.get_positions(
show_closed_positions=True,
calc_pnl=True,
coerce_float=True)
# Filter by rl bot
rl_bot_wallet = current_wallet[current_wallet["wallet_address"] == self.rl_bot.address]
# The rl_bot_wallet shows the pnl of all positions
Expand Down

0 comments on commit ab49768

Please sign in to comment.