Skip to content

Commit

Permalink
rename not exported methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mrddter committed Oct 22, 2024
1 parent 31e294f commit 401e6c0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/helpers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const versionAPI = 'v3'
const endpointExchangeInfo = 'exchangeInfo'
const endpointCandles = 'klines'

async function callBinanceAPI(endpoint: string, query: string): Promise<any> {
async function _callBinanceAPI(endpoint: string, query: string): Promise<any> {
try {
// Call Binance API
const url = `${binanceUrl}/api/${versionAPI}/${endpoint}?${query}`
Expand All @@ -34,7 +34,7 @@ export async function getBaseQuote(symbol: string): Promise<{ base: any; quote:
let query = `symbol=${symbol}`

// Call Binance with symbol
const baseQuote = await callBinanceAPI(endpointExchangeInfo, query)
const baseQuote = await _callBinanceAPI(endpointExchangeInfo, query)

// Parse and return base and quote
return { base: baseQuote.symbols[0].baseAsset, quote: baseQuote.symbols[0].quoteAsset }
Expand All @@ -52,5 +52,5 @@ export async function getCandles(getCandlesParams: GetCandles): Promise<any> {
if (getCandlesParams.endTime !== undefined) query += `&endTime=${getCandlesParams.endTime}`

// Call and return the call to Binance
return await callBinanceAPI(endpointCandles, query)
return await _callBinanceAPI(endpointCandles, query)
}
14 changes: 7 additions & 7 deletions src/helpers/csv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import csvToJson from 'csvtojson'
import * as path from 'path'
import * as fs from 'fs'

function getNormalizedField(json: LooseObject, possibleFields: string[]): string | null {
function _getNormalizedField(json: LooseObject, possibleFields: string[]): string | null {
const normalizedFields: { [key: string]: string } = Object.keys(json).reduce(
(acc: { [key: string]: string }, key) => {
acc[key.toLowerCase()] = key
Expand All @@ -23,10 +23,10 @@ function getNormalizedField(json: LooseObject, possibleFields: string[]): string
return null
}

function getFieldKeys(json: LooseObject, fields: { [key: string]: string[] }): { [key: string]: string } {
function _getFieldKeys(json: LooseObject, fields: { [key: string]: string[] }): { [key: string]: string } {
const fieldKeys: { [key: string]: string } = {}
for (const [key, possibleFields] of Object.entries(fields)) {
const fieldKey = getNormalizedField(json, possibleFields)
const fieldKey = _getNormalizedField(json, possibleFields)
if (fieldKey) {
fieldKeys[key] = fieldKey
} else {
Expand All @@ -36,10 +36,10 @@ function getFieldKeys(json: LooseObject, fields: { [key: string]: string[] }): {
return fieldKeys
}

function getOptionalFieldKeys(json: LooseObject, fields: { [key: string]: string[] }): { [key: string]: string } {
function _getOptionalFieldKeys(json: LooseObject, fields: { [key: string]: string[] }): { [key: string]: string } {
const optionalFields: { [key: string]: string } = {}
for (const [key, possibleFields] of Object.entries(fields)) {
const fieldKey = getNormalizedField(json, possibleFields)
const fieldKey = _getNormalizedField(json, possibleFields)
if (fieldKey) {
optionalFields[key] = fieldKey
}
Expand Down Expand Up @@ -73,8 +73,8 @@ export async function importCSV(importCSVParams: ImportCSV) {
}

try {
const fieldKeys = getFieldKeys(json, requiredFields)
const optionalFileds = getOptionalFieldKeys(json, optionalFields)
const fieldKeys = _getFieldKeys(json, requiredFields)
const optionalFileds = _getOptionalFieldKeys(json, optionalFields)

// Parse JSON for DB
const jsonParsedCandles: Candle[] = jsonCSV.map((entry: LooseObject) => ({
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/historical-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import * as logger from './logger'

export const intervals = ['1m', '3m', '5m', '15m', '30m', '1h', '2h', '4h', '6h', '8h', '12h', '1d', '3d', '1w', '1M']

async function getParseSaveCandlesPrivate(runParams: GetCandles, newData: boolean): Promise<Candle[]> {
async function _getParseSaveCandlesPrivate(runParams: GetCandles, newData: boolean): Promise<Candle[]> {
// Define function globals
let finishedCandles = false
let allCandles: Candle[] = []
Expand Down Expand Up @@ -96,7 +96,7 @@ async function getParseSaveCandlesPrivate(runParams: GetCandles, newData: boolea

export async function saveHistoricalData(runParams: GetCandles) {
// Get, parse and save all needed candles
const allCandlesResults = await getParseSaveCandlesPrivate(runParams, true)
const allCandlesResults = await _getParseSaveCandlesPrivate(runParams, true)
if (allCandlesResults) {
logger.info(
`Saved ${allCandlesResults.length} candles for ${runParams.symbol} on the ${runParams.interval} interval`
Expand Down
10 changes: 5 additions & 5 deletions src/helpers/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@ export enum LogLevel {
const currentLevel = 0 // TODO: da inserire in .env / config

export function error(...args: any[]) {
if (shouldLog(LogLevel.ERROR)) {
if (_shouldLog(LogLevel.ERROR)) {
console.log('ERROR:', ...args)
}
}

export function info(...args: any[]) {
if (shouldLog(LogLevel.INFO)) {
if (_shouldLog(LogLevel.INFO)) {
console.log('INFO:', ...args)
}
}

export function debug(...args: any[]) {
if (shouldLog(LogLevel.DEBUG)) {
if (_shouldLog(LogLevel.DEBUG)) {
console.log('DEBUG:', ...args)
}
}

export function trace(...args: any[]) {
if (shouldLog(LogLevel.TRACE)) {
if (_shouldLog(LogLevel.TRACE)) {
console.log('TRACE:', ...args)
}
}

function shouldLog(level: LogLevel): boolean {
function _shouldLog(level: LogLevel): boolean {
return level >= currentLevel
}
2 changes: 1 addition & 1 deletion src/helpers/prisma-results-multi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function getAllMultiResults(): Promise<StrategyResultMulti[]> {
})

const results: StrategyResultMulti[] = await Promise.all(
strategyResults.map(async (result) => await getMultiResult(result.name))
strategyResults.map(async (result) => await _getMultiResult(result.name))
)
return results
} catch (error) {
Expand Down

0 comments on commit 401e6c0

Please sign in to comment.