-
Notifications
You must be signed in to change notification settings - Fork 22
Add qty fields to market orders #283
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
cogs/commands/market.py
Outdated
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) |
There was a problem hiding this comment.
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
f395109
to
a47230e
Compare
4afd282
to
308f08c
Compare
cogs/commands/market.py
Outdated
|
||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"""You would place a bid by using this command | |
"""You would place an ask by using this command |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
cogs/commands/market.py
Outdated
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()): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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""" |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
The command should now be
/bid_market 123.4 1000 AAPL
etc