JS API Reference

Class: MarketModuleImpl

market/market.module.MarketModuleImpl

Implements

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new MarketModuleImpl(deps, options?): MarketModuleImpl

Parameters

NameType
depsObject
deps.loggerLogger
deps.yagnaYagnaApi
deps.paymentApiIPaymentApi
deps.activityApiIActivityApi
deps.marketApiIMarketApi
deps.networkApiINetworkApi
deps.networkModuleNetworkModule
deps.fileServerIFileServer
deps.storageProviderStorageProvider
options?Partial<MarketModuleOptions>

Returns

MarketModuleImpl

Defined in

src/market/market.module.ts:243

Properties

events

events: EventEmitter<MarketEvents, any>

Implementation of

MarketModule.events

Defined in

src/market/market.module.ts:236

Methods

buildDemandDetails

buildDemandDetails(demandOptions, orderOptions, allocation): Promise<DemandSpecification>

Build a DemandSpecification based on the given options and allocation. You can obtain an allocation using the payment module. The method returns a DemandSpecification that can be used to publish the demand to the market, for example using the publishDemand method.

Parameters

NameType
demandOptionsOrderDemandOptions
orderOptionsOrderMarketOptions
allocationAllocation

Returns

Promise<DemandSpecification>

Implementation of

MarketModule.buildDemandDetails

Defined in

src/market/market.module.ts:269


buildScanSpecification

buildScanSpecification(options): ScanSpecification

Build a ScanSpecification that can be used to scan the market for offers. The difference between this method and buildDemandDetails is that this method does not require an allocation, doesn't inherit payment properties from GolemNetwork settings and doesn't provide any defaults. If you wish to set the payment platform, you need to specify it in the ScanOptions.

Parameters

NameType
optionsScanOptions

Returns

ScanSpecification

Implementation of

MarketModule.buildScanSpecification

Defined in

src/market/market.module.ts:302


publishAndRefreshDemand

publishAndRefreshDemand(demandSpecification): Observable<Demand>

Publishes the specified demand and re-publishes it based on demandSpecification.expirationSec interval

Parameters

NameType
demandSpecificationDemandSpecification

Returns

Observable<Demand>

Implementation of

MarketModule.publishAndRefreshDemand

Defined in

src/market/market.module.ts:339


collectMarketProposalEvents

collectMarketProposalEvents(demand): Observable<MarketProposalEvent>

Return an observable that will emit values representing various events related to this demand

Parameters

NameType
demandDemand

Returns

Observable<MarketProposalEvent>

Implementation of

MarketModule.collectMarketProposalEvents

Defined in

src/market/market.module.ts:409


collectAllOfferProposals

collectAllOfferProposals(demand): Observable<OfferProposal>

Subscribes to the proposals for the given demand. If an error occurs, the observable will emit an error and complete. Keep in mind that since this method returns an observable, nothing will happen until you subscribe to it.

This method will just yield all the proposals that will be found for that demand without any additional logic.

The collectDraftOfferProposals is a more specialized variant of offer collection, which includes negotiations and demand re-subscription logic

Parameters

NameType
demandDemand

Returns

Observable<OfferProposal>

Implementation of

MarketModule.collectAllOfferProposals

Defined in

src/market/market.module.ts:416


negotiateProposal

negotiateProposal(offerProposal, counterDemand): Promise<OfferCounterProposal>

Sends a counter-offer to the provider. Note that to get the provider's response to your counter you should listen to events returned by collectDemandOfferEvents.

Parameters

NameType
offerProposalOfferProposal
counterDemandDemandSpecification

Returns

Promise<OfferCounterProposal>

The counter-proposal that the requestor made to the Provider

Implementation of

MarketModule.negotiateProposal

Defined in

src/market/market.module.ts:423


proposeAgreement

proposeAgreement(proposal, options?): Promise<Agreement>

Internally

  • ya-ts-client createAgreement
  • ya-ts-client approveAgreement
  • ya-ts-client "wait for approval"

Parameters

NameType
proposalOfferProposal
options?AgreementOptions

Returns

Promise<Agreement>

Returns when the provider accepts the agreement, rejects otherwise. The resulting agreement is ready to create activities from.

Implementation of

MarketModule.proposeAgreement

Defined in

src/market/market.module.ts:444


terminateAgreement

terminateAgreement(agreement, reason?): Promise<Agreement>

Parameters

NameType
agreementAgreement
reason?string

Returns

Promise<Agreement>

The Agreement that has been terminated via Yagna

Implementation of

MarketModule.terminateAgreement

Defined in

src/market/market.module.ts:455


collectDraftOfferProposals

collectDraftOfferProposals(options): Observable<OfferProposal>

Creates a demand for the given package and allocation and starts collecting, filtering and negotiating proposals. The method returns an observable that emits a batch of draft proposals every time the buffer is full. The method will automatically negotiate the proposals until they are moved to the Draft state. Keep in mind that since this method returns an observable, nothing will happen until you subscribe to it. Unsubscribing from the observable will stop the process and remove the demand from the market.

Parameters

NameType
optionsObject
options.demandSpecificationDemandSpecification
options.pricingPricingOptions
options.filter?OfferProposalFilter
options.minProposalsBatchSize?number
options.proposalsBatchReleaseTimeoutMs?number

Returns

Observable<OfferProposal>

Implementation of

MarketModule.collectDraftOfferProposals

Defined in

src/market/market.module.ts:467


signAgreementFromPool

signAgreementFromPool(draftProposalPool, agreementOptions?, signalOrTimeout?): Promise<Agreement>

Acquire a proposal from the pool and sign an agreement with the provider. If signing the agreement fails, destroy the proposal and try again with another one. The method returns an agreement that's ready to be used. Optionally, you can provide a timeout in milliseconds or an AbortSignal that can be used to cancel the operation early. If the operation is cancelled, the method will throw an error. Note that this method will respect the acquire timeout set in the pool and will throw an error if no proposal is available within the specified time.

Parameters

NameTypeDescription
draftProposalPoolDraftOfferProposalPoolThe pool of draft proposals to acquire from
agreementOptions?AgreementOptionsoptions used to sign the agreement such as expiration or waitingForApprovalTimeout
signalOrTimeout?number | AbortSignalThe timeout in milliseconds or an AbortSignal that will be used to cancel the operation

Returns

Promise<Agreement>

Example

const agreement = await marketModule.signAgreementFromPool(draftProposalPool, 10_000); // throws TimeoutError if the operation takes longer than 10 seconds

Example

const signal = AbortSignal.timeout(10_000);
const agreement = await marketModule.signAgreementFromPool(draftProposalPool, signal); // throws TimeoutError if the operation takes longer than 10 seconds

Implementation of

MarketModule.signAgreementFromPool

Defined in

src/market/market.module.ts:528


estimateBudget

estimateBudget(«destructured»): number

Estimate the budget for the given order and maximum numbers of agreemnets. Keep in mind that this is just an estimate and the actual cost may vary. The method returns the estimated budget in GLM.

Parameters

NameType
«destructured»Object
› orderMarketOrderSpec
› maxAgreementsnumber

Returns

number

Implementation of

MarketModule.estimateBudget

Defined in

src/market/market.module.ts:628


fetchAgreement

fetchAgreement(agreementId): Promise<Agreement>

Fetch the most up-to-date agreement details from the yagna

Parameters

NameType
agreementIdstring

Returns

Promise<Agreement>

Implementation of

MarketModule.fetchAgreement

Defined in

src/market/market.module.ts:653


scan

scan(scanSpecification): Observable<ScannedOffer>

Scan the market for offers that match the given demand specification.

Parameters

NameType
scanSpecificationScanSpecification

Returns

Observable<ScannedOffer>

Implementation of

MarketModule.scan

Defined in

src/market/market.module.ts:733