Skip to content
Snippets Groups Projects
Select Git revision
  • 6623047177cc259042f96412db3d2d57991557a2
  • master default
2 results

branches-commits.md

Blame
  • lib.js 1.21 KiB
    // COPYRIGHT: FUNDACIÓN TECNALIA RESEARCH & INNOVATION, 2022.
    
    const inquirer = require("inquirer")
    
    const { promptAssetSelection } = require("@hypercog/utils")
    
    const bidAsset = async (
      apiClient,
      { assetId: paramAssetId, quantity, price }
    ) => {
      const biddableAssets = await apiClient.getBiddableAssets()
    
      const assetId = paramAssetId || (await promptAssetSelection(biddableAssets))
      const assetToBid = biddableAssets.find(({ id }) => id === assetId)
    
      let chosenQuantity = quantity
      if (!quantity) {
        const { inputQuantity } = await inquirer.prompt([
          {
            type: "number",
            name: "inputQuantity",
            message: `Choose an ammount of slag (max: ${assetToBid.quantity} ${assetToBid.units}):`
          }
        ])
        chosenQuantity = inputQuantity
      }
    
      let chosenPrice = price
      if (!price) {
        const { inputPrice } = await inquirer.prompt([
          {
            type: "number",
            name: "inputPrice",
            message: "Provide the offered price (in €):"
          }
        ])
        chosenPrice = inputPrice
      }
    
      await apiClient.bidForAsset(assetId, chosenQuantity, chosenPrice)
      console.log("Bid for slag stock", assetId)
    }
    
    // To be reused as a library in @hypercog/batch-sim
    module.exports = { bidAsset }