Home Reference Source Test Repository
import {Trader} from 'market-agents/src/index.js'
public class | source

Trader

Extends:

events~EventEmitterAgent → Trader

Indirect Subclass:

UnitAgent

agent that places trades in one or more markets based on marginal costs or values

This is an abstract class, meant to be subclassed for particular strategies.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Method Summary

Public Methods
public abstract

ask(market: Object, myPrice: number)

send a limit order to sell one unit to the indicated market at myPrice.

public abstract

askPrice(marginalCost: number, market: Object): number | undefined

calculate price this agent is willing to accept.

public abstract

bid(market: Object, myPrice: number)

send a limit order to buy one unit to the indicated market at myPrice.

public abstract

bidPrice(marginalValue: number, market: Object): number | undefined

calculate price this agent is willing to pay.

public

For each market in agent's configured markets, calculates agent's price strategy for buy or sell prices and then sends limit orders for 1 unit at those prices.

Inherited Summary

From class Agent
public

period: *

public

time, in JS ms since epoch, of agent wake

public

ends current period, causing agent to undertake end-of-period tasks such as production and redemption of units

public

init(newSettings: Object)

initialize an agent to new settings

public

initPeriod(period: number | Object)

re-initialize agent to the beginning of a new simulation period

public

percent of period used

public

guess at number of random Poisson wakes remaining in period

public

produces units in negative inventory with configured costs, usually called automatically at end-of-period.

public

redeem()

redeems units in positive inventory with configured values, usually called automatically at end-of-period.

public

transfer(myTransfers: Object, memo: Object)

increases or decreases agent's inventories of one or more goods and/or money

public

unitCostFunction(good: String, hypotheticalInventory: Object): number

agent's marginal cost of producing next unit

public

unitValueFunction(good: String, hypotheticalInventory: Object): number

agent's marginal value for redeeming next unit

public

wake(info: Object)

wakes agent so it can act, emitting wake, and sets next wakeTime from this.nextWake() unless period.endTime exceeded

Public Constructors

public constructor(options: Object) source

creates an Agent with clone of specified options and initializes with .init(). Option properties are stored directly on the created agent's this.

Override:

Agent#constructor

Params:

NameTypeAttributeDescription
options Object
  • optional

passed to Agent constructor(); Trader specific properties detailed below

options.markets Array<Object>
  • optional
  • default: []

list of market objects where this agent acts on wake

options.minPrice number
  • optional
  • default: 0

minimum price when submitting limit orders to buy

options.maxPrice number
  • optional
  • default: 1000

maximum price when submitting sell limit orders to sell

options.ignoreBudgetConstraint boolean
  • optional
  • default: false

ignore budget constraint, substituting maxPrice for unit value when bidding, and minPrice for unit cost when selling

Listen:

wake

to trigger sendBidsAndAsks()

Public Methods

public abstract ask(market: Object, myPrice: number) source

send a limit order to sell one unit to the indicated market at myPrice. Placeholder throws error. Must be overridden and implemented in other code.

Params:

NameTypeAttributeDescription
market Object
myPrice number

Throw:

Error

when calling placeholder

public abstract askPrice(marginalCost: number, market: Object): number | undefined source

calculate price this agent is willing to accept. Placeholder throws error. Must be overridden and implemented in other code.

Params:

NameTypeAttributeDescription
marginalCost number

The marginal cost of producing the next unit.

market Object

For requesting current market conditions, previous trade price, etc.

Return:

number | undefined

agent's sell price or undefined if not willing to sell

Throw:

Error

when calling placeholder

public abstract bid(market: Object, myPrice: number) source

send a limit order to buy one unit to the indicated market at myPrice. Placeholder throws error. Must be overridden and implemented in other code.

Params:

NameTypeAttributeDescription
market Object
myPrice number

Throw:

Error

when calling placeholder

public abstract bidPrice(marginalValue: number, market: Object): number | undefined source

calculate price this agent is willing to pay. Placeholder throws error. Must be overridden and implemented in other code.

Params:

NameTypeAttributeDescription
marginalValue number

The marginal value of redeeming the next unit.

market Object

For requesting current market conditions, previous trade price, etc.

Return:

number | undefined

agent's buy price or undefined if not willing to buy

Throw:

Error

when calling placeholder

public sendBidsAndAsks() source

For each market in agent's configured markets, calculates agent's price strategy for buy or sell prices and then sends limit orders for 1 unit at those prices. Normally you do not need to explicltly call this function: the wake listener set in the constructor of Trader and subclasses calls sendBidsAndAsks() automatcally on each wake event.