Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
players_per_group = models.IntegerField()
round_length = models.IntegerField()
batch_length = models.IntegerField(initial=0)
trade_ended = models.BooleanField(initial=False)
code = models.CharField(default=random_chars_8)
has_trial = models.BooleanField(initial=True)
is_trial = models.BooleanField(initial=False)
trial_length = models.IntegerField(initial=0)
log_file = models.StringField()
first_round = models.IntegerField(initial=1)
last_round = models.IntegerField(initial=0)
total_rounds = models.IntegerField(initial=0)
restore_from = models.CharField()
restore = models.BooleanField(initial=False)
lambda_i = models.FloatField()
lambda_j = models.FloatField()
def init_cache(self):
pairs = {}
session_lock = Constants.lock_key.format(self=self)
pairs[session_lock] = Constants.unlock_value
ready_groups = Constants.groups_ready_key.format(self=self)
pairs[ready_groups] = {g.id: False for g in self.get_groups()}
for k, v in pairs.items():
cache.set(k, v, timeout=None)
def convert_lambdas(self):
self.lambda_i = round(1 / self.lambda_i, 1)
self.lambda_j = round(1 / self.lambda_j, 1)
self.save()
def set_payoff_round(self):
csv_meta = (
'timestamp', 'subsession_id', 'market_id', 'player_id', 'trigger_event_type',
'event_no', 'trader_model_name', 'inventory', 'bid', 'offer',
'best_bid_except_me', 'best_offer_except_me',
'delay', 'staged_bid', 'staged_offer', 'implied_bid',
'implied_offer', 'slider_a_x','slider_a_y', 'slider_a_z',
'net_worth', 'cash', 'tax_paid', 'speed_cost', 'midpoint_peg', 'peg_price', 'peg_state')
# timestamp = models.DateTimeField(default=timezone.now)
# trigger_event_type = models.CharField()
# event_no = models.IntegerField()
# subsession_id = models.IntegerField()
# market_id = models.IntegerField()
player_id = models.IntegerField()
trader_model_name = models.CharField()
delay = models.FloatField()
net_worth = models.IntegerField()
cash = models.IntegerField()
cost = models.IntegerField()
speed_cost = models.IntegerField()
tax_paid = models.IntegerField()
reference_price = models.IntegerField()
inventory = models.IntegerField()
bid = models.IntegerField()
offer = models.IntegerField()
staged_bid = models.IntegerField()
staged_offer = models.IntegerField()
implied_bid = models.IntegerField()
implied_offer = models.IntegerField()
best_bid = models.IntegerField()
best_offer = models.IntegerField()
best_bid_except_me = models.IntegerField()
implied_offer = models.IntegerField()
best_bid = models.IntegerField()
best_offer = models.IntegerField()
e_best_bid = models.IntegerField()
e_best_offer = models.IntegerField()
slider_a_x = models.FloatField()
slider_a_y = models.FloatField()
slider_a_z = models.FloatField()
signed_volume = models.FloatField()
e_signed_volume = models.FloatField()
# fields for this player's initial strategy decisions
# these are set from the InitialDecisionSelection form
initial_slider_a_x = models.FloatField()
initial_slider_a_y = models.FloatField()
initial_slider_a_z = models.FloatField()
initial_role = models.CharField()
initial_speed_on = models.BooleanField()
def configure_for_trade_session(self, market, session_format: str):
for field in ('exchange_host', 'exchange_port', 'market_id', 'subsession_id'):
setattr(self, field, getattr(market, field))
utility.configure_model_for_market('player', self, session_format,
self.session.config)
self.save()
def update_from_state_record(self, state_record):
for field in state_record._meta.fields:
if hasattr(self, field.name):
attr = getattr(self, field.name)
if attr is None:
setattr(self, field.name, getattr(state_record, field.name))
staged_offer = models.IntegerField()
implied_bid = models.IntegerField()
implied_offer = models.IntegerField()
best_bid = models.IntegerField()
best_offer = models.IntegerField()
best_bid_except_me = models.IntegerField()
best_offer_except_me = models.IntegerField()
next_bid = models.IntegerField()
next_offer = models.IntegerField()
volume_at_best_bid = models.IntegerField()
volume_at_best_offer = models.IntegerField()
e_best_bid = models.IntegerField()
e_best_offer = models.IntegerField()
slider_a_x = models.FloatField()
slider_a_y = models.FloatField()
slider_a_z = models.FloatField()
signed_volume = models.FloatField()
e_signed_volume = models.FloatField()
midpoint_peg = models.BooleanField()
peg_price = models.IntegerField()
peg_state = models.IntegerField()
class MarketRecord(TimeAwareInSessionRecord):
csv_meta = (
'timestamp', 'subsession_id', 'market_id', 'player_id', 'trigger_event_type',
'event_no', 'reference_price', 'best_bid', 'best_offer',
'next_bid', 'next_offer', 'volume_at_best_bid', 'volume_at_best_offer',
'e_best_bid', 'e_best_offer', 'signed_volume', 'e_signed_volume', 'clearing_price', 'transacted_volume')
reference_price = models.IntegerField()
# not abstracting for reuse
from otree.api import models
from otree.db.models import Model, ForeignKey
from .cache import get_cache_key
from django.core.cache import cache
from .output import TraderRecord
import logging
log = logging.getLogger(__name__)
class HFTPlayerSessionSummary(Model):
subsession_id = models.StringField()
player_id = models.IntegerField()
market_id = models.IntegerField()
signed_vol_sensitivity = models.FloatField(initial=0.0)
inventory_sensitivity = models.FloatField(initial=0.0)
external_feed_sensitivity = models.FloatField(initial=0.0)
time_as_automated = models.FloatField(initial=0.0)
time_as_out = models.FloatField(initial=0.0)
time_as_manual = models.FloatField(initial=0.0)
net_worth = models.IntegerField(initial=0)
tax_paid = models.IntegerField(initial=0)
speed_cost = models.IntegerField(initial=0)
def state_for_results_template(player):
summary_objects = HFTPlayerSessionSummary.objects.filter(subsession_id=player.subsession.id,
market_id=player.market_id)
nets = {str(o.player_id): o.net_worth * 0.0001 for o in summary_objects}
taxes = {str(o.player_id): o.tax_paid * 0.0001 for o in summary_objects}
print([o.speed_cost for o in summary_objects])
speed_costs = {str(o.player_id): o.speed_cost * 0.0001 for o in summary_objects}
submitted_file = ForeignKey(ExogenousEventFile, on_delete=models.CASCADE)
arrival_time = models.FloatField()
market_id_in_subsession = models.StringField()
price = models.IntegerField()
time_in_force = models.IntegerField()
buy_sell_indicator = models.StringField()
class ExternalFeedRecord(Model, CSVRowMixIn):
submitted_file = ForeignKey(ExogenousEventFile, on_delete=models.CASCADE)
arrival_time = models.FloatField()
market_id_in_subsession = models.StringField()
e_best_bid = models.IntegerField()
e_best_offer = models.IntegerField()
e_signed_volume = models.FloatField()
def handle_exogenous_event_file(filename, filelike, record_cls, record_type):
if None in (filename, filelike):
raise Exception('null input {}:{}'.format(filename, filelike))
if not isinstance(filename, str):
try:
filename = str(filename)
except:
raise Exception('invalid filename {}'.format(filename))
if not len(filename):
raise Exception('filename should have at least one character %s' % filename)
if ExogenousEventFile.objects.filter(upload_name=filename).exists():
log.warning('event file: {} already in db, overwriting.'.format(filename))
file_record = ExogenousEventFile.objects.get(upload_name=filename)
file_record.delete()
implied_offer = models.IntegerField()
best_bid = models.IntegerField()
best_offer = models.IntegerField()
best_bid_except_me = models.IntegerField()
best_offer_except_me = models.IntegerField()
next_bid = models.IntegerField()
next_offer = models.IntegerField()
volume_at_best_bid = models.IntegerField()
volume_at_best_offer = models.IntegerField()
e_best_bid = models.IntegerField()
e_best_offer = models.IntegerField()
slider_a_x = models.FloatField()
slider_a_y = models.FloatField()
slider_a_z = models.FloatField()
signed_volume = models.FloatField()
e_signed_volume = models.FloatField()
midpoint_peg = models.BooleanField()
peg_price = models.IntegerField()
peg_state = models.IntegerField()
class MarketRecord(TimeAwareInSessionRecord):
csv_meta = (
'timestamp', 'subsession_id', 'market_id', 'player_id', 'trigger_event_type',
'event_no', 'reference_price', 'best_bid', 'best_offer',
'next_bid', 'next_offer', 'volume_at_best_bid', 'volume_at_best_offer',
'e_best_bid', 'e_best_offer', 'signed_volume', 'e_signed_volume', 'clearing_price', 'transacted_volume')
reference_price = models.IntegerField()
best_bid = models.IntegerField()
best_offer = models.IntegerField()
next_available_exchange = models.IntegerField()
players_per_group = models.IntegerField()
round_length = models.IntegerField()
batch_length = models.IntegerField(initial=0)
trade_ended = models.BooleanField(initial=False)
code = models.CharField(default=random_chars_8)
has_trial = models.BooleanField(initial=True)
is_trial = models.BooleanField(initial=False)
trial_length = models.IntegerField(initial=0)
log_file = models.StringField()
first_round = models.IntegerField(initial=1)
last_round = models.IntegerField(initial=0)
total_rounds = models.IntegerField(initial=0)
restore_from = models.CharField()
restore = models.BooleanField(initial=False)
lambda_i = models.FloatField()
lambda_j = models.FloatField()
def init_cache(self):
pairs = {}
session_lock = Constants.lock_key.format(self=self)
pairs[session_lock] = Constants.unlock_value
ready_groups = Constants.groups_ready_key.format(self=self)
pairs[ready_groups] = {g.id: False for g in self.get_groups()}
for k, v in pairs.items():
cache.set(k, v, timeout=None)
def convert_lambdas(self):
self.lambda_i = round(1 / self.lambda_i, 1)
self.lambda_j = round(1 / self.lambda_j, 1)
self.save()
speed_cost = models.IntegerField()
tax_paid = models.IntegerField()
reference_price = models.IntegerField()
inventory = models.IntegerField()
bid = models.IntegerField()
offer = models.IntegerField()
staged_bid = models.IntegerField()
staged_offer = models.IntegerField()
implied_bid = models.IntegerField()
implied_offer = models.IntegerField()
best_bid = models.IntegerField()
best_offer = models.IntegerField()
e_best_bid = models.IntegerField()
e_best_offer = models.IntegerField()
slider_a_x = models.FloatField()
slider_a_y = models.FloatField()
slider_a_z = models.FloatField()
signed_volume = models.FloatField()
e_signed_volume = models.FloatField()
# fields for this player's initial strategy decisions
# these are set from the InitialDecisionSelection form
initial_slider_a_x = models.FloatField()
initial_slider_a_y = models.FloatField()
initial_slider_a_z = models.FloatField()
initial_role = models.CharField()
initial_speed_on = models.BooleanField()
def configure_for_trade_session(self, market, session_format: str):
for field in ('exchange_host', 'exchange_port', 'market_id', 'subsession_id'):
setattr(self, field, getattr(market, field))
utility.configure_model_for_market('player', self, session_format,