Skip to content
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

✨ an option to only update buying price if an item is in stock #337

Merged
merged 14 commits into from
Mar 2, 2021

Conversation

idinium96
Copy link
Member

@idinium96 idinium96 commented Feb 13, 2021

  • closes Better Pricing #284

  • not implement: Safe guard should be added here: if buying price = selling price of other bot users (simple bp.tf check) then buying price - 0.11 ref = new buying price. But the selling price stays the same with the market (other bots).

  • new options.json properties:

    • pricelist.partialPriceUpdate.enable (default is false)
    • pricelist.partialPriceUpdate.thresholdInSeconds (default is 604800 seconds or 7 days.)
    • sendAlert.partialPrice.onUpdate (default is true)
    • sendAlert.partialPrice.onSuccessUpdatePartialPriced (default is true)
    • sendAlert.partialPrice.onFailedUpdatePartialPriced (default is true)

How does this work?

  • Previously, on start, the bot will get full pricelist from prices.tf/custom-autopricer and then loop through the bot pricelist and compare the time. If time in the bot pricelist is less than the time in prices.tf/custom-autopricer pricelist entry, the bot will update the buying and selling prices along with the time.

Code

if (match !== null && match.autoprice) {
const oldPrice = {
buy: new Currencies(match.buy),
sell: new Currencies(match.sell)
};
let pricesChanged = false;
const optPartialUpdate = opt.pricelist.partialPriceUpdate;
const isInStock = this.bot.inventoryManager.getInventory.getAmount(match.sku, true) > 0;
const isNotExceedThreshold = data.time - match.time < optPartialUpdate.thresholdInSeconds;
const isNotExcluded = !['5021;6'].concat(optPartialUpdate.excludeSKU).includes(match.sku);
if (
optPartialUpdate.enable &&
isInStock &&
isNotExceedThreshold &&
this.globalKeyPrices !== undefined &&
isNotExcluded
) {
// if optPartialUpdate.enable is true and the item is currently in stock
// and difference between latest time and time recorded in pricelist is less than threshold
const keyPrice = this.getKeyPrice.metal;
const newBuyValue = newPrices.buy.toValue(keyPrice);
const newSellValue = newPrices.sell.toValue(keyPrice);
// TODO: Use last bought prices instead of current buying prices
const currBuyingValue = match.buy.toValue(keyPrice);
const currSellingValue = match.sell.toValue(keyPrice);
const isNegativeDiff = newSellValue - currBuyingValue < 0;
if (isNegativeDiff || match.group === 'isPartialPriced') {
// Only trigger this if difference of new selling price and current buying price is negative
// Or item group is "isPartialPriced".
let isUpdate = false;
if (newBuyValue < currSellingValue) {
// if new buying price is less than current selling price
// update only the buying price.
match.buy = newPrices.buy;
if (newSellValue > currSellingValue) {
// If new selling price is more than old, then update selling price too
match.sell = newPrices.sell;
}
isUpdate = true;
// no need to update time here
} else if (newSellValue > currSellingValue) {
// If new selling price is more than old, then update selling price too
match.sell = newPrices.sell;
isUpdate = true;
}
if (isUpdate) {
match.group = 'isPartialPriced';
pricesChanged = true;
const dw = opt.discordWebhook.sendAlert;
const isDwEnabled = dw.enable && dw.url !== '';
const msg =
`${
isDwEnabled ? `[${match.name}](https://www.prices.tf/items/${match.sku})` : match.name
} (${match.sku}):\n▸ ` +
[
`old: ${oldPrice.buy.toString()}/${oldPrice.sell.toString()}`,
`current: ${match.buy.toString()}/${match.sell.toString()}`,
`pricestf: ${newPrices.buy.toString()}/${newPrices.sell.toString()}`
].join('\n▸ ');
if (opt.sendAlert.partialPrice.onUpdate) {
if (isDwEnabled) {
sendAlert('isPartialPriced', this.bot, msg);
} else {
this.bot.messageAdmins('Partial price update\n\n' + msg, []);
}
}
}
} else {
// else, just update as usual now (except if group is "isPartialPriced").
if (match.group !== 'isPartialPriced') {
match.buy = newPrices.buy;
match.sell = newPrices.sell;
match.time = data.time;
pricesChanged = true;
}
}
} else {
// else if optPartialUpdate.enable is false and/or the item is currently not in stock
// and/or more than threshold, update everything
match.buy = newPrices.buy;
match.sell = newPrices.sell;
match.time = data.time;
pricesChanged = true;
if (pricesChanged) {
this.priceChanged(match.sku, match);
}

Explanation

  • (1) if pricelist.partialPriceUpdate.enable is set to true AND that particular item is currently in stock (> 0) AND difference in time is less than the threshold AND not include excluded items (default only Mann Co. Supply Crate Key),

    • (1.1) if newSelling - currentBuying < 0 OR item group is "isPartialPriced";
      • (1.1.1) if it's determined that the new buying price (prices.tf/custom-autopricer) is less than the current selling price (in pricelist entry), then update ONLY the buying price of that item.
        • (1.1.1.1) then if it's also determined that the new selling price (prices.tf/custom-autopricer) is more than the current selling price (in pricelist entry), then update the selling price of that item too.
      • (1.1.2) else if 1.1.1 false, check if, the new selling price (prices.tf/custom-autopricer) is more than the current selling price (in pricelist entry), then update the selling price of that item.
    • (1.2) else if 1.1 false, update as usual (meaning the new selling price is higher and/or we did not partially price the item before).
  • (2) Else, update as usual (disabled and/or not in stock and/or difference in time is more than threshold and/or any of the excluded item (sku).

  • The above conditions also applied when the bot starts/restart (updateOldPrices method).

@idinium96 idinium96 linked an issue Feb 13, 2021 that may be closed by this pull request
@idinium96 idinium96 marked this pull request as draft February 14, 2021 23:19
@idinium96
Copy link
Member Author

merging...

@idinium96 idinium96 merged commit fafd517 into development Mar 2, 2021
@idinium96 idinium96 mentioned this pull request Mar 2, 2021
@idinium96 idinium96 deleted the only-update-buying-price-if-in-stock branch March 2, 2021 11:52
idinium96 added a commit that referenced this pull request Mar 3, 2021
#373

## Added
- Options.json related:
    - ✨option to disable sending the pre-accepted message - @idinium96
        - new option added: `offerReceived.sendPreAcceptMessage.enable` (default is `true`)
    - ✨option to only show price update that is in stock - @idinium96
       - new option added: `discordWebhook.priceUpdate.showOnlyInStock` (default is `false`)
    - ✨an option to partially update item prices if in stock and the difference between the new selling price and current buying price is negative (#284 - read: #337) - @idinium96
    - ✨ option to select highValue spells - @idinium96
        - new option added: `highValue.spells` (default is `[]` - all spells)
- Others:
     - ✨Docker build for node images (refer: [Wiki](https://github.com/TF2Autobot/tf2autobot/wiki/Running-the-bot-using-docker)) - @rennokki
     - ✨support **buy order** for skins/war paints (Festivized skins/war paints not supported - see [`#337`](#377)) - @idinium96
    - ✨option to disable socket entirely (read: #383) - @idinium96

## Changed/updated
- 🔄 replaced bracket with a dash to not combine with generated URL on retrying to accept offer message sent to admins via Steam Chat - @idinium96
- 🤝 custom-pricer friendly (#363) - @idinium96
- 📝 log bot uptime on auto-restart - @idinium96
- 🔑 ensure selling price for Mann Co. Supply Crate Key never be zero - @idinium96
- 🔄 updated dependencies - @idinium96
- 🔄 improve `!deposit` command (#325, #326) - @idinium96
- 🔄 more flexibility when adding items with parameters - @idinium96
- 🔄 refactor `!find` command (view what changed: #387) - @idinium96
- ✅ do not hold items in an offer for review - @idinium96
- ⏮ revert only pick 1 craft weapon when constructing an offer - @idinium96

## Fixed
- 🔨 wrong position for pure stock and total items in the Offer review send as Discord Webhook.
- `!autoadd` command:
    - 🐛 fix the glitch where the pure got deleted from items dictionary - @idinium96
    - ⌚ add a delay before sending `autoadd` summary - @idinium96
- 🔨 fix generic unusual buy order (ensure the generic match is used against 'their' inventory) (#340) - @joekiller
- 🔨 fix sending duplicated trade summary - @idinium96
- 🔨 fix failed to disable Autokeys error - @idinium96
- 🐛 fix bot crashed (rare) on startup - @idinium96 
    - ⛔ do not execute sending price update to Discord Webhook if globalKeyPrices still undefined
@idinium96 idinium96 mentioned this pull request Mar 6, 2021
idinium96 added a commit that referenced this pull request Mar 6, 2021
#411

## Added
- Mainly if you're using generic Unusual buy order feature:
    - ✨option to not automatically add bought Unusual item to the pricelist (usual because buying with Generic Unusual buy order - #412, [Wiki](https://github.com/TF2Autobot/tf2autobot/wiki/Configure-your-options.json-file#--automatic-add-invalid-unusual--)) - @joekiller
        - new options added:
            - `pricelist.autoAddInvalidUnusual.enable` (default is `false`)
            - `sendAlert.receivedUnusualNotInPricelist` (default if `true`)
- ✨HTTP API health check (and others in the future - #413, [Wiki](https://github.com/TF2Autobot/tf2autobot/wiki/Configuring-the-bot#api)) - @rennokki
    - new env variables:
       - `ENABLE_HTTP_API` (default is `false`)
       - `HTTP_API_PORT` (default is `3001`)
- ✨option to show proper item name in trade/offer summary (with "The", no short - #415, [Wiki](https://github.com/TF2Autobot/tf2autobot/wiki/Configure-your-options.json-file#-trade-summary-settings-)) - @idinium96
    - new options added:
        - `tradeSummary.showProperName` (default is `false`)

## Updates
- Partial price update feature (updated #337):
    - ⛔ do not partial price Mann Co. Supply Crate Key (#407) - @idinium96
    - ✅ add an option to exclude items for partial price update (#408, [Wiki](https://github.com/TF2Autobot/tf2autobot/wiki/Configure-your-options.json-file#--partial-price-update--)) - @idinium96
        - new options.json property: `pricelist.partialPriceUpdate.excludeSKU` (default is `[]`)
    - 💅 include name in partial price update summary (#409) - @idinium96
    - ⛔ do not perform usual update if grouped (#410) - @idinium96
- 🔨 refactor Bot.ts (#399) - @arik123
- 🔎🔑 keyPrices verification (2) and 🔨 small refactor on Pricelist.ts (#416) - @idinium96
- 🔕 ignore some error on fail action or to accept mobile confirmation (#419) - @idinium96 
- 🔨 refactor: use Map and Set (#420) - @idinium96
- 🎨 show amount offering/offered/taking/taken in overstocked/understocked review/trade summary (#421) - @idinium96
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.

Better Pricing
1 participant