Skip to content

Conversation

icendoan
Copy link

The command should now be /bid_market 123.4 1000 AAPL etc

def bid(self, price, user_id):
self.bids.append(Order(price, 'bid', user_id))
def bid(self, price, user_id, qty):
self.bids.append(Order(price, 'bid', user_id, qty))
heapq.heapify(self.bids)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably also consider heapq.heappush for this, as it can't be slower than calling heapify every time

@icendoan icendoan force-pushed the master branch 2 times, most recently from f395109 to a47230e Compare April 23, 2025 13:38
@icendoan icendoan force-pushed the master branch 4 times, most recently from 4afd282 to 308f08c Compare April 23, 2025 14:02

await ctx.reply("Bid placed", ephemeral=True)

if did_trade is not None:
await ctx.reply(did_trade, ephemeral=False)

@commands.hybrid_command(help=LONG_HELP_TEXT, brief=SHORT_HELP_TEXT)
async def ask_market(self, ctx: Context, price: float, *, market: clean_content):
async def ask_market(self, ctx: Context, price: float, qty: int, *, market: clean_content):
"""You would place a bid by using this command
Copy link
Contributor

@jfitz02 jfitz02 Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""You would place a bid by using this command
"""You would place an ask by using this command

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

def bid(self, price, user_id):
self.bids.append(Order(price, 'bid', user_id))
heapq.heapify(self.bids)
def bid(self, price, user_id, qty, time=time.time()):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pretty sure python will take time.time when it "creates" the function. So every bid will have the same time, and every ask will have the same time

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python--

assert len(m.asks) == 0
assert len(m.bids) == 1
assert m.bids[0].qty == 99
assert m.bids[0].order_time == 2
Copy link
Contributor

@jfitz02 jfitz02 Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
assert m.bids[0].order_time == 2
assert m.bids[0].order_time == 2
def test_time():
m = Market("test")
assert m.ask(102, 1, 1) is None
assert m.ask(102, 2, 1) is None
ask_times = [ask.order_time for ask in m.asks]
# Testing that all ask times are distinct
assert all([ask_times.count(ask.order_time) == 1 for ask in m.asks])
assert m.bid(102, 3, 1) == """<@3> bought 1 from <@1> at 102"""

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote this in GitHub and have not tested it, but this is just the gist of testing times are ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants