Skip to content

Commit

Permalink
Fix order placing
Browse files Browse the repository at this point in the history
  • Loading branch information
notVitaliy committed Nov 27, 2020
1 parent ad0e9f7 commit 1ec9dca
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/core/exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class ExchangeCore {
if (currency > currencyFree) return this.error(`currency ${c} does not have enough free funds (${currencyFree})`)

// prettier-ignore
await this.strategyCores.get(symbol).get(strategy).adjustWallet({ asset, currency, type: 'user' })
await this.strategyCores.get(symbol).get(strategy).adjustStrategyWallet({ asset, currency, type: 'user' })
}

private getFreeFunds(wallets, a: string, c: string, assetBalance: number, currencyBalance: number): { assetFree: any; currencyFree: any } {
Expand Down
7 changes: 6 additions & 1 deletion src/core/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class StrategyCore {
PeriodStore.instance.addSymbol(storeOpts, { period, lookbackSize: 250 })

this.orderEngine = new OrderEngine(this.exchangeProvider, strategyConfig)
this.initStrategyWallet()
}

public isRunning() {
Expand All @@ -71,7 +72,11 @@ export class StrategyCore {
logger.info(`Stopping Strategy ${strategy}`)
}

public async adjustWallet(adjustment: Adjustment) {
public async initStrategyWallet() {
await this.adjustStrategyWallet(null)
}

public async adjustStrategyWallet(adjustment: Adjustment) {
const walletOpts = { exchange: this.exchange, symbol: this.symbol, strategy: this.strategy }
await WalletStore.instance.initWallet(walletOpts, adjustment)
}
Expand Down
5 changes: 4 additions & 1 deletion src/store/wallet.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { dbDriver, Wallet, eventBus, EVENT, Adjustment, wsServer } from '@lib'
import { SessionStore } from './session.store'
import { AdjustmentStore } from './adjustment.store'
import { StoreOpts } from '@m8bTypes'
import { logger } from '../util'

const singleton = Symbol()

Expand All @@ -24,10 +25,12 @@ export class WalletStore {

private constructor() {}

public async initWallet(storeOpts: StoreOpts, adjustment: Adjustment) {
public async initWallet(storeOpts: StoreOpts, adjustment: Adjustment = null) {
await this.loadOrNewWallet(storeOpts, adjustment)
this.subcribeToWalletEvents(storeOpts)

logger.debug(`Wallet ${this.makeIdStr(storeOpts)} loaded.`)

// @todo(notVitaliy): Find a better place for this
wsServer.broadcast('wallet', { ...storeOpts, wallet: this.getWallet(storeOpts) })
}
Expand Down

0 comments on commit 1ec9dca

Please sign in to comment.