-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.py
More file actions
44 lines (32 loc) · 1.41 KB
/
executor.py
File metadata and controls
44 lines (32 loc) · 1.41 KB
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
42
43
44
#!/usr/bin/env python
# encoding: utf-8
import os
import time
from _decimal import Decimal
from dotenv import load_dotenv
from context import BackTestContext
from kline_cache import BackTestKLineCached
from enumeration import KLineSymbol, KLineInterval
from strategies import IStrategy
from strategies.moving_average_trend import MovingAverageTrendStrategy
if __name__ == "__main__":
load_dotenv()
kline_provider = os.environ.get("KLINE_PROVIDER")
kline_symbol = KLineSymbol.LtcUsdt
kline_interval = KLineInterval.OneMinute
start_ts = int(time.time()) - 86400 * 300
context = BackTestContext(kline_provider, kline_symbol, kline_interval, start_ts)
context.init_currency_balances(Decimal("0"), Decimal("10000"))
context.init_exchange_fee_rate(Decimal("0.002"))
# strategy = IStrategy(context)
strategy = MovingAverageTrendStrategy(context, 50, 50,
Decimal("0.04"), Decimal("0.04"), Decimal("0.05"))
kline_cached = BackTestKLineCached(context)
for kline in kline_cached:
strategy.run(kline)
print(strategy.first_kline.close_price)
print(strategy.last_kline.close_price)
base_balance, quote_balance = context.get_currency_balances()
print(base_balance * strategy.last_kline.close_price + quote_balance)
base_fee, quote_fee = context.get_exchange_fee()
print(base_fee * strategy.last_kline.close_price + quote_fee)