Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
market_id = models.CharField()
id_in_market = models.IntegerField()
speed_unit_cost = models.IntegerField()
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()
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()
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()
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):
from otree.api import models
from otree.db.models import Model, ForeignKey
from . import market_environments
from django.utils import timezone
import logging
log = logging.getLogger(__name__)
class TimeAwareInSessionRecord(Model):
timestamp = models.DateTimeField(default=timezone.now)
trigger_event_type = models.CharField()
event_no = models.IntegerField()
subsession_id = models.IntegerField()
market_id = models.IntegerField()
class TraderRecord(TimeAwareInSessionRecord):
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()
from .dispatcher import DispatcherFactory
log = logging.getLogger(__name__)
class Constants(BaseConstants):
name_in_url = 'hft'
players_per_group = None
num_rounds = 3
class Subsession(BaseSubsession):
model_name = models.StringField(initial='subsession')
auction_format = models.StringField()
session_duration = models.IntegerField()
batch_length = models.IntegerField(initial=0)
code = models.CharField(default=random_chars_8)
def creating_session(self):
def create_trade_session(session_format):
trade_session_cls = TradeSessionFactory.get_session(session_format)
dispatcher = DispatcherFactory.get_dispatcher(session_format)
trade_session = trade_session_cls(self, session_format, dispatcher)
environment = market_environments.environments[session_format]
for event_type in environment.exogenous_events:
event_filename = self.session.config[event_type].pop(0)
trade_session.register_exogenous_event(
event_type, event_filename)
return trade_session
session_format = self.session.config['environment']
if self.round_number == 1:
self.session.config = utility.process_configs(
exchange_port = models.IntegerField()
# subsession_id = models.CharField()
market_id = models.CharField()
id_in_market = models.IntegerField()
speed_unit_cost = models.IntegerField()
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()
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()
name_in_url = 'survey'
players_per_group = None
num_rounds = 1
class Subsession(BaseSubsession):
pass
class Group(BaseGroup):
pass
class Player(BasePlayer):
age = models.IntegerField(label='What is your age?', min=13, max=125)
gender = models.StringField(
choices=[['Male', 'Male'], ['Female', 'Female']],
label='What is your gender?',
widget=widgets.RadioSelect,
)
crt_bat = models.IntegerField(
label='''
A bat and a ball cost 22 dollars in total.
The bat costs 20 dollars more than the ball.
How many dollars does the ball cost?'''
)
crt_widget = models.IntegerField(
label='''
# def status_update(self, new, field=None):
# k = Constants.player_status_key.format(self=self)
# status = cache.get(k)
# if field in Constants.player_state:
# status[field] = new
# elif field in Constants.player_accum:
# status[field] += new
# else:
# raise ValueError('invalid field.')
# cache.set(k, status, timeout=None)
class Investor(Model):
group = ForeignKey(Group)
order_count = models.IntegerField(initial=1)
def receive_from_consumer(self, msg):
side = msg['direction']
s = ('buy' if side=='B' else 'sell')
log.debug('Group%d: investor%d: %s.' % (self.group.id, self.order_count, s))
self.invest(side)
def invest(self, side):
p = (2147483647 if side == 'B' else 0)
order = Order(
pid= 0, count=self.order_count, status='stage',
side=side, price=p, time_in_force=self.group.subsession.batch_length # LOL
)
ouch = [translate.enter(order)]
self.group.send_exchange([ouch]) # send exchange expects list of lists
self.order_count += 1
pass
class Player(BasePlayer):
channel = models.CharField(max_length=255)
consented = models.BooleanField(initial=False)
exchange_host = models.CharField()
exchange_port = models.IntegerField()
# subsession_id = models.CharField()
market_id = models.CharField()
id_in_market = models.IntegerField()
speed_unit_cost = models.IntegerField()
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()
e_best_bid = models.IntegerField()
e_best_offer = models.IntegerField()
slider_a_x = models.FloatField()
slider_a_y = models.FloatField()
'field': models.IntegerField(min=0, max=20),
}),
('q_comment', {
'text': "Please give us feedback on the experiment:",
'field': models.LongStringField(max_length=500)
}),
]
}
]
},
)
# now dynamically create the Player class from the survey definitions
# we can also pass additional (non-survey) fields via `other_fields`
Player = create_player_model_for_survey('otreeutils_example2.models', SURVEY_DEFINITIONS, other_fields={
'treatment': models.IntegerField()
})
log.exception(e)
else:
for _, process_list in subprocesses.items():
if process_list:
for process in process_list:
try:
process.kill()
except Exception as e:
log.exception(e)
class Subsession(BaseSubsession):
design = models.StringField()
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()