Skip to content

Commit

Permalink
Document createOrder's parameter properly
Browse files Browse the repository at this point in the history
  • Loading branch information
tiennou committed Feb 2, 2025
1 parent 1f73abf commit 27a9374
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 14 deletions.
47 changes: 40 additions & 7 deletions dist/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3072,14 +3072,16 @@ interface Market {
* it will be automatically activated and deactivated depending on the resource/credits availability.
*
* An order expires in 30 days after its creation, and the remaining market fee is returned.
*
* @param params A object describing the order.
* @returns One of the following codes:
* - OK: The operation has been scheduled successfully.
* - ERR_NOT_OWNER: You are not the owner of the room's terminal or there is no terminal.
* - ERR_NOT_ENOUGH_RESOURCES: You don't have enough credits to pay a fee.
* - ERR_FULL: You cannot create more than 50 orders.
* - ERR_INVALID_ARGS: The arguments provided are invalid.
*/
createOrder(params: {
type: ORDER_BUY | ORDER_SELL;
resourceType: MarketResourceConstant;
price: number;
totalAmount: number;
roomName?: string;
}): ScreepsReturnCode;
createOrder(params: CreateOrderParam): ScreepsReturnCode;
/**
* Execute a trade deal from your Terminal to another player's Terminal using the specified buy/sell order.
*
Expand Down Expand Up @@ -3179,6 +3181,37 @@ interface PriceHistory {
avgPrice: number;
stddevPrice: number;
}

/** Parameters to {@link Game.market.createOrder} */
interface CreateOrderParam {
/**
* The order type.
*/
type: ORDER_BUY | ORDER_SELL;
/**
* The resource type to trade.
*
* If your Terminal doesn't have the specified resource, the order will be temporary inactive.
*/
resourceType: MarketResourceConstant;
/**
* The price for one resource unit in credits.
*
* Can be a decimal number.
*/
price: number;
/**
* The amount of resources to be traded in total.
*/
totalAmount: number;
/**
* The room where your order will be created.
*
* You must have your own Terminal structure in this room, otherwise the created order will be temporary inactive.
* This argument is not used when `resourceType` is one of the {@link InterShardResourceConstant} resources.
*/
roomName?: string;
}
interface Memory {
creeps: { [name: string]: CreepMemory };
powerCreeps: { [name: string]: PowerCreepMemory };
Expand Down
47 changes: 40 additions & 7 deletions src/market.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ interface Market {
* it will be automatically activated and deactivated depending on the resource/credits availability.
*
* An order expires in 30 days after its creation, and the remaining market fee is returned.
*
* @param params A object describing the order.
* @returns One of the following codes:
* - OK: The operation has been scheduled successfully.
* - ERR_NOT_OWNER: You are not the owner of the room's terminal or there is no terminal.
* - ERR_NOT_ENOUGH_RESOURCES: You don't have enough credits to pay a fee.
* - ERR_FULL: You cannot create more than 50 orders.
* - ERR_INVALID_ARGS: The arguments provided are invalid.
*/
createOrder(params: {
type: ORDER_BUY | ORDER_SELL;
resourceType: MarketResourceConstant;
price: number;
totalAmount: number;
roomName?: string;
}): ScreepsReturnCode;
createOrder(params: CreateOrderParam): ScreepsReturnCode;
/**
* Execute a trade deal from your Terminal to another player's Terminal using the specified buy/sell order.
*
Expand Down Expand Up @@ -159,3 +161,34 @@ interface PriceHistory {
avgPrice: number;
stddevPrice: number;
}

/** Parameters to {@link Game.market.createOrder} */
interface CreateOrderParam {
/**
* The order type.
*/
type: ORDER_BUY | ORDER_SELL;
/**
* The resource type to trade.
*
* If your Terminal doesn't have the specified resource, the order will be temporary inactive.
*/
resourceType: MarketResourceConstant;
/**
* The price for one resource unit in credits.
*
* Can be a decimal number.
*/
price: number;
/**
* The amount of resources to be traded in total.
*/
totalAmount: number;
/**
* The room where your order will be created.
*
* You must have your own Terminal structure in this room, otherwise the created order will be temporary inactive.
* This argument is not used when `resourceType` is one of the {@link InterShardResourceConstant} resources.
*/
roomName?: string;
}

0 comments on commit 27a9374

Please sign in to comment.