Skip to content

Commit

Permalink
Init QuoteEnginer with default values
Browse files Browse the repository at this point in the history
  • Loading branch information
notVitaliy committed Nov 27, 2020
1 parent 3169b20 commit ad0e9f7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 2 additions & 0 deletions src/core/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { CoreHelpers } from './core.helpers'
import * as Adapters from '../exchange/adapters'
import { Strategies } from '../strategy/strategies/strategies'
import { BaseStrategy } from '@strategy'
import { logger } from '../util'

class Core {
private readonly exchangeProvider: ExchangeProvider
Expand Down Expand Up @@ -228,6 +229,7 @@ class Core {

const exchangeCore = new ExchangeCore(this.exchangeProvider, exchangeConfig)
await exchangeCore.init()
logger.debug(`Exchange core ${exchangeConfig.exchange} init.`)
this.exchangeCores.set(exchangeConfig.exchange, exchangeCore)

return true
Expand Down
5 changes: 5 additions & 0 deletions src/engine/order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ export class OrderEngine {
public async executeBuy(quote?: number, strength = 1) {
const { exchange, symbol } = this.opts
const rawPrice = quote ? quote : await this.quoteEngine.getBuyPrice()
logger.debug(`Executing buy order on ${exchange}.${symbol} with: ${quote}, ${rawPrice}`)

const price = this.exchangeProvider.priceToPrecision(exchange, symbol, rawPrice)

const purchasingPower = this.exchangeProvider.priceToPrecision(exchange, symbol, this.wallet.currency * strength)
Expand All @@ -71,6 +73,9 @@ export class OrderEngine {
public async executeSell(quote?: number, strength = 1) {
const { exchange, symbol } = this.opts
const rawPrice = quote ? quote : await this.quoteEngine.getSellPrice()

logger.debug(`Executing sell order on ${exchange}.${symbol} with: ${quote}, ${rawPrice}`)

const price = this.exchangeProvider.priceToPrecision(exchange, symbol, rawPrice)
const amount = this.exchangeProvider.amountToPrecision(this.wallet.asset * strength)

Expand Down
5 changes: 3 additions & 2 deletions src/engine/quote.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { ExchangeProvider } from '@exchange'
import { logger } from '../util'

export class QuoteEngine {
constructor(
private readonly exchangeProvider: ExchangeProvider,
private readonly exchange: string,
private readonly symbol: string,
private readonly markUp: number,
private readonly markDn: number
private readonly markUp: number = 0,
private readonly markDn: number = 0
) {}

public async getBuyPrice() {
Expand Down
7 changes: 2 additions & 5 deletions src/strategy/strategies/macd/macd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ export class Macd extends BaseStrategy<MacdOptions, { rsi: number; signal: numbe
// prettier-ignore
const { periods: [{ signal, rsi }] } = this

if (!this.isPreroll) {
/* istanbul ignore next */
logger.debug(`calculated: ${JSON.stringify({ rsi: rsi !== null ? rsi.toPrecision(4) : null, signal: signal !== null ? signal.toPrecision(6) : null })}`)
}

return { rsi, signal }
}

Expand Down Expand Up @@ -198,7 +193,9 @@ export class Macd extends BaseStrategy<MacdOptions, { rsi: number; signal: numbe

logger.verbose(`Period finished => Signal: ${signal === null ? 'no signal' : signal}`)
}

this.newPeriod()

return signal
}

Expand Down

0 comments on commit ad0e9f7

Please sign in to comment.