Class: Trader

Trader(optionsopt)

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

new Trader(optionsopt)

Parameters:
Name Type Attributes Description
options Object <optional>
passed to Agent constructor(); Trader specific properties detailed below
Properties
Name Type Attributes Default Description
markets Array.<Object> <optional>
[] list of market objects where this agent acts on wake
minPrice number <optional>
0 minimum price when submitting limit orders to buy
maxPrice number <optional>
1000 maximum price when submitting sell limit orders to sell
ignoreBudgetConstraint boolean <optional>
false ignore budget constraint, substituting maxPrice for unit value when bidding, and minPrice for unit cost when selling
Source:
Listens to Events:
  • event:{wake} to trigger sendBidsAndAsks()

Classes

Trader

Methods

(abstract) ask(market, myPrice)

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.
Parameters:
Name Type Description
market Object
myPrice number
Source:
Throws:
when calling placeholder
Type
Error

(abstract) askPrice(marginalCost, market) → {number|undefined}

calculate price this agent is willing to accept. Placeholder throws error. Must be overridden and implemented in other code.
Parameters:
Name Type Description
marginalCost number The marginal cost of producing the next unit.
market Object For requesting current market conditions, previous trade price, etc.
Source:
Throws:
when calling placeholder
Type
Error
Returns:
agent's sell price or undefined if not willing to sell
Type
number | undefined

(abstract) bid(market, myPrice)

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.
Parameters:
Name Type Description
market Object
myPrice number
Source:
Throws:
when calling placeholder
Type
Error

(abstract) bidPrice(marginalValue, market) → {number|undefined}

calculate price this agent is willing to pay. Placeholder throws error. Must be overridden and implemented in other code.
Parameters:
Name Type Description
marginalValue number The marginal value of redeeming the next unit.
market Object For requesting current market conditions, previous trade price, etc.
Source:
Throws:
when calling placeholder
Type
Error
Returns:
agent's buy price or undefined if not willing to buy
Type
number | undefined

sendBidsAndAsks()

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.
Source: