-
-
Save avkos/38206a9acef7f71912fed00885bbada3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import HoldModel, {HoldDocument} from '../model/hold' | |
import Base from './base' | |
import {HOLD_STATUS} from '../../constants' | |
class Hold extends Base<HoldDocument, THold> { | |
getByTypeAndSymbol(type: string, symbol: string): Promise<THold | undefined> { | |
return this.getFirst({type, symbol}) | |
} | |
getByTypeAndSymbolStatus(type: string, symbol: string, status: string): Promise<THold | undefined> { | |
return this.getFirst({type, symbol, status}) | |
} | |
create(data: THold): Promise<THold> { | |
return super.create({ | |
status: HOLD_STATUS.STARTED, | |
...data | |
}) | |
} | |
getCurrentHolds(): Promise<THold[]> { | |
return this.getList({status: HOLD_STATUS.STARTED}) | |
} | |
} | |
export default new Hold(HoldModel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SettingModel, {SettingDocument} from '../model/setting' | |
import Base from './base' | |
import config from '../../config' | |
class Setting extends Base<SettingDocument, TSetting> { | |
async getByTypeAndSymbol(type: string, symbol: string): Promise<TSetting> { | |
let setting = await this.getFirst({type, symbol}) | |
if (!setting) { | |
setting = await this.create({ | |
type, | |
symbol, | |
data: config.strategy.defaultSetting | |
}) | |
} | |
return setting | |
} | |
} | |
export default new Setting(SettingModel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import StrategyModel, {StrategyDocument} from '../model/strategy' | |
import Base from './base' | |
import {STRATEGY_STATUS} from '../../constants' | |
import {getOrderPrice} from '../../helper/order' | |
class Strategy extends Base<StrategyDocument, TStrategy> { | |
getByTypeAndSymbol(type: string, symbol: string): Promise<TStrategy[]> { | |
return this.getList({type, symbol}) | |
} | |
create(data: TStrategy): Promise<TStrategy> { | |
return super.create({ | |
status: STRATEGY_STATUS.CREATED, | |
...data | |
}) | |
} | |
update(s: TStrategy): Promise<TStrategy> { | |
if (s.id) { | |
return super.update(s) | |
} else { | |
return this.create(s) | |
} | |
} | |
getByHoldId(type: string, symbol: string, holdId: string): Promise<TStrategy[]> { | |
return this.getList({type, symbol, holdId}) | |
} | |
async getSimilarHold(strategy: TStrategy, currentPrice: number): Promise<TStrategy | undefined> { | |
const list = (await this.getList({ | |
type: strategy.type, | |
symbol: strategy.symbol, | |
status: STRATEGY_STATUS.HOLD, | |
})) || [] | |
return list.find((s: TStrategy) => currentPrice >= getOrderPrice(s.data?.buyOrder)) | |
} | |
getByTypeAndSymbolStatus(type: string, symbol: string, status: string): Promise<TStrategy[]> { | |
return this.getList({type, symbol, status}) | |
} | |
getCurrentStrategy(type: string, symbol: string): Promise<TStrategy | undefined> { | |
return this.getFirst({type, symbol, status: STRATEGY_STATUS.STARTED}) | |
} | |
} | |
export default new Strategy(StrategyModel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment