forked from uniVocity/univocity-trader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MarketSimulation.java
66 lines (52 loc) · 2.15 KB
/
MarketSimulation.java
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.univocity.trader.examples;
import com.univocity.trader.account.*;
import com.univocity.trader.config.*;
import com.univocity.trader.exchange.binance.*;
import com.univocity.trader.notification.*;
import java.time.*;
/**
* @author uniVocity Software Pty Ltd - <a href="mailto:[email protected]">[email protected]</a>
*/
public class MarketSimulation {
public static void main(String... args) {
Binance.Simulator simulator = Binance.simulator();
// TODO: configure your database connection as needed. By default MySQL will be used
// simulator.configure().database()
// .jdbcDriver("my.database.DriverClass")
// .jdbcUrl("jdbc:mydb://localhost:5555/database")
// .user("admin")
// .password("qwerty");
//you can test with one or more accounts at the same time
Account account = simulator.configure().account();
// account.enableShorting(); //NOTE: Binance doesn't support shorting. Enable this for testing only.
account
.referenceCurrency("USDT") //Balances will be calculated using the reference currency.
.tradeWith("BTC", "ADA", "LTC", "XRP", "ETH")
.maximumInvestmentPercentagePerAsset(10.0)
.maximumInvestmentPercentagePerTrade(2.0)
.minimumInvestmentAmountPerTrade(10.0)
// .maximumInvestmentPercentagePerAsset(30.0, "ADA", "ETH")
// .maximumInvestmentPercentagePerAsset(50.0, "BTC", "LTC")
// .maximumInvestmentAmountPerAsset(200, "XRP")
;
account.strategies()
.add(ExampleStrategy::new);
account.monitors()
.add(ExampleStrategyMonitor::new);
account.listeners()
.add(new OrderExecutionToLog())
.add(new OrderExecutionToCsv().fileName("simulation.csv"))
.add((symbol) -> new SimpleStrategyStatistics(symbol))
;
// account.orderManager(new ExampleOrderManager());
Simulation simulation = simulator.configure().simulation();
simulation.initialFunds(1000.0)
.tradingFees(SimpleTradingFees.percentage(0.1))
.emulateSlippage()
.simulateFrom(LocalDate.of(2018, 7, 1).atStartOfDay())
.simulateTo(LocalDate.of(2019, 7, 1).atStartOfDay());
simulator.symbolInformation("USDT").priceDecimalPlaces(2).quantityDecimalPlaces(2);
// execute simulation
simulator.run();
}
}