Skip to content

Conversation

@wstathis
Copy link
Collaborator

the meatMarket is open babyyy

@jwparsons
Copy link
Owner

You gotta clarify what the fuck this is

@jwparsons
Copy link
Owner

+420 −11 😏

@wstathis
Copy link
Collaborator Author

wstathis commented Mar 20, 2020

No changes to base functionality. Added !post, !market, and !market rules

!post <buy/sell/adjust> <price> <amt MC>
    Creates a buy/sell post on the meatMarket with the provided values, or adjusts your current post.
    Users cannot have multiple posts, and there is a xaction fee of %7 for adjustments.
!market
    displays all of the current postings
!market rules
    basically just says what I put under !post above

@wstathis
Copy link
Collaborator Author

wstathis commented Mar 20, 2020

also how does your CI work, seems like it just always fails npm

@jwparsons
Copy link
Owner

also how does your CI work

It doesn't yet. I think we need to add a test file which exercises certain functionality. You're welcome to take a crack at it.

@jwparsons
Copy link
Owner

No changes to base functionality. Added !post, !market, and !market rules

    Creates a buy/sell post on the meatMarket with the provided values, or adjusts your current post.
    Users cannot have multiple posts, and there is a xaction fee of %7 for adjustments.
!market
    displays all of the current postings
!market rules
    basically just says what I put under !post above```

Does this mean you can only buy and sell with other people?

message.author.send('Your posting:\n' + id.padStart(18,'0') + '\tS ' + String(market[1][id].quantity).padStart(10,' ') + '\t@' + String(market[1][id].price).padStart(8,' ') + '\n');
return;
}
response += ', is looking to unload some meat, get it while it\'s hot';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Love this lmao
response += ', is looking to unload some meat, get it while it's hot';

index.js Outdated
Comment on lines 1068 to 1074
// history not sure if we want this in history here, probably in processMarket()....
// if (userData.history.length > 9)
// userData.history.pop();
// userData.history.unshift('b' + ',' + amount.toFixed(2) + ',' + price.toFixed(2));

// statistics
//volume.bought += amount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if want to remove?

index.js Outdated
Comment on lines 1019 to 1025
// history not sure if we want this in history here, probably in processMarket()....
// if (userData.history.length > 9)
// userData.history.pop();
// userData.history.unshift('b' + ',' + amount.toFixed(2) + ',' + price.toFixed(2));

// statistics
//volume.bought += amount;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check if want to remove?

@Dkohanski Dkohanski self-requested a review March 20, 2020 23:03
@wstathis wstathis requested a review from jwparsons March 20, 2020 23:05
@wstathis wstathis added the WiP Work in Progress label Mar 21, 2020
@wstathis
Copy link
Collaborator Author

Need to change DMs to users to use name instead of ID or just remove altogether

@wstathis
Copy link
Collaborator Author

wstathis commented Mar 21, 2020

fix name padding - moot if we make anon

SELLERS-----------+------------QUANTITY+---------PRICE+
Sabrina the Teenage Lich|                 1.8|           1.1|

@wstathis
Copy link
Collaborator Author

wstathis commented Mar 21, 2020

Price matching function currently only adds to volume.bought, needs to write to volume.sold too
just adding volume.traded

@wstathis
Copy link
Collaborator Author

wstathis commented Mar 21, 2020

Need to handle when two posts match 2:1 buyer:seller or vice versa, currently causes crash

TypeError: negPrice.toFixed is not a function
    at C:\Users\NigelThornburry\MeatCoin\index.js:1240:129
    at Array.forEach (<anonymous>)
    at C:\Users\NigelThornburry\MeatCoin\index.js:1190:38
    at Array.forEach (<anonymous>)
    at processMarket (C:\Users\NigelThornburry\MeatCoin\index.js:1187:29)
    at post (C:\Users\NigelThornburry\MeatCoin\index.js:1179:5)
    at Client.<anonymous> (C:\Users\NigelThornburry\MeatCoin\index.js:122:13)
    at Client.emit (events.js:311:20)
    at MessageCreateAction.handle (C:\Users\NigelThornburry\MeatCoin\node_modules\discord.js\src\client\actions\MessageCreate.js:31:14)
    at Object.module.exports [as MESSAGE_CREATE] (C:\Users\NigelThornburry\MeatCoin\node_modules\discord.js\src\client\websocket\handlers\MESSAGE_CREATE.js:4:32)

Comment on lines +61 to +62
data/token.txt
#keep price local
Copy link
Owner

Choose a reason for hiding this comment

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

Add a space.

}
market[0]=buyerData;
market[1]=sellerData;

Copy link
Owner

Choose a reason for hiding this comment

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

Remove newline.

Comment on lines +196 to +211
function printMarket(message) {
var response = '```glsl\nGET YER FLESH HERE!\n';
if (Object.keys(market[1]).length > 0) {
response += 'SELLERS'.padEnd(18,'-') + '+' + 'QUANTITY'.padStart(20,'-') + '+' + 'PRICE'.padStart(14,'-') + '+\n';
Object.keys(market[1]).forEach(function(key) {
response += market[1][key].username.padEnd(18,' ') + '|' + String(market[1][key].quantity).padStart(20,' ') + '|' + String(market[1][key].price).padStart(14,' ') + '|\n';
});
}
if (Object.keys(market[0]).length > 0) {
response += 'BUYERS'.padEnd(18,'-') + '+' + 'QUANTITY'.padStart(20,'-') + '+' + 'PRICE'.padStart(14,'-') + '+\n';
Object.keys(market[0]).forEach(function(key) {
response += market[0][key].username.padEnd(18,' ') + '|' + String(market[0][key].quantity).padStart(20,' ') + '|' + String(market[0][key].price).padStart(14,' ') + '|\n';
});
}
response += '```';
message.channel.send(response);
Copy link
Owner

Choose a reason for hiding this comment

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

NO TABS????????????

Comment on lines +958 to +959
function post(message, command, price, coinage){

Copy link
Owner

Choose a reason for hiding this comment

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

Need a space before { and remove the newline.

return;
}
//check that the user is not already buying
if (id in market[0]){
Copy link
Owner

Choose a reason for hiding this comment

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

Space before {

Comment on lines +1076 to +1078
else if (command == 'adjust'){
//adjusting a buy
if (id in market[0]){
Copy link
Owner

Choose a reason for hiding this comment

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

Space before {

//adjusting a buy
if (id in market[0]){
//remvoing post
if (amount <= 0.0 || floatPrice <= 0.0){
Copy link
Owner

Choose a reason for hiding this comment

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

Make sure there is a space before every {. I'll stop making this comment.


}
else{
response += ', ' + command + ' is not a valid command. ya dingus!';
Copy link
Owner

Choose a reason for hiding this comment

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

🙇

Comment on lines 1183 to 1254
var buyers = market[0];
var sellers = market[1];
//iterate through buyers
if (Object.keys(buyers).length > 0) {
Object.keys(buyers).forEach(function(Bkey) {
//iterate through sellers
if (Object.keys(sellers).length > 0) {
Object.keys(sellers).forEach(function(Skey) {
// check if we can make a deal
if(buyers[Bkey].price >= sellers[Skey].price){ //price match
var negPrice = buyers[Bkey].price; //probably won't happen too much, but good to be safe, buyers lose
//Buying > Selling
if(buyers[Bkey].quantity > sellers[Skey].quantity){
var buyerData = ledger[Bkey];
var sellerData = ledger[Skey];
//credit both parties as they have already paid
buyerData.meatCoin += parseFloat(sellers[Skey].quantity);
volume.bought += parseFloat(sellers[Skey].quantity);
sellerData.gold += sellers[Skey].quantity * negPrice;
if (buyerData.history.length > 9)
buyerData.history.pop();
buyerData.history.unshift('b' + ',' + parseFloat(sellers[Skey].quantity).toFixed(2) + ',' + negPrice.toFixed(2));
if (sellerData.history.length > 9)
sellerData.history.pop();
sellerData.history.unshift('s' + ',' + parseFloat(sellers[Skey].quantity).toFixed(2) + ',' + negPrice.toFixed(2));
//decrease buyer quantity by amount sold, remove seller posting
buyers[Bkey].quantity -= sellers[Skey].quantity;
delete sellers[Skey];
}
//Selling > Buying
else if (sellers[Skey].quantity > buyers[Bkey].quantity){
var buyerData = ledger[Bkey];
var sellerData = ledger[Skey];
//credit both parties as they have already paid
buyerData.meatCoin += parseFloat(buyers[Bkey].quantity);
volume.bought += parseFloat(buyers[Bkey].quantity);
sellerData.gold += buyers[Bkey].quantity * negPrice;
if (buyerData.history.length > 9)
buyerData.history.pop();
buyerData.history.unshift('b' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2));
if (sellerData.history.length > 9)
sellerData.history.pop();
sellerData.history.unshift('s' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2));
//decrease seller quantity by amount sold, remove buyer posting
sellers[Skey].quantity -= buyers[Bkey].quantity;
delete buyers[Bkey];
}
//equal
else{
var buyerData = ledger[Bkey];
var sellerData = ledger[Skey];
//credit both parties as they have already paid
buyerData.meatCoin += parseFloat(buyers[Bkey].quantity);
volume.bought += parseFloat(buyers[Bkey].quantity);
sellerData.gold += buyers[Bkey].quantity * negPrice;
if (buyerData.history.length > 9)
buyerData.history.pop();
buyerData.history.unshift('b' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2));
if (sellerData.history.length > 9)
sellerData.history.pop();
sellerData.history.unshift('s' + ',' + parseFloat(buyers[Bkey].quantity).toFixed(2) + ',' + negPrice.toFixed(2));
//decrease seller quantity by amount sold, remove buyer posting
delete sellers[Skey];
delete buyers[Bkey];
}
}
})
}
});
}
}

Copy link
Owner

Choose a reason for hiding this comment

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

Try to space out the code. Put a newline before all the comments (thank you for having comments) and some of the if statements.

var sellers = market[1];
//iterate through buyers
if (Object.keys(buyers).length > 0) {
Object.keys(buyers).forEach(function(Bkey) {
Copy link
Owner

Choose a reason for hiding this comment

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

Are we doing list iterations here? Can we perhaps use a hash map instead? To find matching buy/sells.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

WiP Work in Progress

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants