Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document createOrder's parameter properly #269

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}