新版仿ok交易所-后端
1
zj
2025-07-10 f15406ac788fb4e17a630c4d48129943af89fb9c
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
package com.yami.trading.api.controller;
 
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.model.RealNameAuthRecord;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.common.util.UTCDateUtils;
import com.yami.trading.common.web.ResultObject;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.service.RealNameAuthRecordService;
import com.yami.trading.service.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import java.io.IOException;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
 
@RestController
@Api(tags = "资产")
@Slf4j
public class ApiAssetsController {
 
    private final String action = "/api/assets!";
 
    @Autowired
    RealNameAuthRecordService realNameAuthRecordService;
 
 
    @Autowired
    WalletService walletService;
 
    /**
     * 总账户资产 所有币种,订单资产转换到Usdt余额
     */
    @RequestMapping(action + "getContractBySymbolType.action")
    @ApiOperation("总账户资产 所有币种,订单资产转换到Usdt余额")
    public Result<Map<String, String>> getContractBySymbolType(String symbolType) {
        Map<String, String> data = new HashMap<String, String>();
        DecimalFormat df2 = new DecimalFormat("#.##");
        // 向下取整
        df2.setRoundingMode(RoundingMode.HALF_UP);
        String partyId = SecurityUtils.getCurrentUserId();
        if ("".equals(partyId) || null == partyId) {
            // 当前外汇资产
            data.put("money_contract", df2.format(0));
            data.put("money_contract_deposit", df2.format(0));
            // 外汇浮动盈亏
            data.put("money_contract_profit", df2.format(0));
            // 当日盈亏
            data.put("money_contract_profit_today", df2.format(0));
            // 外汇可用余额
            data.put("money_wallet", df2.format(0));
        } else {
            Map<String, Double> moneyContract = walletService.getMoneyContract(partyId, symbolType);
            data.put("money_contract", df2.format(moneyContract.get("money_contract")));
            data.put("money_contract_deposit", df2.format(moneyContract.get("money_contract_deposit")));
            // 外汇浮动盈亏
            data.put("money_contract_profit", df2.format(moneyContract.get("money_contract_profit")));
            // 当日盈亏
            data.put("money_contract_profit_today", df2.format(moneyContract.get("money_contract_profit_today")));
            // 外汇可用余额
            data.put("money_wallet", df2.format(moneyContract.get("money_wallet")));
        }
        return Result.ok(data);
    }
 
    @RequestMapping(action + "getAllAggregation.action")
    @ApiOperation("总账户资产 所有币种,订单资产转换到Usdt余额")
    public Object getAllAggregation() {
        ResultObject resultObject = new ResultObject();
        Map<String, Object> data = new HashMap<String, Object>();
        try {
            List<String> types = new ArrayList<>();
            types.add(Item.indices);
            types.add(Item.forex);
            types.add(Item.cryptos);
            types.add(Item.US_STOCKS);
            for (String type : types) {
                data.put(type, getAssert(type));
            }
            data.put("all", getAssert(""));
            resultObject.setData(data);
            return resultObject;
 
 
        } catch (BusinessException e) {
            resultObject.setCode("1");
            resultObject.setMsg(e.getMessage());
        } catch (Throwable t) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            log.error("error:", t);
        }
        return resultObject;
 
    }
 
    /**
     * 总账户资产 所有币种,订单资产转换到Usdt余额
     */
    @RequestMapping(action + "getAll.action")
    @ApiOperation("总账户资产 所有币种,订单资产转换到Usdt余额")
    public Object getAll(@RequestParam(required = false) String symbolType) {
        ResultObject resultObject = new ResultObject();
 
        Map<String, Object> data = new HashMap<String, Object>();
        DecimalFormat df2 = new DecimalFormat("#.##");
        // 向下取整
        df2.setRoundingMode(RoundingMode.FLOOR);
 
        String partyId = SecurityUtils.getCurrentUserId();
        try {
 
            if ("".equals(partyId) || null == partyId) {
 
                data.put("total", df2.format(0));
                data.put("lock_money", df2.format(0));
                //冻结金额
                data.put("freeze_money", df2.format(0));
                data.put("money_wallet", df2.format(0));
                data.put("money_coin", df2.format(0));
                data.put("money_all_coin", df2.format(0));
                data.put("money_miner", df2.format(0));
                data.put("money_finance", df2.format(0));
                data.put("money_contract", df2.format(0));
                data.put("money_contract_deposit", df2.format(0));
                data.put("money_contract_profit", df2.format(0));
                data.put("money_futures", df2.format(0));
                data.put("money_futures_profit", df2.format(0));
 
            } else {
                if (StringUtils.isNotEmpty(symbolType)) {
                    data = walletService.getMoneyAll(partyId, symbolType);
                } else {
                    data = walletService.getMoneyAll(partyId);
                }
            }
 
            RealNameAuthRecord kyc = realNameAuthRecordService.getByUserId(partyId);
            data.put("status", kyc == null ? 0 : kyc.getStatus());
            resultObject.setData(data);
        } catch (BusinessException e) {
            resultObject.setCode("1");
            resultObject.setMsg(e.getMessage());
        } catch (Throwable t) {
            resultObject.setCode("1");
            resultObject.setMsg("程序错误");
            log.error("error:", t);
        }
 
        return resultObject;
    }
 
    public Map<String, Object> getAssert(String symbolType) {
        Map<String, Object> data = new HashMap<String, Object>();
        DecimalFormat df2 = new DecimalFormat("#.##");
        // 向下取整
        df2.setRoundingMode(RoundingMode.FLOOR);
 
        String partyId = SecurityUtils.getCurrentUserId();
        if ("".equals(partyId) || null == partyId) {
            data.put("total", df2.format(0));
            data.put("lock_money", df2.format(0));
            //冻结金额
            data.put("freeze_money", df2.format(0));
            data.put("money_wallet", df2.format(0));
            data.put("money_coin", df2.format(0));
            data.put("money_all_coin", df2.format(0));
            data.put("money_miner", df2.format(0));
            data.put("money_finance", df2.format(0));
            data.put("money_contract", df2.format(0));
            data.put("money_contract_deposit", df2.format(0));
            data.put("money_contract_profit", df2.format(0));
            data.put("money_futures", df2.format(0));
            data.put("money_futures_profit", df2.format(0));
 
        } else {
            if (StringUtils.isNotEmpty(symbolType)) {
                data = walletService.getMoneyAll(partyId, symbolType);
            } else {
                data = walletService.getMoneyAll(partyId);
            }
        }
 
        RealNameAuthRecord kyc = realNameAuthRecordService.getByUserId(partyId);
        data.put("status", kyc == null ? 0 : kyc.getStatus());
        return data;
 
    }
 
 
    /**
     * 获取当前是否休市
     */
    @RequestMapping(action + "isClosed.action")
    public Result<Map<String, Object>> isClosed() throws IOException, ParseException {
        Map<String, Object> data = new HashMap<String, Object>();
 
 
        SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        f.setTimeZone(TimeZone.getTimeZone(UTCDateUtils.GMT_TIME_ZONE));
        Date now = f.parse(f.format(new Date()));
//        if (now.before(UTCDateUtils.getClosedTime()) && now.after(UTCDateUtils.getOpenTime())) {
//            data.put("isClosed", "false");
//        } else {
//            // 休市
//            data.put("isClosed", "true");
//        }
        return Result.ok(data);
 
    }
 
    @RequestMapping(action + "getTime.action")
    public Result<Map<String, Object>> getTime() throws IOException {
        Map<String, Object> data = new HashMap<String, Object>();
        Date date = new Date();
        data.put("time", date.toGMTString());
        data.put("time2", System.currentTimeMillis());
        return Result.ok(data);
    }
 
 
}