2.0.3 • Published 2 months ago

@debut/plugin-utils v2.0.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 months ago

@debut/plugin-utils

A set of indispensable utilities for the Debut ecosystem.

Installation

npm install @debut/plugin-utils --save

CLI - Command Line Interface utilities

requireUncached(module: string)

Allows the specified module to be connected without the standard Node caching. Instead of a native call to require(module: string)

getBotsSchema()

Get the contents of schema.json file

getBotData(name: string, schema = getBotsSchema())

Getting the bot's meta data by the name of the constructor.

getArgs<T>()

Gets the arguments passed at startup. Returns an object key-value.

Example: node ./myscript.js --arg1=foo --arg2=bar.

import { cli } from '@debut/plugin-utils`;

const args = getArgs(); // { arg1: "foo", arg2: "bar" }

getTokens().

Getting an object with private keys to work with the broker's API. From the file .tokens.json in the working directory of the project.

Date - Utilities for working with dates

isSameDay(d1: Date, d2: Date)

Are the two dates the same day

isWeekend(d: string | number | Date)

Is the date the same day off

toIsoString(d: string | number | Date)

Convert date to custom ISO format to work with tinkoff API.

getWeekDay(stamp: number)

Get the day of the week in UTC time stamp

intervalToMs(interval: TimeFrame)

Converting candlestick timeframe into a value in milliseconds

Debug - Debugging utilities

logDebug(...data: any[])

Logging with event time information

File - Utilities for working with files

saveFile(path: string, data: any)

saveFile(path: string: data: any) ## Save the transferred data to the path path

ensureFile(path: string)

Checks if the path exists; if it does not, creates it

readFile(path: string)

Safely reads a file

isDir(path: string)

Is the path a directory

Math - Calculation utilities

clamp(num: number, min: number, max: number)

Clamping a number between a minimum and a maximum value

getPrecision(number: number | string)

Getting the precision of a floating point number calculation

percentChange(current: number, prev: number)

Percentage difference between two numbers

toFixed(num: number, precision = 2)

A quick fix for the accuracy of a calculation, without losing type

getRandomArbitrary(min: number, max: number, odd?: boolean)

Generation of a random number in the range min, max and optionally an odd number

getRandomInt(min: number, max: number, odd?: boolean)

Generation of a random integer in the range min, max, optionally odd

Orders - Utilities for working with deals

inverseType(type: OrderType)

Inverts the type of a trade

syntheticOrderId(order: ExecutedOrder | OrderOptions)

Synthetic random identifier for a trade

getMinIncrementValue(price: number | string)

Minimum value in the accuracy of the passed number

getCurrencyProfit(order: ExecutedOrder, price: number)

Counting the current profit in the currency of the trade

getCurrencyBatchProfit(orders: ExecutedOrder[], price: number)

Counting current profit in the currency of the trade for several orders simultaneously

getCurrencyComissions(orders: ExecutedOrder[], price: number, fee: number)

Counting current commision for single order based on predicatable fee number

getCurrencyBatchComissions(orders: ExecutedOrder[], price: number, fee: number)

Counting current commision for several orders order based on predicatable fee number

Promise

sleep(ms: number)

Initializes downtime for some time in milliseconds

2.0.3

2 months ago

2.0.2

6 months ago

2.0.1

1 year ago

2.0.0

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.4

2 years ago

1.3.2

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.4.0-beta.2

2 years ago

1.4.0-beta.1

2 years ago

1.4.0-beta.0

2 years ago

1.2.1-esm.1

2 years ago

1.2.1-esm.0

2 years ago

1.2.0

2 years ago

1.1.0

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago