JS API Reference

Interface: MarketModule

market/market.module.MarketModule

Implemented by

Table of contents

Properties

Methods

Properties

events

events: EventEmitter<MarketEvents, any>

Defined in

src/market/market.module.ts:84

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>

Defined in

src/market/market.module.ts:92


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

Defined in

src/market/market.module.ts:104


publishAndRefreshDemand

publishAndRefreshDemand(demandSpec): Observable<Demand>

Publishes the demand to the market and handles refreshing it when needed. Each time the demand is refreshed, a new demand is emitted by the observable. Keep in mind that since this method returns an observable, nothing will happen until you subscribe to it. Unsubscribing will remove the demand from the market.

Parameters

NameType
demandSpecDemandSpecification

Returns

Observable<Demand>

Defined in

src/market/market.module.ts:112


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>

Defined in

src/market/market.module.ts:117


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>

Defined in

src/market/market.module.ts:129


negotiateProposal

negotiateProposal(receivedProposal, counterDemandSpec): 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
receivedProposalOfferProposal
counterDemandSpecDemandSpecification

Returns

Promise<OfferCounterProposal>

The counter-proposal that the requestor made to the Provider

Defined in

src/market/market.module.ts:137


proposeAgreement

proposeAgreement(proposal): Promise<Agreement>

Internally

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

Parameters

NameType
proposalOfferProposal

Returns

Promise<Agreement>

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

Defined in

src/market/market.module.ts:153


terminateAgreement

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

Parameters

NameType
agreementAgreement
reason?string

Returns

Promise<Agreement>

The Agreement that has been terminated via Yagna

Defined in

src/market/market.module.ts:158


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

Defined in

src/market/market.module.ts:181


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>

Defined in

src/market/market.module.ts:194


estimateBudget

estimateBudget(params): 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
paramsObject
params.maxAgreementsnumber
params.orderMarketOrderSpec

Returns

number

Defined in

src/market/market.module.ts:208


fetchAgreement

fetchAgreement(agreementId): Promise<Agreement>

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

Parameters

NameType
agreementIdstring

Returns

Promise<Agreement>

Defined in

src/market/market.module.ts:213


scan

scan(scanSpecification): Observable<ScannedOffer>

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

Parameters

NameType
scanSpecificationScanSpecification

Returns

Observable<ScannedOffer>

Defined in

src/market/market.module.ts:218

Was this helpful?