Administrator
5 days ago 672f2cf6d8d87dffb5713067b3545e74f544cca7
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
package com.xcong.excoin.modules.okxApi;
 
import com.xcong.excoin.modules.okxApi.wsHandler.handler.MarkPriceOkxChannelHandler;
import com.xcong.excoin.modules.okxApi.wsHandler.handler.OrderAlgoOkxChannelHandler;
import com.xcong.excoin.modules.okxApi.wsHandler.handler.PositionsOkxChannelHandler;
 
import java.math.BigDecimal;
import java.util.concurrent.CountDownLatch;
 
/**
 * OKX 网格策略独立启动入口(用于测试或非 Spring 环境)。
 *
 * @author Administrator
 */
public class OkxWebSocketClientMain {
 
    public static void main(String[] args) throws InterruptedException {
        OkxConfig config = OkxConfig.builder()
                .apiKey("YOUR_OKX_API_KEY")
                .apiSecret("YOUR_OKX_API_SECRET")
                .passphrase("YOUR_OKX_PASSPHRASE")
                .contract("ETH-USDT-SWAP")
                .leverage("100")
                .marginMode("cross")
                .positionMode("long_short_mode")
                .gridRate(new BigDecimal("0.003"))
                .expectedProfit(new BigDecimal("25"))
                .maxLoss(new BigDecimal("15"))
                .baseQuantity("15")
                .quantity("15")
                .restartGridSpan(6)
                .priceScale(2)
                .contractMultiplier(new BigDecimal("0.01"))
                .isProduction(false)
                .build();
 
        OkxGridTradeService gridTradeService = new OkxGridTradeService(config);
        gridTradeService.init();
 
        OkxKlineWebSocketClient wsClient = new OkxKlineWebSocketClient(config);
 
        wsClient.addPublicHandler(new MarkPriceOkxChannelHandler(
                config.getContract(), gridTradeService));
        wsClient.addPrivateHandler(new PositionsOkxChannelHandler(
                config, gridTradeService));
        wsClient.addPrivateHandler(new OrderAlgoOkxChannelHandler(
                config, gridTradeService));
 
        gridTradeService.setWsClient(wsClient);
        wsClient.init();
 
        gridTradeService.startGrid();
 
        // 保持主线程不退出
        CountDownLatch latch = new CountDownLatch(1);
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            gridTradeService.stopGrid();
            wsClient.destroy();
            latch.countDown();
        }));
        latch.await();
    }
}