-
-
Notifications
You must be signed in to change notification settings - Fork 143
/
Copy pathLiveBinanceTrader.java
71 lines (59 loc) · 2.31 KB
/
LiveBinanceTrader.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
67
68
69
70
package com.univocity.trader.examples;
import com.univocity.trader.*;
import com.univocity.trader.account.*;
import com.univocity.trader.candles.*;
import com.univocity.trader.exchange.binance.*;
import com.univocity.trader.notification.*;
import java.math.*;
public class LiveBinanceTrader {
public static void main(String... args) {
Binance.Trader trader = Binance.trader();
// TODO: configure your database connection as needed. By default MySQL will be used
// trader.configure().database()
// .jdbcDriver("my.database.DriverClass")
// .jdbcUrl("jdbc:mydb://localhost:5555/database")
// .user("admin")
// .password("qwerty");
// If you want to receive e-mail notifications each time an order is submitted to the exchange, configure your e-mail sender
trader.configure().mailSender()
.replyToAddress("[email protected]")
.smtpHost("smtp.gmail.com")
.smtpSSL(true)
.smtpPort(587)
.smtpUsername("<YOU>@gmail.com")
.smtpPassword("<YOUR SMTP PASSWORD>")
.smtpSender("<YOU>>@gmail.com");
//set an e-mail and timezone here to get notifications to your e-mail every time a BUY or SELL happens.
//the timezone is required if you want to host this in a server outside of your local timezone
//so the time a trade happens will come to you in your local time and not the server time
Account account = trader.configure().account()
.email("<YOUR E-MAIL")
.timeZone("system")
.referenceCurrency("USDT")
.apiKey("<YOUR BINANCE API KEY>")
.secret("<YOUR BINANCE API SECRET>");
account.strategies().add(ExampleStrategy::new);
account.monitors().add(ExampleStrategyMonitor::new);
account.listeners().add(new OrderExecutionToLog());
// never invest more than 20 USDT on anything
account
.tradeWith("BTC", "ETH", "XRP", "ADA")
.maximumInvestmentAmountPerAsset(20)
;
// overrides the default order manager submit orders that likely won't be filled so you can see what the program does.
account.orderManager(new DefaultOrderManager() {
@Override
public void prepareOrder(OrderBook book, OrderRequest order, Context context) {
switch (order.getSide()) {
case BUY:
order.setPrice(order.getPrice() * 0.9); //10% less
break;
case SELL:
order.setPrice(order.getPrice() * 1.1); //10% more
}
}
});
// Begin trading
trader.run();
}
}