import { NS } from '@ns' // eslint-disable-next-line require-await export async function main(ns : NS) : Promise { const api = ns.stock; if(!api.hasWSEAccount() || !api.has4SDataTIXAPI()){ ns.tprint("api need") ns.tprint("purchase stock API!"); return; } ns.print("start stock-auto-sell-daemon"); ns.disableLog("ALL") ns.tail(); for(;;){ for(const stock of api.getSymbols()){ const p = api.getForecast(stock); if(p < 0.5){ const share = api.getPosition(stock)[0] if(share > 0){ ns.print(`forecast: ${p}, sell ${stock} amount of ${share}`); const v = api.sellStock(stock, share); if(v == 0){ ns.print("failed to sell stock!"); ns.toast("Failed To Sell Stock","error",6000); } else{ ns.print(`avg sold price ${v}`); ns.toast(`Sell ${stock} amount of ${ns.nFormat(share,"0.000a")}`,"info",6000); } } } } await ns.sleep(6000); } }