-
Notifications
You must be signed in to change notification settings - Fork 2
/
tests.py
55 lines (47 loc) · 1.48 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from . import pages
from otree.api import Bot, Submission
class PlayerBot(Bot):
def print_assets(self):
for player in self.group.get_players():
print(player.participant.code + ':')
print(player.assets, player.cash)
def play_round(self):
if self.round_number > self.subsession.config.num_rounds:
return
if self.player.id_in_group == 1:
self.p1_round()
else:
self.p2_round()
exchange = self.group.exchanges.get(asset_name='A')
print('orders:')
print(exchange)
print('trades:')
print('\n'.join(str(e) for e in exchange._get_trades_qset()))
yield Submission(pages.TextInterface, check_html=False)
yield Submission(pages.Results, check_html=False)
def p1_round(self):
msg = {
'price': 10,
'volume': 1,
'is_bid': True,
'pcode': self.participant.code,
'asset_name': 'A',
}
self.group._handle_enter(msg)
msg = {
'price': 9,
'volume': 1,
'is_bid': True,
'pcode': self.participant.code,
'asset_name': 'A',
}
self.group._handle_enter(msg)
def p2_round(self):
msg = {
'price': 10,
'volume': 2,
'is_bid': False,
'pcode': self.participant.code,
'asset_name': 'A',
}
self.group._handle_enter(msg)