Select Git revision
-
Gomez Goiri, Aitor authoredGomez Goiri, Aitor authored
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 }