-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuyAndHodl.ts
41 lines (38 loc) · 1.03 KB
/
buyAndHodl.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { Exchange, Trade } from 'exchange'
import { PriceHistory } from 'coin'
import { Strategy, Parameter } from '../'
/**
* A strategy that simply buys and then hodls through rain or shine
*/
export class BuyAndHodlStrategy extends Strategy {
get parameters(): Parameter[] {
return []
}
protected getTrades({
priceHistory,
coinAmount,
cashAmount,
exchange
}: {
priceHistory: PriceHistory
coinAmount: number
cashAmount: number
exchange: Exchange
}): {
trades: Trade[]
endingCoinAmount: number
endingCashAmount: number
} {
let { trade, newCoinAmount, newCashAmount } = exchange.buy({
amount: cashAmount,
historicalPrice: priceHistory.prices[0],
initialCoinAmount: coinAmount,
initialCashAmount: cashAmount
})
return {
trades: [trade],
endingCoinAmount: newCoinAmount,
endingCashAmount: newCashAmount
}
}
}